Comments (7)
Yes, thank you a lot for your help.
I have tested it out, and it works as expected, albeit for many cases I work with it seems like starting with previous found best optimum point and diagonal covariance matrix gives just as good progress
from pycma.
The _copy_light
method seems to be what you are looking for.
import cma
cma.CMAEvolutionStrategy._copy_light??
Signature: cma.CMA._copy_light(self, sigma=None, inopts=None)
Source:
def _copy_light(self, sigma=None, inopts=None):
"""tentative copy of self, versatile (interface and functionalities may change).
`sigma` overwrites the original initial `sigma`.
`inopts` allows to overwrite any of the original options.
This copy may not work as expected depending on the used sampler.
Copy mean and sample distribution parameters and input options. Do
not copy evolution paths, termination status or other state variables.
>>> import cma
>>> es = cma.CMAEvolutionStrategy(3 * [1], 0.1,
... {'bounds':[0,9], 'verbose':-9}).optimize(cma.ff.elli, iterations=10)
>>> es2 = es._copy_light()
>>> assert es2.sigma == es.sigma
>>> assert sum((es.sm.C - es2.sm.C).flat < 1e-12)
>>> es3 = es._copy_light(sigma=3)
>>> assert es3.sigma == es3.sigma0 == 3
>>> es.mean[0] = -11
>>> es4 = es._copy_light(inopts={'CMA_on': False})
>>> assert es4.sp.c1 == es4.sp.cmu == 0
>>> assert es.mean[0] == -11 and es4.mean[0] >= -4.5
"""
if sigma is None:
sigma = self.sigma
opts = dict(self.inopts)
if inopts is not None:
opts.update(inopts)
es = type(self)(self.gp.pheno(self.mean[:], into_bounds=self.boundary_handler.repair),
sigma, opts)
es.sigma_vec = transformations.DiagonalDecoding(self.sigma_vec.scaling)
try: es.sm.C = self.sm.C.copy()
except: warnings.warn("self.sm.C.copy failed")
es.sm.update_now(-1) # make B and D consistent with C
es._updateBDfromSM()
return es
In case you use the functional interface: the second return argument of cma.fmin2
is the cma.CMAEvolutionStrategy
class instance to be used and the second argument to fmin2
can be the light-copied class instance.
from pycma.
You may also just directly use these few lines given es
is the previous class instance:
es2 = cma.CMAEvolutionStrategy(...)
es2.sigma_vec = cma.transformations.DiagonalDecoding(es.sigma_vec.scaling)
es2.sm.C = es.sm.C.copy()
es2.sm.update_now(-1) # make B and D consistent with C
es2._updateBDfromSM()
It seems like a good idea if this would work (it doesn't currently) by executing the above lines:
es2 = cma.CMAEvolutionStrategy(...)
es2._set_C_from(es)
from pycma.
Great thank you , I will check this out and give feedback.
from pycma.
Using this class would allow the two liner to work:
class CMAEvolutionStrategyWithSetCovarianceFrom(cma.CMAEvolutionStrategy):
def _set_C_from(self, es):
"""set the current covariance matrix from another class instance.
This may not work as expected unless the default sampler is used.
"""
if es.N != self.N:
warnings.warn("setting C with dimension {} != {} (the current "
"dimension). This is likely to fail."
.format(es.N, self.N))
self.sigma_vec = transformations.DiagonalDecoding(es.sigma_vec.scaling)
try:
self.sm.C = es.sm.C.copy()
except Exception:
warnings.warn("es.sm.C.copy() failed")
self.sm.update_now(-1) # make B and D consistent with C
self._updateBDfromSM()
from pycma.
Ok thanks!
from pycma.
Can this be closed?
from pycma.
Related Issues (20)
- 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
- What do the UserWarnings mean? HOT 8
- The initialization value for \tau
- What is the point of calculating 1^2 in recombination_weights.py? HOT 2
- Step size HOT 1
- Add Numpy 2.0 support HOT 5
- Default boundary handling on bbob discus
- `cma.plot()` not working for `matplotlib==3.9` update 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.