Package gov.nih.mipav.model.algorithms
Class NMSimplex
java.lang.Object
gov.nih.mipav.model.algorithms.NMSimplex
Example
public class Objfunc implements Objfun
{
public double evalObjfun(double x[]){
return (100*(x[1]-x[0]*x[0])*(x[1]-x[0]*x[0])+(1.0-x[0])*(1.0-x[0]));
}
}
public class Constraint implements Constraints
{
double round2(double num, int precision)
{
double rnum;
int tnum;
rnum = num*Math.pow(10,precision);
tnum = (int)(rnum invalid input: '<' 0 ? rnum-0.5 : rnum + 0.5);
rnum = tnum/Math.pow(10,precision);
return rnum;
}
public void getConstrainedValues(double x[], int n) {
// round to 2 decimal places
int i;
for (i=0; iinvalid input: '<'n; i++) {
x[i] = round2(x[i],2);
}
}
}
public class Testfun
{
public static void main(String[] args) throws IOException
{
double start[] = {-1.2,1.0};
int dim = 2;
double eps = 1.0e-4;
double scale = 1.0;
boolean display = true;
int i;
NMSimplex simplex = new NMSimplex(start,dim,eps,scale,display);
for (i=0; iinvalid input: '<'dim; i++) {
System.out.format("%f\n",start[i]);
}
}
}
My run of Rosenbrock example gives:
Starting at double x0[] = new double[]{0.0,0.0};
The minimum was found at
1.000000e+00
1.000000e+00
101 Function Evaluations
50 Iterations through program
This agrees with Nike Hutt's answer:
Initial Values
0.00, 0.00, value 1.00
0.97, 0.26, value 46.36
0.26, 0.97, value 81.98
102 Function Evaluations
50 Iterations through program
The minimum was found at
1.00, 1.00, value 0.00
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final double(package private) static final doubleprivate booleanprivate double(package private) static final double(package private) static final intprivate intprivate doubleprivate double[] -
Constructor Summary
ConstructorsConstructorDescriptionNMSimplex(double[] start, int n, double EPSILON, double scale, boolean display) -
Method Summary
Modifier and TypeMethodDescriptionvoiddriver()abstract doubleevalObjfun(double[] x) abstract voidgetConstrainedValues(double[] x, int n)
-
Field Details
-
MAX_IT
static final int MAX_IT- See Also:
-
ALPHA
static final double ALPHA- See Also:
-
BETA
static final double BETA- See Also:
-
GAMMA
static final double GAMMA- See Also:
-
start
private double[] start -
n
private int n -
EPSILON
private double EPSILON -
scale
private double scale -
display
private boolean display
-
-
Constructor Details
-
NMSimplex
public NMSimplex(double[] start, int n, double EPSILON, double scale, boolean display)
-
-
Method Details
-
driver
public void driver() -
getConstrainedValues
public abstract void getConstrainedValues(double[] x, int n) -
evalObjfun
public abstract double evalObjfun(double[] x)
-