当前位置: 首页>>代码示例>>C#>>正文


C# Instance.numAttributes方法代码示例

本文整理汇总了C#中Instance.numAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.numAttributes方法的具体用法?C# Instance.numAttributes怎么用?C# Instance.numAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Instance的用法示例。


在下文中一共展示了Instance.numAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SparseInstance

		/// <summary> Constructor that generates a sparse instance from the given
		/// instance. Reference to the dataset is set to null.
		/// (ie. the instance doesn't have access to information about the
		/// attribute types)
		/// 
		/// </summary>
		/// <param name="instance">the instance from which the attribute values
		/// and the weight are to be copied
		/// </param>
		public SparseInstance(Instance instance)
		{
			
			m_Weight = instance.m_Weight;
			m_Dataset = null;
			m_NumAttributes = instance.numAttributes();
			if (instance is SparseInstance)
			{
				m_AttValues = ((SparseInstance) instance).m_AttValues;
				m_Indices = ((SparseInstance) instance).m_Indices;
			}
			else
			{
				double[] tempValues = new double[instance.numAttributes()];
				int[] tempIndices = new int[instance.numAttributes()];
				int vals = 0;
				for (int i = 0; i < instance.numAttributes(); i++)
				{
					if (instance.value_Renamed(i) != 0)
					{
						tempValues[vals] = instance.value_Renamed(i);
						tempIndices[vals] = i;
						vals++;
					}
				}
				m_AttValues = new double[vals];
				m_Indices = new int[vals];
				Array.Copy(tempValues, 0, m_AttValues, 0, vals);
				Array.Copy(tempIndices, 0, m_Indices, 0, vals);
			}
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:40,代码来源:SparseInstance.cs

示例2: convertInstance

		/// <summary> Convert a single instance over. The converted instance is 
		/// added to the end of the output queue.
		/// 
		/// </summary>
		/// <param name="instance">the instance to convert
		/// </param>
		private void  convertInstance(Instance instance)
		{
			
			Instance inst = null;
			if (instance is SparseInstance)
			{
				double[] vals = new double[instance.numValues()];
				int[] indices = new int[instance.numValues()];
				int num = 0;
				for (int j = 0; j < instance.numValues(); j++)
				{
					if (instance.isMissingSparse(j) && (getInputFormat().classIndex() != instance.index(j)) && (instance.attributeSparse(j).Nominal || instance.attributeSparse(j).Numeric))
					{
						if (m_ModesAndMeans[instance.index(j)] != 0.0)
						{
							vals[num] = m_ModesAndMeans[instance.index(j)];
							indices[num] = instance.index(j);
							num++;
						}
					}
					else
					{
						vals[num] = instance.valueSparse(j);
						indices[num] = instance.index(j);
						num++;
					}
				}
				if (num == instance.numValues())
				{
					inst = new SparseInstance(instance.weight(), vals, indices, instance.numAttributes());
				}
				else
				{
					double[] tempVals = new double[num];
					int[] tempInd = new int[num];
					Array.Copy(vals, 0, tempVals, 0, num);
					Array.Copy(indices, 0, tempInd, 0, num);
					inst = new SparseInstance(instance.weight(), tempVals, tempInd, instance.numAttributes());
				}
			}
			else
			{
				double[] vals = new double[getInputFormat().numAttributes()];
				for (int j = 0; j < instance.numAttributes(); j++)
				{
					if (instance.isMissing(j) && (getInputFormat().classIndex() != j) && (getInputFormat().attribute(j).Nominal || getInputFormat().attribute(j).Numeric))
					{
						vals[j] = m_ModesAndMeans[j];
					}
					else
					{
						vals[j] = instance.value_Renamed(j);
					}
				}
				inst = new Instance(instance.weight(), vals);
			}
			inst.Dataset = instance.dataset();
			push(inst);
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:65,代码来源:ReplaceMissingValues.cs

示例3: attributeValuesString

		/// <summary> Builds a string listing the attribute values in a specified range of indices,
		/// separated by commas and enclosed in brackets.
		/// 
		/// </summary>
		/// <param name="instance">the instance to print the values from
		/// </param>
		/// <param name="attRange">the range of the attributes to list
		/// </param>
		/// <returns> a string listing values of the attributes in the range
		/// </returns>
		protected internal static System.String attributeValuesString(Instance instance, Range attRange)
		{
			System.Text.StringBuilder text = new System.Text.StringBuilder();
			if (attRange != null)
			{
				bool firstOutput = true;
				attRange.Upper = instance.numAttributes() - 1;
				for (int i = 0; i < instance.numAttributes(); i++)
					if (attRange.isInRange(i) && i != instance.classIndex())
					{
						if (firstOutput)
							text.Append("(");
						else
							text.Append(",");
						text.Append(instance.toString(i));
						firstOutput = false;
					}
				if (!firstOutput)
					text.Append(")");
			}
			return text.ToString();
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:32,代码来源:Evaluation.cs

示例4: mergeInstance

		/// <summary> Merges this instance with the given instance and returns
		/// the result. Dataset is set to null.
		/// 
		/// </summary>
		/// <param name="inst">the instance to be merged with this one
		/// </param>
		/// <returns> the merged instances
		/// </returns>
		public override Instance mergeInstance(Instance inst)
		{
			
			double[] values = new double[numValues() + inst.numValues()];
			int[] indices = new int[numValues() + inst.numValues()];
			
			int m = 0;
			for (int j = 0; j < numValues(); j++, m++)
			{
				values[m] = valueSparse(j);
				indices[m] = index(j);
			}
			for (int j = 0; j < inst.numValues(); j++, m++)
			{
				values[m] = inst.valueSparse(j);
				indices[m] = numAttributes() + inst.index(j);
			}
			
			return new SparseInstance(1.0, values, indices, numAttributes() + inst.numAttributes());
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:28,代码来源:SparseInstance.cs

示例5: checkInstance

		/// <summary> Checks if the given instance is compatible
		/// with this dataset. Only looks at the size of
		/// the instance and the ranges of the values for 
		/// nominal and string attributes.
		/// 
		/// </summary>
		/// <returns> true if the instance is compatible with the dataset 
		/// </returns>
		public virtual bool checkInstance(Instance instance)
		{
			
			if (instance.numAttributes() != numAttributes())
			{
				return false;
			}
			for (int i = 0; i < numAttributes(); i++)
			{
				if (instance.isMissing(i))
				{
					continue;
				}
				else if (attribute(i).Nominal || attribute(i).String)
				{
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					if (!(Utils.eq(instance.value_Renamed(i), (double) instance.value_Renamed(i))))
					{
						return false;
					}
					else if (Utils.sm(instance.value_Renamed(i), 0) || Utils.gr(instance.value_Renamed(i), attribute(i).numValues()))
					{
						return false;
					}
				}
			}
			return true;
		}
开发者ID:intille,项目名称:mitessoftware,代码行数:36,代码来源:Instances.cs


注:本文中的Instance.numAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。