cmaEvalMeanX {rCMA} | R Documentation |
Evaluate the meanX of the current population.
Description
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.
Usage
cmaEvalMeanX(cma, fitFunc, isFeasible = function(x) TRUE)
Arguments
cma |
CMA-ES Java object, already initialized with |
fitFunc |
a function to be minimized. Signature: accepts a vector x, returns a double. |
isFeasible |
[ |
Details
The code of this function is also instructive as a full example for the extensibility of the
rJava
interface to CMA-ES. See the full code in demo/demoEvalMeanX
. Some example rJava
-calls are:
rJava::.jcall(cma,"[D","getMeanX"); bestSolutionObj = rJava::.jcall(cma,"Lfr/inria/optimization/cmaes/CMASolution;","setFitnessOfMeanX",fitFunc(meanX)); rJava::.jcall(bestSolutionObj,"J","getEvaluationNumber");
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 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
bestSolutionObj = .jcall(cma,rType,"setFitnessOfMeanX",fitFunc(meanX));
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 | |
Value
bestSolution
, a list with entries:
bestX |
a vector of length |
meanX |
a vector of length |
bestFitness |
the best-ever fitness value, including the evaluation of meanX |
bestEvalNum |
the function evaluation count where |
lastEvalNum |
the total function evaluation count. If |
Author(s)
Wolfgang Konen, FHK, 2013-2015
References
[Hansen09] https://www.lri.fr/~hansen/javadoc Nikolaus Hansen: Javadoc for CMA-ES Java package fr.inria.optimization.cmaes, 2009.
[Hansen13] https://www.lri.fr/~hansen/cmaesintro.html Nikolaus Hansen: The CMA Evolution Strategy, 2013.
[Oracle14] http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html
Oracle: The Java Native Interface. Programmer's Guide and Specification.
Chapter 3 (JNI types), Sec. 'Type Signatures', 2014.
See Also
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)