本文整理汇总了C#中Instance.valueSparse方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.valueSparse方法的具体用法?C# Instance.valueSparse怎么用?C# Instance.valueSparse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Instance
的用法示例。
在下文中一共展示了Instance.valueSparse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例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);
}
示例3: innerProduct
/// <summary> Computes the inner product of two instances</summary>
private double innerProduct(Instance i1, Instance i2)
{
// we can do a fast dot product
double result = 0;
int n1 = i1.numValues(); int n2 = i2.numValues();
int classIndex = m_Train.classIndex();
for (int p1 = 0, p2 = 0; p1 < n1 && p2 < n2; )
{
int ind1 = i1.index(p1);
int ind2 = i2.index(p2);
if (ind1 == ind2)
{
if (ind1 != classIndex)
{
result += i1.valueSparse(p1) * i2.valueSparse(p2);
}
p1++; p2++;
}
else if (ind1 > ind2)
{
p2++;
}
else
{
p1++;
}
}
result += 1.0;
if (m_Exponent != 1)
{
return System.Math.Pow(result, m_Exponent);
}
else
{
return result;
}
}