Accord.Statistics.Distributions.Multivariate.NormalDistribution.Fit C# (CSharp) Method

Fit() public method

Fits the underlying distribution to a given set of observations.
public Fit ( double observations, double weights ) : IDistribution
observations double /// The array of observations to fit the model against. ///
weights double /// The weight vector containing the weight for each of the samples. ///
return IDistribution
        public override IDistribution Fit(double[][] observations, double[] weights)
        {
#if DEBUG
            for (int i = 0; i < weights.Length; i++)
                if (Double.IsNaN(weights[i]) || Double.IsInfinity(weights[i]))
                    throw new Exception("Invalid numbers in the weight vector.");
#endif
            // Compute weighted mean vector
            double[] means = Tools.Mean(observations, weights);

            // Compute weighted covariance matrix
            double[,] cov = Tools.Covariance(observations, means, weights);

            // return the newly fitted distribution.
            return new NormalDistribution(means, cov);
        }