You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Vincent Wolowski <vw...@gmail.com> on 2012/05/14 18:43:48 UTC
[math] fitting hill equation & parameter estimation
Hi all,
I am having some troubles fitting data to a hill equation
in order to estimate the dissociation constant.
I would be thankful for your advise.
The details:
The hill equation is the following:
x^h / (x^h + Kd^h) * s
An example of the data is the following:
x, y
1.0, 2.5118
5.0, 6.8069
25.0, 16.4898
125.0, 24.8289
625.0, 18.2857
In R I used the nls package and I have done the following which works fine:
ints_values <- c(2.5118, 6.8069, 16.4898, 24.8289, 18.2857)
datapoints <- data.frame(x = c(1,5,25,125,625), intensity = ints_values)
model <- nls(intensity ~ (x^h / (x^h + Kd^h) * s),
data = datapoints,
start = list(Kd=90, h=1.8, s=0.8),
upper = c(1000,2,1),
lower = c(1,1,0.4),
algorithm = "port",
trace = TRUE)
res <- coef(model)[1]
print(res) // shows Kd
I tried the following with the Apache commons math lib (see below) but
the fitting does not work.
Is it the right approach to use the LevenbergMarquardtOptimizer here?
...
CurveFitter fitter = new CurveFitter(new LevenbergMarquardtOptimizer());
...
fitter.addObservedPoint(1.0, 2.5118);
fitter.addObservedPoint(5.0, 6.8069);
...
ParametricUnivariateFunction hill_equation = new HillFunction();
// 0:h=1.8, 1:Kd=90, 2:s=0.8
double[] initialguess = new double[3];
initialguess[0] = 1.8;
initialguess[1] = 90.0;
initialguess[2] = 2.0;
double[] parameter_estimations = fitter.fit(hill_equation, initialguess);
private static class HillFunction implements ParametricUnivariateFunction {
public double value(double x, double[] params)
{
double h = params[0];
double Kd = params[1];
double s = params[2];
return (Math.pow(x,h) / (Math.pow(x,h) + Math.pow(Kd,h)) * s);
}
public double[] gradient(double x, double[] params)
{
double h = params[0];
double Kd = params[1];
double s = params[2];
double[] gradientVector = new double[params.length];
gradientVector[0] = // differentiate hill equation with respect to h
gradientVector[1] = // differentiate hill equation with respect to Kd
gradientVector[2] = // differentiate hill equation with respect to s
return gradientVector;
}
}
Also tried to apply a DifferentiableMultivariateVectorFunction with an
Jacobian matrix, but no fitting either.
Best regards,
Vincent
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org