Accord.Statistics.Distributions.Univariate.BernoulliDistribution.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)
        {
            double mean = observations.Mean(weights);
            return new BernoulliDistribution(mean);
        }

Usage Example

        public void GenerationTest()
        {
            double prob = 0.5;
            int trials = 10000;

            BernoulliDistribution target = new BernoulliDistribution(prob);
            target.Fit(target.Generate(trials).Select(x => (double)x).ToArray());

            Assert.AreEqual(target.Mean, prob, 0.01);
        }