本文整理匯總了C#中numl.Math.LinearAlgebra.Vector.Sum方法的典型用法代碼示例。如果您正苦於以下問題:C# Vector.Sum方法的具體用法?C# Vector.Sum怎麽用?C# Vector.Sum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numl.Math.LinearAlgebra.Vector
的用法示例。
在下文中一共展示了Vector.Sum方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Compute
/// <summary>Computes.</summary>
/// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
/// <param name="x">The Vector to process.</param>
/// <param name="y">The Vector to process.</param>
/// <returns>A double.</returns>
public double Compute(Vector x, Vector y)
{
if (x.Length != y.Length)
throw new InvalidOperationException("Cannot compute similarity between two unequally sized Vectors!");
var xSum = x.Sum();
var ySum = y.Sum();
var xElem = (x^2).Sum() - ((xSum * xSum) / x.Length);
var yElem = (y^2).Sum() - ((ySum * ySum) / y.Length);
return (x.Dot(y) - ((xSum * ySum) / x.Length)) / System.Math.Sqrt(xElem * yElem);
}