當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。