Comments (8)
Thanks for the suggestions.
Sorry, I didn't include the call sequence and options. You are correct that my 5th parameter has a smaller range. But other parameters have a bigger range.
I am optimizing a function with 18 parameters. The call sequence is as follows.
import cma
def cost_func(param_vector):
# do calculations
return cost_value
options = {'bounds': [
[0.0, 0.5, 0.5, 0.2, 0.8947368421052632, 0.0, 0.05, 0.0, 0.002, 0.038526039943027696, 0.4642503980947164, 0.01, 0.002, 0.0, 0.0, 0.0, 0.0, 0.0],
[10.0, 3.5, 10.0, 200.0, 1.0263157894736843, 25.0, 2.0, 25.0, 2.0, 3.8140779543597416, 2.785502388568298, 10.0, 2.0, 4.166666666666667, 4.0, 3.3333333333333335, 6.818181818181818, 3.1034482758620694]
],
'maxiter': 500,
'maxfevals': 50000,
'popsize': 1000,
'popsize_factor': 1,
'tolx': 1e-06,
'tolfun': 1e-06}
cma_es = cma.CMAEvolutionStrategy([1.0]*18, 0.5, options)
res = cma_es.optimize(cost_func)
following your suggestion, if I make the bounds between 0 to 1 for each parameter using cma.ScaleCoordinates
and set sigma0
as 0.25, then the warning doesn't come. Now I do as follows.
import cma
def cost_func(param_vector):
# do calculations
return cost_value
options = {'bounds': [
[0.0, 0.5, 0.5, 0.2, 0.8947368421052632, 0.0, 0.05, 0.0, 0.002, 0.038526039943027696, 0.4642503980947164, 0.01, 0.002, 0.0, 0.0, 0.0, 0.0, 0.0],
[10.0, 3.5, 10.0, 200.0, 1.0263157894736843, 25.0, 2.0, 25.0, 2.0, 3.8140779543597416, 2.785502388568298, 10.0, 2.0, 4.166666666666667, 4.0, 3.3333333333333335, 6.818181818181818, 3.1034482758620694]
],
'maxiter': 500,
'maxfevals': 50000,
'popsize': 1000,
'popsize_factor': 1,
'tolx': 1e-06,
'tolfun': 1e-06}
cost_func2 = cma.ScaleCoordinates(cost_func, multipliers=[ub - lb for ub, lb in zip(options['bounds'][1], options['bounds'][0])], zero=[-(lb/ub) for ub, lb in zip(options['bounds'][1], options['bounds'][0])])
options["bounds"] = [np.zeros(len(p_names)), np.ones(len(p_names))]
cma_es = cma.CMAEvolutionStrategy([0.5]*18, 0.25, options)
res = cma_es.optimize(cost_func)
from pycma.
I am not sure the argument
zero=[-(lb/ub) for...
is correct for parameters with nonzero lower bound, I think it should read -lb/(ub-lb) for ...
?
This is why the development branch now implements a simpler way to pass the actual lower values like
lower=options['bounds'][0]
However this would require for the time being to install the cma
package like
pip install git+https://github.com/CMA-ES/pycma.git@development
from pycma.
So, I thought multipliers * (xbest - zeros) should be the same as cost_func2.inverse(xbest).
It seems to me that multipliers * (xbest - zeros)
should be the same as cost_func2.transform(xbest)
and that's indeed what you want, my mistake.
from pycma.
It is (generally) useful to give the calling sequence and parameters and options used when asking a question about the output. The above warning comes most likely from the discrepancy between the difference between upper and lower bound of the fifth variable and a much larger (about tenfold) standard deviation given as input (sigma0
). Sampling far beyond the bound(s) makes little sense, hence the code is correcting this input.
You may want to check out the bounds and rescaling section of this notebook and/or these practical hints.
from pycma.
Thank you so much for checking it and suggesting the correction. The new cma.ScaleCoordinates
seems very convenient. Can it handle a parameter bound between negative lower bound to positive upper bound (for e.g., -5 to 30)?
Does pycma have any function to convert back the xbest
or fbest
values (which will be between 0 to 1) in res
dictionary to the actual parameter value (between the actual parameter range) or x_actual = multipliers * x_scaled + lower
work for both zero and non-zero values of lower bound?
I am currently using v3.3.0. Is there any significant difference between the v3.3.0 and the current development version? If not, then I will probably switch to the development version, or else I can correct my code as suggested by you.
from pycma.
Can it handle a parameter bound between negative lower bound to positive upper bound (for e.g., -5 to 30)?
Yes.
Does pycma have any function to convert back the xbest or fbest values (which will be between 0 to 1) in res dictionary to the actual parameter value (between the actual parameter range) or x_actual = multipliers * x_scaled + lower work for both zero and non-zero values of lower bound?
The ScaleCoordinates
class has an inverse
transform
method which should give the desired solution when applied to xbest
or xfavorite
like
cost_func2.transform(cma_es.result.xfavorite)
Just a caveat, cma_es.mean
is not necessarily in-bounds (it's a "genotype" solution), xfavorite
is (internally) computed as es.result.xfavorite == es.gp.pheno(es.mean, into_bounds=es.boundary_handler.repair)
.
I am currently using v3.3.0. Is there any significant difference between the v3.3.0 and the current development version?
There is no difference in the core functionalities.
from pycma.
Thank you so much for the clarifications.
The
ScaleCoordinates
class has aninverse
method which should give the desired solution when applied toxbest
orxfavorite
like
cost_func2.inverse(cma_es.result.xfavorite)
The following gives me True
and it seems the actual parameter values are multipliers * (xbest - zeros)
.
multipliers = [ub - lb for ub, lb in zip(options['bounds'][1], options['bounds'][0])]
zeros = [-lb/(ub-lb) for ub, lb in zip(options['bounds'][1], options['bounds'][0])]
cost_func(multipliers * (xbest - zeros)) == cost_func2(xbest)
So, I thought multipliers * (xbest - zeros)
should be the same as cost_func2.inverse(xbest)
. But in my case, they are not the same. So, I am a bit confused what's the correct way to get actual values of xbest
(multipliers * (xbest - zeros)
or cost_func2.inverse(xbest)
).
from pycma.
Perfect, now I can get the actual parameter values. Thank you so much.
from pycma.
Related Issues (20)
- Undesired CSA behavior with large population size HOT 3
- CPU bottleneck when benchmarking with large population size
- BoundTransform and BoundPenalty do not behave the same HOT 1
- Boundary transformations with 'ask and tell' interface. HOT 1
- CMA-ES in trajectories generation HOT 4
- How to manually set Covariance matrix HOT 1
- Motivation for boundary handler functions HOT 1
- Limit the memory resources while running fmin2 HOT 6
- if 1 < 3 HOT 1
- `feed_for_resume` does not always work as desired
- Option for cma.plot: plot variables as difference to initial solution HOT 1
- Feeding in solutions from a previous optimisation run HOT 1
- AttributeError: 'EvalParallel2' object has no attribute 'pool' HOT 2
- How to use cma effectively when the function values are not accurate? HOT 1
- fetch_bbob_fcts uses an outdated link HOT 1
- tolflatfitness with penalty bounds can be falsely triggered
- CMAAdaptSigmaMedianImprovement uses unpenalized f-values
- The initialization value for \tau
- What is the point of calculating 1^2 in recombination_weights.py? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycma.