Exemple #1
0
        public void Bug7213()
        {
            Sample s = new Sample();

            s.Add(0.00590056, 0.00654598, 0.0066506, 0.00679065, 0.008826);
            WeibullFitResult r = WeibullDistribution.FitToSample(s);
        }
Exemple #2
0
        public static void FitToDistribution()
        {
            Random rng = new Random(7);
            WeibullDistribution distribution = new WeibullDistribution(3.0, 1.5);
            List <double>       sample       = distribution.GetRandomValues(rng, 500).ToList();

            WeibullFitResult weibull = sample.FitToWeibull();

            Console.WriteLine($"Best fit scale: {weibull.Scale}");
            Console.WriteLine($"Best fit shape: {weibull.Shape}");
            Console.WriteLine($"Probability of fit: {weibull.GoodnessOfFit.Probability}");

            LognormalFitResult lognormal = sample.FitToLognormal();

            Console.WriteLine($"Best fit mu: {lognormal.Mu}");
            Console.WriteLine($"Best fit sigma: {lognormal.Sigma}");
            Console.WriteLine($"Probability of fit: {lognormal.GoodnessOfFit.Probability}");

            var result = sample.MaximumLikelihoodFit(parameters => {
                return(new WeibullDistribution(parameters["Scale"], parameters["Shape"]));
            },
                                                     new Dictionary <string, double>()
            {
                { "Scale", 1.0 }, { "Shape", 1.0 }
            }
                                                     );

            foreach (Parameter parameter in result.Parameters)
            {
                Console.WriteLine($"{parameter.Name} = {parameter.Estimate}");
            }
        }
Exemple #3
0
        public void Bug7953()
        {
            // Fitting this sample to a Weibull caused a NonconvergenceException in the root finder that was used inside the fit method.
            // The underlying problem was that our equation to solve involved x^k and k ~ 2000 and (~12)^(~2000) overflows double
            // so all the quantities became Infinity and the root-finder never converged. We changed the algorithm to operate on
            // w = log x - <log x> which keeps quantities much smaller.

            Sample sample = new Sample(
                12.824, 12.855, 12.861, 12.862, 12.863,
                12.864, 12.865, 12.866, 12.866, 12.866,
                12.867, 12.867, 12.868, 12.868, 12.870,
                12.871, 12.871, 12.871, 12.871, 12.872,
                12.876, 12.878, 12.879, 12.879, 12.881
                );

            WeibullFitResult result = WeibullDistribution.FitToSample(sample);

            Console.WriteLine("{0} {1}", result.Scale, result.Shape);
            Console.WriteLine(result.GoodnessOfFit.Probability);
        }