示例#1
0
        public static void demo1()
        {
            // Gamma distribution

            // define distribution parameters
            double mean     = 5;
            double variance = 1.5;
            double alpha    = mean * mean / variance;
            double lambda   = 1 / (variance / mean);

            // for tests and debugging use a random engine with CONSTANT seed --> deterministic and reproducible results
            RandomEngine engine = new MersenneTwister();

            // your favourite distribution goes here
            AbstractDistribution dist = new Gamma(alpha, lambda, engine);

            // collect random numbers and print statistics
            int size    = 100000;
            var numbers = new DoubleArrayList(size);

            for (int i = 0; i < size; i++)
            {
                numbers.Add(dist.NextDouble());
            }

            DynamicBin1D bin = new DynamicBin1D();

            bin.AddAllOf(numbers);
            Console.WriteLine(bin);
        }
示例#2
0
        /// <summary>
        /// /// Fills all cell values of the given vector into a bin from which statistics measures can be retrieved efficiently.
        /// Cells values are copied.
        /// </summary>
        /// <param name="vector">the vector to analyze.</param>
        /// <returns>a bin holding the statistics measures of the vector.</returns>
        /// <example>
        /// Tip: Use <i>Console.WriteLine(bin(vector))</i> to print most measures computed by the bind Example:
        /// <table>
        /// <td class="PRE">
        /// <pre>
        /// Size: 20000
        /// Sum: 299858.02350278624
        /// SumOfSquares: 5399184.154095971
        /// Min: 0.8639113139711261
        /// Max: 59.75331890541892
        /// Mean: 14.992901175139313
        /// RMS: 16.43043540825375
        /// Variance: 45.17438077634358
        /// Standard deviation: 6.721188940681818
        /// Standard error: 0.04752598277592142
        /// Geometric mean: 13.516615397064466
        /// Product: Infinity
        /// Harmonic mean: 11.995174297952191
        /// Sum of inversions: 1667.337172700724
        /// Skew: 0.8922838940067878
        /// Kurtosis: 1.1915828121825598
        /// Sum of powers(3): 1.1345828465808412E8
        /// Sum of powers(4): 2.7251055344494686E9
        /// Sum of powers(5): 7.367125643433887E10
        /// Sum of powers(6): 2.215370909100143E12
        /// Moment(0,0): 1.0
        /// Moment(1,0): 14.992901175139313
        /// Moment(2,0): 269.95920770479853
        /// Moment(3,0): 5672.914232904206
        /// Moment(4,0): 136255.27672247344
        /// Moment(5,0): 3683562.8217169433
        /// Moment(6,0): 1.1076854545500715E8
        /// Moment(0,mean()): 1.0
        /// Moment(1,mean()): -2.0806734113421045E-14
        /// Moment(2,mean()): 45.172122057305664
        /// Moment(3,mean()): 270.92018671421
        /// Moment(4,mean()): 8553.8664869067
        /// Moment(5,mean()): 153357.41712233616
        /// Moment(6,mean()): 4273757.570142922
        /// 25%, 50% and 75% Quantiles: 10.030074811938091, 13.977982089912224,
        /// 18.86124362967137
        /// quantileInverse(mean): 0.559163335012079
        /// Distinct elements & frequencies not printed (too many).
        /// </pre>
        /// </td>
        /// </table>
        /// </example>
        public static DynamicBin1D Bin(DoubleMatrix1D vector)
        {
            DynamicBin1D bin = new DynamicBin1D();

            bin.AddAllOf(new DoubleArrayList(DoubleFactory1D.Dense.ToList(vector).ToArray()));
            return(bin);
        }
示例#3
0
        /// <summary>
        /// Applies the given aggregation functions to each column and stores the results in a the result matrix.
        /// If matrix has shape <i>m x n</i>, then result must have shape <i>aggr.Length x n</i>.
        /// Tip: To do aggregations on rows use dice views (transpositions), as in <i>aggregate(matrix.viewDice(),aggr,result.viewDice())</i>.
        /// </summary>
        /// <param name="matrix">any matrix; a column holds the values of a given variable.</param>
        /// <param name="aggr">the aggregation functions to be applied to each column.</param>
        /// <param name="result">the matrix to hold the aggregation results.</param>
        /// <returns><i>result</i> (for convenience only).</returns>
        /// <see cref="Formatter"/>
        /// <see cref="Hep.Aida.Bin.BinFunction1D"/>
        /// <see cref="Hep.Aida.Bin.BinFunctions1D"/>
        public static DoubleMatrix2D Aggregate(DoubleMatrix2D matrix, Hep.Aida.Bin.BinFunction1D[] aggr, DoubleMatrix2D result)
        {
            var bin      = new DynamicBin1D();
            var elements = new double[matrix.Rows];
            var values   = elements;

            for (int column = matrix.Columns; --column >= 0;)
            {
                matrix.ViewColumn(column).ToArray(ref elements); // copy column into values
                bin.Clear();
                bin.AddAllOf(new DoubleArrayList(values));
                for (int i = aggr.Length; --i >= 0;)
                {
                    result[i, column] = aggr[i](bin);
                }
            }
            return(result);
        }