本文整理汇总了C#中SparseVector.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# SparseVector.Normalize方法的具体用法?C# SparseVector.Normalize怎么用?C# SparseVector.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseVector
的用法示例。
在下文中一共展示了SparseVector.Normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildExample
private static void BuildExample(TextExample example, Vocabulary voc, int exampleCount)
{
int dimension = voc.Count;
SparseVector vector = new SparseVector(dimension);
foreach (string word in example.Tokens.Keys)
{
int pos = voc.GetWordPosition(word);
if (pos == Constants.KEY_NOT_FOUND)
continue;
// phi i(x) = tfi log(idfi) /k
// tfi: number of occurences of the term i in the document x
// idfi: the ratio between the total number of documents and the
// number of documents containing the term
// k: normalisation constant ensuring that ||phi|| = 1
double phi = example.Tokens[word] * Math.Log(exampleCount / voc.WordExampleOccurMap[word]);
vector.Components.Add(pos, phi);
}
vector.Normalize();
example.X = vector;
}
示例2: NormalizeThrowsExceptionWhenNullVector
public void NormalizeThrowsExceptionWhenNullVector()
{
SparseVector v = new SparseVector(5);
v.Normalize();
}