public void ExponentialFitUncertainty() { // check that the uncertainty in reported fit parameters is actually meaningful // it should be the standard deviation of fit parameter values in a sample of many fits // define a population distribution ExponentialDistribution distribution = new ExponentialDistribution(4.0); // draw a lot of samples from it; fit each sample and // record the reported parameter value and error of each Sample values = new Sample(); Sample uncertainties = new Sample(); for (int i = 0; i < 128; i++) { Sample sample = SampleTest.CreateSample(distribution, 8, i); ExponentialFitResult fit = ExponentialDistribution.FitToSample(sample); UncertainValue lambda = fit.Parameters[0].Estimate; values.Add(lambda.Value); uncertainties.Add(lambda.Uncertainty); } // the reported values should agree with the source distribution Assert.IsTrue(values.PopulationMean.ConfidenceInterval(0.95).ClosedContains(distribution.Mean)); // the reported errors should agree with the standard deviation of the reported parameters Assert.IsTrue(values.PopulationStandardDeviation.ConfidenceInterval(0.95).ClosedContains(uncertainties.Mean)); }
public void ExponentialFit() { ExponentialDistribution distribution = new ExponentialDistribution(5.0); Sample sample = SampleTest.CreateSample(distribution, 100); // fit to normal should be bad NormalFitResult nfit = NormalDistribution.FitToSample(sample); Assert.IsTrue(nfit.GoodnessOfFit.Probability < 0.05); // fit to exponential should be good ExponentialFitResult efit = ExponentialDistribution.FitToSample(sample); Assert.IsTrue(efit.GoodnessOfFit.Probability > 0.05); Assert.IsTrue(efit.Mean.ConfidenceInterval(0.95).ClosedContains(distribution.Mean)); }
public void NormalFit() { // pick mu >> sigma so that we get no negative values; // otherwise the attempt to fit to an exponential will fail ContinuousDistribution distribution = new NormalDistribution(6.0, 2.0); Sample sample = SampleTest.CreateSample(distribution, 100); // fit to normal should be good NormalFitResult nfit = NormalDistribution.FitToSample(sample); Assert.IsTrue(nfit.GoodnessOfFit.Probability > 0.05); Assert.IsTrue(nfit.Mean.ConfidenceInterval(0.95).ClosedContains(distribution.Mean)); Assert.IsTrue(nfit.StandardDeviation.ConfidenceInterval(0.95).ClosedContains(distribution.StandardDeviation)); // fit to exponential should be bad ExponentialFitResult efit = ExponentialDistribution.FitToSample(sample); Assert.IsTrue(efit.GoodnessOfFit.Probability < 0.05); }