YAMP.YMath.Histogram C# (CSharp) Method

Histogram() public static method

public static Histogram ( MatrixValue v, Double centers ) : MatrixValue
v MatrixValue
centers Double
return MatrixValue
        public static MatrixValue Histogram(MatrixValue v, Double[] centers)
        {
            if (centers.Length == 0)
                throw new YAMPWrongLengthException(0, 1);

            var H = new MatrixValue(centers.Length, 1);
            var N = new int[centers.Length];
            var last = centers.Length - 1;

            for (var i = 1; i <= v.Length; i++)
            {
                var y = v[i].Re;

                if (y < centers[0])
                {
                    N[0]++;
                }
                else if (y > centers[last])
                {
                    N[last]++;
                }
                else
                {
                    var min = Double.MaxValue;
                    var index = 0;

                    for (var j = 0; j < centers.Length; j++)
                    {
                        var dist = Math.Abs(y - centers[j]);

                        if (dist < min)
                        {
                            index = j;
                            min = dist;
                        }
                    }

                    N[index]++;
                }
            }

            for (var i = 1; i <= centers.Length; i++)
            {
                H[i, 1] = new ScalarValue(N[i - 1]);
            }

            return H;
        }

Same methods

YMath::Histogram ( MatrixValue v, Int32 nbins ) : MatrixValue

Usage Example

Exemplo n.º 1
0
        public BarPlotValue Function(MatrixValue Y, MatrixValue x)
        {
            var bp = new BarPlotValue();
            var X  = new double[x.Length];

            for (var i = 0; i < x.Length; i++)
            {
                X[i] = x[i + 1].Re;
            }

            if (Y.IsVector)
            {
                bp.AddPoints(YMath.Histogram(Y, X));
            }
            else
            {
                var M = new MatrixValue();

                for (var i = 1; i <= Y.DimensionX; i++)
                {
                    var N = YMath.Histogram(Y.GetColumnVector(i), X);

                    for (var j = 1; j <= N.Length; j++)
                    {
                        M[j, i] = N[j];
                    }
                }

                bp.AddPoints(M);
            }

            return(bp);
        }
All Usage Examples Of YAMP.YMath::Histogram