本文整理汇总了C#中YAMP.MatrixValue.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# MatrixValue.Sum方法的具体用法?C# MatrixValue.Sum怎么用?C# MatrixValue.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YAMP.MatrixValue
的用法示例。
在下文中一共展示了MatrixValue.Sum方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Function
public ScalarValue Function(MatrixValue M)
{
var deviation = ScalarValue.Zero;
var mean = M.Sum() / M.Length;
for (var i = 1; i <= M.Length; i++)
{
deviation += (M[i] - mean).Square();
}
return new ScalarValue(Math.Sqrt(deviation.Abs() / M.Length));
}
示例2: Variance
public static Value Variance(MatrixValue M)
{
if (M.Length == 0)
{
return ScalarValue.Zero;
}
if (M.IsVector)
{
var variance = ScalarValue.Zero;
var mean = M.Sum() / M.Length;
for (var i = 1; i <= M.Length; i++)
{
variance += (M[i] - mean).Square();
}
return variance / M.Length;
}
var avg = (MatrixValue)YMath.Average(M);
var scale = 1.0;
var s = new MatrixValue(1, M.DimensionX);
for (var i = 1; i <= M.DimensionY; i++)
{
for (var j = 1; j <= M.DimensionX; j++)
{
s[1, j] += (M[i, j] - avg[j]).Square();
}
}
scale /= M.DimensionY;
for (var i = 1; i <= s.DimensionY; i++)
{
for (var j = 1; j <= s.DimensionX; j++)
{
s[i, j] *= scale;
}
}
return s;
}
示例3: Function
public FunctionValue Function(MatrixValue Y, ScalarValue nbins, ScalarValue nParameters)
{
var nn = nbins.GetIntegerOrThrowException("nbins", Name);
var nP = nParameters.GetIntegerOrThrowException("nParameters", Name);
var N = Y.Length;
var min_idx = Y.Min();
var min = Y[min_idx.Row, min_idx.Column];
var max_idx = Y.Max();
var max = Y[max_idx.Row, max_idx.Column];
var median = YMath.Median(Y);
var variance = ScalarValue.Zero;
var mean = Y.Sum() / Y.Length;
for (var i = 1; i <= Y.Length; i++)
{
variance += (Y[i] - mean).Square();
}
variance /= Y.Length;
var delta = (max - min) / nn;
var x = new MatrixValue(nn, 1);
for (var i = 0; i < nn; i++)
{
x[i + 1] = min + delta * i;
}
var histogram = new HistogramFunction();
var fx = histogram.Function(Y, x);
var linearfit = new LinfitFunction(Context);
var dist = linearfit.Function(x, fx, new FunctionValue((context, argument) =>
{
var _x = (argument as ScalarValue - median / 2) / (variance / 4);
var _exp_x_2 = (-_x * _x).Exp();
var result = new MatrixValue(1, nP - 1);
for (var i = 0; i < nP - 1; i++)
{
result[i + 1] = _exp_x_2 * _x.Pow(new ScalarValue(i));
}
return result;
}, true));
var norm = Y.Length * (max - min) / nbins;
var normed_dist = new FunctionValue((context, argument) =>
{
var temp = dist.Perform(context, argument);
if (temp is ScalarValue)
{
return ((ScalarValue)temp) / norm;
}
else if (temp is MatrixValue)
{
return ((MatrixValue)temp) / norm;
}
throw new YAMPOperationInvalidException();
}, true);
return normed_dist;
}