本文整理汇总了C#中Instance.weight方法的典型用法代码示例。如果您正苦于以下问题:C# Instance.weight方法的具体用法?C# Instance.weight怎么用?C# Instance.weight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Instance
的用法示例。
在下文中一共展示了Instance.weight方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: convertInstance
/// <summary> Convert a single instance over if the class is nominal. 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)
{
double[] vals = new double[outputFormatPeek().numAttributes()];
int attSoFar = 0;
for (int j = 0; j < getInputFormat().numAttributes(); j++)
{
weka.core.Attribute att = getInputFormat().attribute(j);
if (!att.Nominal || (j == getInputFormat().classIndex()) || !m_Columns.isInRange(j))
{
vals[attSoFar] = instance.value_Renamed(j);
attSoFar++;
}
else
{
if (att.numValues() <= 2)
{
vals[attSoFar] = instance.value_Renamed(j);
attSoFar++;
}
else
{
if (instance.isMissing(j))
{
for (int k = 0; k < att.numValues(); k++)
{
vals[attSoFar + k] = instance.value_Renamed(j);
}
}
else
{
for (int k = 0; k < att.numValues(); k++)
{
//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 (k == (int) instance.value_Renamed(j))
{
vals[attSoFar + k] = 1;
}
else
{
vals[attSoFar + k] = 0;
}
}
}
attSoFar += att.numValues();
}
}
}
Instance inst = null;
if (instance is SparseInstance)
{
inst = new SparseInstance(instance.weight(), vals);
}
else
{
inst = new Instance(instance.weight(), vals);
}
copyStringValues(inst, false, instance.dataset(), InputStringIndex, getOutputFormat(), OutputStringIndex);
inst.Dataset = getOutputFormat();
push(inst);
}
示例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: updateStatsForPredictor
/// <summary> Updates all the statistics about a predictors performance for
/// the current test instance.
///
/// </summary>
/// <param name="predictedValue">the numeric value the classifier predicts
/// </param>
/// <param name="instance">the instance to be classified
/// </param>
/// <throws> Exception if the class of the instance is not </throws>
/// <summary> set
/// </summary>
protected internal virtual void updateStatsForPredictor(double predictedValue, Instance instance)
{
if (!instance.classIsMissing())
{
// Update stats
m_WithClass += instance.weight();
if (Instance.isMissingValue(predictedValue))
{
m_Unclassified += instance.weight();
return ;
}
m_SumClass += instance.weight() * instance.classValue();
m_SumSqrClass += instance.weight() * instance.classValue() * instance.classValue();
m_SumClassPredicted += instance.weight() * instance.classValue() * predictedValue;
m_SumPredicted += instance.weight() * predictedValue;
m_SumSqrPredicted += instance.weight() * predictedValue * predictedValue;
if (m_ErrorEstimator == null)
{
setNumericPriorsFromBuffer();
}
double predictedProb = Math.Max(m_ErrorEstimator.getProbability(predictedValue - instance.classValue()), MIN_SF_PROB);
double priorProb = Math.Max(m_PriorErrorEstimator.getProbability(instance.classValue()), MIN_SF_PROB);
m_SumSchemeEntropy -= Utils.log2(predictedProb) * instance.weight();
m_SumPriorEntropy -= Utils.log2(priorProb) * instance.weight();
m_ErrorEstimator.addValue(predictedValue - instance.classValue(), instance.weight());
updateNumericScores(makeDistribution(predictedValue), makeDistribution(instance.classValue()), instance.weight());
}
else
m_MissingClass += instance.weight();
}
示例4: updateStatsForClassifier
/// <summary> Updates all the statistics about a classifiers performance for
/// the current test instance.
///
/// </summary>
/// <param name="predictedDistribution">the probabilities assigned to
/// each class
/// </param>
/// <param name="instance">the instance to be classified
/// </param>
/// <throws> Exception if the class of the instance is not </throws>
/// <summary> set
/// </summary>
protected internal virtual void updateStatsForClassifier(double[] predictedDistribution, Instance instance)
{
//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'"
int actualClass = (int) instance.classValue();
if (!instance.classIsMissing())
{
updateMargins(predictedDistribution, actualClass, instance.weight());
// Determine the predicted class (doesn't detect multiple
// classifications)
int predictedClass = - 1;
double bestProb = 0.0;
for (int i = 0; i < m_NumClasses; i++)
{
if (predictedDistribution[i] > bestProb)
{
predictedClass = i;
bestProb = predictedDistribution[i];
}
}
m_WithClass += instance.weight();
// Determine misclassification cost
if (m_CostMatrix != null)
{
if (predictedClass < 0)
{
// For missing predictions, we assume the worst possible cost.
// This is pretty harsh.
// Perhaps we could take the negative of the cost of a correct
// prediction (-m_CostMatrix.getXmlElement(actualClass,actualClass)),
// although often this will be zero
m_TotalCost += instance.weight() * m_CostMatrix.getMaxCost(actualClass);
}
else
{
m_TotalCost += instance.weight() * m_CostMatrix.getXmlElement(actualClass, predictedClass);
}
}
// Update counts when no class was predicted
if (predictedClass < 0)
{
m_Unclassified += instance.weight();
return ;
}
double predictedProb = System.Math.Max(MIN_SF_PROB, predictedDistribution[actualClass]);
double priorProb = System.Math.Max(MIN_SF_PROB, m_ClassPriors[actualClass] / m_ClassPriorsSum);
if (predictedProb >= priorProb)
{
m_SumKBInfo += (Utils.log2(predictedProb) - Utils.log2(priorProb)) * instance.weight();
}
else
{
m_SumKBInfo -= (Utils.log2(1.0 - predictedProb) - Utils.log2(1.0 - priorProb)) * instance.weight();
}
m_SumSchemeEntropy -= Utils.log2(predictedProb) * instance.weight();
m_SumPriorEntropy -= Utils.log2(priorProb) * instance.weight();
updateNumericScores(predictedDistribution, makeDistribution(instance.classValue()), instance.weight());
// Update other stats
m_ConfusionMatrix[actualClass][predictedClass] += instance.weight();
if (predictedClass != actualClass)
{
m_Incorrect += instance.weight();
}
else
{
m_Correct += instance.weight();
}
}
else
{
m_MissingClass += instance.weight();
}
}
示例5: updatePriors
/// <summary> Updates the class prior probabilities (when incrementally
/// training)
///
/// </summary>
/// <param name="instance">the new training instance seen
/// </param>
/// <throws> Exception if the class of the instance is not </throws>
/// <summary> set
/// </summary>
public virtual void updatePriors(Instance instance)
{
if (!instance.classIsMissing())
{
if (!m_ClassIsNominal)
{
if (!instance.classIsMissing())
{
addNumericTrainClass(instance.classValue(), instance.weight());
}
}
else
{
//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'"
m_ClassPriors[(int) instance.classValue()] += instance.weight();
m_ClassPriorsSum += instance.weight();
}
}
}
示例6: shift
/// <summary> Shifts given instance from one bag to another one.
///
/// </summary>
/// <exception cref="Exception">if something goes wrong
/// </exception>
public void shift(int from, int to, Instance instance)
{
int classIndex;
double weight;
//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'"
classIndex = (int) instance.classValue();
weight = instance.weight();
m_perClassPerBag[from][classIndex] -= weight;
m_perClassPerBag[to][classIndex] += weight;
m_perBag[from] -= weight;
m_perBag[to] += weight;
}
示例7: addWeights
/// <summary> Adds given instance to all bags weighting it according to given weights.
///
/// </summary>
/// <exception cref="Exception">if something goes wrong
/// </exception>
public void addWeights(Instance instance, double[] weights)
{
int classIndex;
int i;
//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'"
classIndex = (int) instance.classValue();
for (i = 0; i < m_perBag.Length; i++)
{
double weight = instance.weight() * weights[i];
m_perClassPerBag[i][classIndex] = m_perClassPerBag[i][classIndex] + weight;
m_perBag[i] = m_perBag[i] + weight;
m_perClass[classIndex] = m_perClass[classIndex] + weight;
totaL = totaL + weight;
}
}