GithubHelp home page GithubHelp logo

What do the UserWarnings mean? about pycma HOT 8 CLOSED

de-ranit avatar de-ranit commented on September 27, 2024
What do the UserWarnings mean?

from pycma.

Comments (8)

de-ranit avatar de-ranit commented on September 27, 2024 1

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.

nikohansen avatar nikohansen commented on September 27, 2024 1

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.

nikohansen avatar nikohansen commented on September 27, 2024 1

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.

nikohansen avatar nikohansen commented on September 27, 2024

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.

de-ranit avatar de-ranit commented on September 27, 2024

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.

nikohansen avatar nikohansen commented on September 27, 2024

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.

de-ranit avatar de-ranit commented on September 27, 2024

Thank you so much for the clarifications.

The ScaleCoordinates class has an inverse method which should give the desired solution when applied to xbest or xfavorite 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.

de-ranit avatar de-ranit commented on September 27, 2024

Perfect, now I can get the actual parameter values. Thank you so much.

from pycma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.