当前位置: 首页>>代码示例>>C#>>正文


C# MatrixValue.Sum方法代码示例

本文整理汇总了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));
        }
开发者ID:FlorianRappl,项目名称:YAMP,代码行数:12,代码来源:DevFunction.cs

示例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;
        }
开发者ID:FlorianRappl,项目名称:YAMP,代码行数:44,代码来源:YMath.cs

示例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;
        }
开发者ID:FlorianRappl,项目名称:YAMP,代码行数:67,代码来源:DistFunction.cs


注:本文中的YAMP.MatrixValue.Sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。