# commons-user mailing list archives

##### Site index · List index
Message view
Top
Subject [math] Parametric Estimation How can I use this clases to minimize functions
Date Fri, 01 Aug 2008 18:17:46 GMT
Hello to all,

I am interested in using a LevenbergMarquardt method in order to
minimize functions (say the classical Rosebrook banana function). I
try to use your LevenbergMarquardtEstimator to do this, but i have
problem with the EstimationProblem definition.

In my context I don't know what a measurement is. I have asumed that a
measurement is a element of the f(x) vector.
In another words:
double[] fx = function.eval(x); // each fx[i] is asumed to be a measurment

I made the problem stimation with this asumptions but I dont have the
spected results.

What I am doing wrong? My asumptions are valid? There is a way to
Nelson Arape

PS: My Estimation Problem -------
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.math.estimation.EstimatedParameter;
import org.apache.commons.math.estimation.SimpleEstimationProblem;
import org.apache.commons.math.estimation.WeightedMeasurement;

/**
* Estimation problem for the minimization of the Rosenbrock function, which has
* a global minimum at (1, 1)
*/
public class RosProblem extends SimpleEstimationProblem {
private static final double ROSD = 105.0;
private static final int N = 2; // Number of elements of the f(x) vector

private EstimatedParameter[] x;
/** Cache for easy parameter -> index lookup */
private Map<EstimatedParameter, Integer> paramIdxCache;

/**
* Constructor for the RosProblem
*
* @param x
*            the initial point
*/
public RosProblem(double[] x) {
this.x = new EstimatedParameter[x.length];
this.paramIdxCache = new HashMap<EstimatedParameter, Integer>();

for (int i = 0; i < x.length; i++) {
this.x[i] = new EstimatedParameter("x" + i, x[i]);
paramIdxCache.put(this.x[i], i);
}

for (int i = 0; i < N; i++) {
}
}

/**
* Get all the parameter as double array
*
* @return double array of the estimated parameters
*/
public double[] getX() {
double[] x = new double[this.x.length];
for (int i = 0; i < x.length; i++) {
x[i] = this.x[i].getEstimate();
}
return x;
}

/**
* Evaluates the Rosenbrock function at <code>x</code>
*
* @param x
*            the point
* @param fx
*            In order to avoid repeated allocations, this array will used
*            to write the return value. If null, a new array will be
*            created
* @return fx Rosenbrock function at <code>x</code>
*/
public double[] eval(double[] x, double[] fx) {
if (fx == null) {
fx = new double[N];
}
for (int i = 0; i < N; ++i) {
double x0 = x[0];
double x1 = x[1];
fx[i] = ((1.0 - x0) * (1.0 - x0) + ROSD * (x1 - x0 * x0) *
(x1 - x0 * x0));
}
return fx;
}

/**
* Evaluates the Jacobian of the Rosenbrock function at <code>x</code>
*
* @param x
*            the point
* @param jac
*            In order to avoid repeated allocations, this matrix will used
*            to write the return value. If null, a new matrix will be
*            created
* @return jac Jacobian of the Rosenbrock function at <code>x</code>
*/
public double[][] jacf(double[] x, double[][] jac) {
if (jac == null) {
jac = new double[N][N];
}
for (int i = 0; i < N; ++i) {
double x0 = x[0];
double x1 = x[1];
jac[i][0] = -2 + 2 * x0 - 4 * ROSD * (x1 - x0 * x0) * x0;
jac[i][1] = 2 * ROSD * (x1 - x0 * x0);
}
return jac;
}

/**
* A Measurement for estimation problem. Each Measurement correspond to each
* element of the f(x) vector
*
* @author narape
*/
private class ProblemMeasurement extends WeightedMeasurement {
private int index; // This measure index of the f(x) vector

public ProblemMeasurement(int i) {
super(1.0, 0.0); // Equal weight, target value 0
index = i;
}

@Override
public double getTheoreticalValue() {
double[] x = getX(); // get estimation Vector: x
double[] fx = eval(x, null); // calc f(x)
return fx[index]; // return f(x) element of this measurement
}

@Override
public double getPartial(EstimatedParameter parameter) {
double[] x = getX(); // get estimation Vector: x
double[][] jac = jacf(x, null); // calc the Jacobian of f(x)
Integer paramIndex = paramIdxCache.get(parameter);
return jac[paramIndex][index];
}
}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org