
Hi.
I am about to write a 3 parameter Weibull distribution with location as the 3rd parameter. It would be helpful to know if the Meta.Numerics.Statistics.Sample.MaximumLikelihoodFit method supported more than 2 parameters... otherwise
I will have to write a kludge which will work but is clumsy and slow :(
So the question: does the MaximumLikelihoodFit method support 3 parameters?
BTW. a great library. Thanks!


Coordinator
Jun 17, 2012 at 6:24 AM

Yes, Sample.MaximumLiklihoodFit supports an arbitrary number of parameters. You just need to make your distribution class implement IParameterizedDistribution and the Sample's MaximumLiklihoodFit will take care of finding the parameter set for your
distribution which best fits the sample.
To make this just a little more concrete, here's some sample code. It leaves out some implementation details, but should still make it a bit clearer how this works.
public class MyDistribution : Distribution, IParameterizedDistribution {
// the distribution's parameters
private double a, b, c;
// typically, these are set in a constructor
public MyDistribution (double a, double b, double c) {
this.a = a;
this.b = b;
this.c = c;
}
// now implement the Distribution methods, including
// most importantly, the ProbabilityDensity method
// now implement the IParameterizedDistribution methods
public double[] GetParameters () {
// just return the parameters as a vector
return(new double[] {a, b, c});
}
public void SetParameters (IList<double> parameters) {
// just set the parameters from the vector
a = parameters[0];
b = parameters[1];
c = parameters[2];
}
public double Liklihood (double x) {
// this is typically just the probability density of the value
return(ProbabilityDensity(x));
}
}
// to do a maximum liklihood fit on an existing sample,
// new up a distribution class with your initial guess for the
// parameters, then call the fit method
MyDistrubtion d = new MyDistribution(1.0, 2.0, 3.0);
s.MaximumLiklihoodFit(d);
// when it returns, d's parameters will have changed from your
// initial guess to the values that best fit the sample
By the way, that code is "notepad compiled" so I make no strong guarantees about its correctness. It's just supposed to get across the general idea.

