After executing cmaOptimDP, there is a current population and a best-ever solution. Evaluate for the mean of the current population whether it is feasible and whether the mean is an even better solution. If so, update the best-ever solution.
Every direct method of classes in the CMA-ES Java package cmaes (see [Hansen09] for the complete Javadoc and [Hansen13] for an overview on CMA-ES in total) can be accessed with the .jcall-mechanism of the list("rJava") R package:
rJava::.jcall(obj,returnType,method,...)
where ... stands for the calling parameter(s) of method.
returnType is a string following the JNI type convention (see, e.g. [Oracle14])
Field Descriptor
Java Language Type
Z
boolean
C
char
I
int
J
long
F
float
D
double
[I
int[]
[[D
double[][]
Ljava/langString;
java.lang.String
S
java.lang.String
T
short
(Note: (a) the terminating ";" in "Ljava/langString;" (!) and (b) "S" is a short hand for "Ljava/langString;" and
"T" is the re-mapped code for short. )
The calling parameters in ... have to be matched exactly. In R, numeric vectors are stored as doubles, so the calling syntax
is just right for the Java method setFitnessOfMeanX(double[]). In other cases, the calling R variable x
has to be cast explicitly:
Cast
Java Language Type
.jbyte(x)
byte
.jchar(x)
char
as.integer(x)
int
.jlong(x)
long
.jfloat(x)
float
Examples
## Not run:## just to show the syntax, without calling cmaOptimDP fitFunc <-function(x){ sum(x*x);} isFeasible <-function(x){TRUE;} cma <- cmaNew(propFile="CMAEvolutionStrategy.properties"); cmaInit(cma,dimension=2,initialX=1.5); bestSolution=cmaEvalMeanX(cma,fitFunc,isFeasible); str(bestSolution);## End(Not run)