本文整理汇总了C#中numl.Math.LinearAlgebra.Vector.Each方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Each方法的具体用法?C# Vector.Each怎么用?C# Vector.Each使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numl.Math.LinearAlgebra.Vector
的用法示例。
在下文中一共展示了Vector.Each方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compute
/// <summary>
/// Returns a softmax function vector from the supplied inputs.
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public Vector Compute(Vector x)
{
double max = x.Max();
Vector softmax = x.Each(v => System.Math.Exp(v - max));
double sum = softmax.Sum();
softmax = softmax.Each(s => s / sum);
return softmax;
}
示例2: Normal
/// <summary>Compute probability according to multivariate Gaussian.</summary>
/// <param name="x">Vector in question.</param>
/// <param name="mu">Mean.</param>
/// <param name="sigma">diag(covariance)</param>
/// <returns>Probability.</returns>
public double Normal(Vector x, Vector mu, Vector sigma)
{
var p = 1 / sqrt(pow(2 * System.Math.PI, mu.Length) * sigma.Prod());
var exp = -0.5d * ((x - mu) * sigma.Each(d => 1 / d, true)).Dot(x - mu);
var e_exp = pow(System.Math.E, exp);
return p * e_exp;
}
示例3: Normal
/// <summary>
/// Compute probability according to multivariate Gaussian
/// </summary>
/// <param name="x">Vector in question</param>
/// <param name="mu">Mean</param>
/// <param name="sigma">diag(covariance)</param>
/// <returns>Probability</returns>
private double Normal(Vector x, Vector mu, Vector sigma)
{
// 1 / (2pi)^(2/D) where D = length of sigma
var one_over_2pi = 1 / System.Math.Pow(2 * System.Math.PI, 2 / sigma.Length);
// 1 / sqrt(det(sigma)) where det(sigma) is the product of the diagonals
var one_over_det_sigma = System.Math.Sqrt(sigma.Aggregate(1d, (a, i) => a *= i));
// -.5 (x-mu).T sigma^-1 (x-mu) I have taken some liberties ;)
var exp = -0.5d * ((x - mu) * sigma.Each(d => 1 / d, true)).Dot(x - mu);
// e^(exp)
var e_exp = System.Math.Pow(System.Math.E, exp);
var result = one_over_2pi * one_over_det_sigma * e_exp;
return result;
}
示例4: Initialize
/// <summary>
/// Initializes the selection function.
/// </summary>
/// <param name="alpha">Alpha vector</param>
/// <param name="gradient">Gradient vector.</param>
public void Initialize(Vector alpha, Vector gradient)
{
alpha.Each((d) => 0, false);
gradient.Each((d) => -1, false);
}