private void fitMLE(double sum1, double sum2, double n) { double[] gradient = new double[2]; var bfgs = new BoundedBroydenFletcherGoldfarbShanno(numberOfVariables: 2); bfgs.LowerBounds[0] = 1e-100; bfgs.LowerBounds[1] = 1e-100; bfgs.Solution[0] = this.alpha; bfgs.Solution[1] = this.beta; bfgs.Function = (double[] parameters) => BetaDistribution.LogLikelihood(sum1, sum2, n, parameters[0], parameters[1]); bfgs.Gradient = (double[] parameters) => BetaDistribution.Gradient(sum1, sum2, n, parameters[0], parameters[1], gradient); if (!bfgs.Minimize()) { throw new ConvergenceException(); } this.alpha = bfgs.Solution[0]; this.beta = bfgs.Solution[1]; }