本文整理汇总了C#中Instance.attributeSparse方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.attributeSparse方法的具体用法?C# Instance.attributeSparse怎么用?C# Instance.attributeSparse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Instance
的用法示例。
在下文中一共展示了Instance.attributeSparse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}