You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Gilles <gi...@harfang.homelinux.org> on 2013/07/22 01:31:27 UTC

[Math] Re: Pass ConvergenceChecker to BOBYQAOptimizer

Hi.

[Do not forget to indicate "[Math]" in the subject line of a post
to this ML, as it is shared by many projects.]

On Sun, 21 Jul 2013 17:06:01 -0400, enzhong.fu@pnc.com wrote:
> I want to stop TooManyEvaluationException by passing a 
> ConvergenceChecker
> to BOBYQAOptimizer. In the ConvergenceChecker I will check iteration 
> and
> return true if it is reached. But BOBYQAOptimizer does not accept
> ConvergenceChecker in constructor even though its parent class does. 
> How
> do I pass ConvergenceChecker to BOBYQAOptimizer?

As it's been advertized in all release notes since version 3.0, the
code in "BOBYQAOptimizer" is alpha. The code seems to work as the
FORTRAN original but is otherwise extremely difficult to modify
without ill consequences. In particular, it's not reached as state
where a custom convergence checker could have been easily added.
For more info, see issue
   https://issues.apache.org/jira/browse/MATH-621

Sorry,
Gilles


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [Math] Re: Pass ConvergenceChecker to BOBYQAOptimizer

Posted by Gilles <gi...@harfang.homelinux.org>.
On Wed, 28 Aug 2013 04:53:26 -0700 (PDT), Thomas wrote:
> Hi!
>
> I have tried to use the CMAESOptimizer but unfortunately the program 
> (given
> below) is aborted with the following exception:
>
> Exception in thread "main" java.lang.NullPointerException
> 	at
> 
> org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.checkParameters(CMAESOptimizer.java:554)
> 	at
> 
> org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.parseOptimizationData(CMAESOptimizer.java:542)
> 	at
> 
> org.apache.commons.math3.optim.BaseOptimizer.optimize(BaseOptimizer.java:137)
> 	at
> 
> org.apache.commons.math3.optim.BaseMultivariateOptimizer.optimize(BaseMultivariateOptimizer.java:66)
> 	at
> 
> org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer.optimize(MultivariateOptimizer.java:64)
> 	at
> 
> org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.optimize(CMAESOptimizer.java:363)
> 	at CMA_ES.main(CMA_ES.java:122)
>
>
>
> The optimizer I used as follows:
>
>
> public static void main(String[] args){
>
>   MultivariateFunction f = new MultivariateFunction() {
>   @Override
>   public double value(double[] arg0) {
>     double res = 0;
>       for(int i = 0; i < arg0.length; i++){
>         res = res + Math.pow(arg0[i], 2);
>       }
>       return res;
>     }
>   };
>
>   int dim = 50;
>
>   JDKRandomGenerator rand = new JDKRandomGenerator();
>   rand.setSeed(1503);
>
>   double[] sigma = new double[dim];
>   for(int i = 0; i < dim; i++){
>     sigma[i] = 5;
>   }
>
>
>   SimpleValueChecker checker = new SimpleValueChecker(1E-3, 1E-6);
>   CMAESOptimizer opt = new CMAESOptimizer(Integer.MAX_VALUE,
> Double.NEGATIVE_INFINITY, true, 1, 1, rand, false, checker);
>   PointValuePair p = opt.optimize(new ObjectiveFunction(f),
> GoalType.MINIMIZE, new CMAESOptimizer.Sigma(sigma), new
> CMAESOptimizer.PopulationSize(25));
>
>
> According to the API I have to specify the objective function and the 
> goal
> of optimization. Moreover, if using the CMAES I have also to specify 
> Sigma
> and PopulationSize. Obviously, I specified these parameters in my 
> code,
> hence I wonder a bit why the exception is thrown. Does anyone has
> suggestions? Thanks a lot.

The error is a missing "starting point".
See apidocs of the parent class(es).

HTH,
Gilles


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [Math] Re: Pass ConvergenceChecker to BOBYQAOptimizer

Posted by Thomas <th...@mathematik.uni-marburg.de>.
Hi!

I have tried to use the CMAESOptimizer but unfortunately the program (given
below) is aborted with the following exception:

Exception in thread "main" java.lang.NullPointerException
	at
org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.checkParameters(CMAESOptimizer.java:554)
	at
org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.parseOptimizationData(CMAESOptimizer.java:542)
	at
org.apache.commons.math3.optim.BaseOptimizer.optimize(BaseOptimizer.java:137)
	at
org.apache.commons.math3.optim.BaseMultivariateOptimizer.optimize(BaseMultivariateOptimizer.java:66)
	at
org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer.optimize(MultivariateOptimizer.java:64)
	at
org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.optimize(CMAESOptimizer.java:363)
	at CMA_ES.main(CMA_ES.java:122)



The optimizer I used as follows:


public static void main(String[] args){

  MultivariateFunction f = new MultivariateFunction() {
  @Override
  public double value(double[] arg0) {
    double res = 0;
      for(int i = 0; i < arg0.length; i++){
        res = res + Math.pow(arg0[i], 2);
      }
      return res;
    }
  };
		
  int dim = 50;
		
  JDKRandomGenerator rand = new JDKRandomGenerator();
  rand.setSeed(1503);
		
  double[] sigma = new double[dim]; 
  for(int i = 0; i < dim; i++){
    sigma[i] = 5;
  }
		

  SimpleValueChecker checker = new SimpleValueChecker(1E-3, 1E-6);
  CMAESOptimizer opt = new CMAESOptimizer(Integer.MAX_VALUE,
Double.NEGATIVE_INFINITY, true, 1, 1, rand, false, checker);
  PointValuePair p = opt.optimize(new ObjectiveFunction(f),
GoalType.MINIMIZE, new CMAESOptimizer.Sigma(sigma), new
CMAESOptimizer.PopulationSize(25));


According to the API I have to specify the objective function and the goal
of optimization. Moreover, if using the CMAES I have also to specify Sigma
and PopulationSize. Obviously, I specified these parameters in my code,
hence I wonder a bit why the exception is thrown. Does anyone has
suggestions? Thanks a lot.



--
View this message in context: http://apache-commons.680414.n4.nabble.com/math-Struggling-with-opimization-tp4650246p4653405.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org