Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger stop condition manually #280

Open
Landau1908 opened this issue Nov 17, 2024 · 3 comments
Open

How to trigger stop condition manually #280

Landau1908 opened this issue Nov 17, 2024 · 3 comments

Comments

@Landau1908
Copy link

Hi,
I found that cma optimizer takes too long time searching over a global minimum (maybe local minimum but near to the global one). The outputs indicate that a plateau is reached, but optimizer does not stop searching. The chi2 is around 57 given by other optimizer like maximum entropy method. I don't understand exactly how the cma works. My question is how to trigger stop condition manually. Below is part of the outcomes.
Regards

Iterat #Fevals   function value  axis ratio  sigma  min&max std  t[m:s]
  451   4510 5.250307038558935e+01 2.7e+01 7.30e-03  3e-03  9e-03 2363:18.9
  452   4520 5.248187220433286e+01 2.7e+01 7.60e-03  3e-03  9e-03 2368:51.4
  453   4530 5.247689410610589e+01 2.6e+01 7.78e-03  3e-03  1e-02 2374:13.0
  454   4540 5.249070072197588e+01 2.7e+01 8.31e-03  3e-03  1e-02 2379:41.1
  455   4550 5.249481983418971e+01 2.7e+01 8.33e-03  3e-03  1e-02 2385:12.4
  456   4560 5.248196091354831e+01 2.7e+01 8.34e-03  3e-03  1e-02 2390:43.5
  457   4570 5.247796492375730e+01 2.7e+01 8.23e-03  3e-03  1e-02 2396:05.0
  458   4580 5.249527814727827e+01 2.7e+01 8.23e-03  3e-03  1e-02 2401:32.4
  459   4590 5.246573220631402e+01 2.8e+01 8.30e-03  3e-03  1e-02 2407:02.5
  460   4600 5.244583108345806e+01 2.7e+01 8.35e-03  3e-03  1e-02 2412:37.3
Iterat #Fevals   function value  axis ratio  sigma  min&max std  t[m:s]
  461   4610 5.252740575361025e+01 2.7e+01 8.42e-03  3e-03  1e-02 2417:59.6
  462   4620 5.246944163241823e+01 2.8e+01 8.14e-03  3e-03  1e-02 2423:27.2
  463   4630 5.243505510224431e+01 2.8e+01 7.95e-03  3e-03  1e-02 2429:00.9
  464   4640 5.241021222487646e+01 2.8e+01 7.75e-03  3e-03  9e-03 2434:33.2
  465   4650 5.236515762160713e+01 2.8e+01 7.75e-03  3e-03  9e-03 2439:55.7
  466   4660 5.239888955982028e+01 2.8e+01 7.53e-03  3e-03  9e-03 2445:30.8
  467   4670 5.236434898378491e+01 2.8e+01 7.35e-03  3e-03  9e-03 2451:04.3
  468   4680 5.234510445089583e+01 2.9e+01 7.32e-03  3e-03  9e-03 2456:40.8
  469   4690 5.233973846991087e+01 2.9e+01 7.21e-03  3e-03  9e-03 2462:04.4
  470   4700 5.231538822611188e+01 2.9e+01 7.38e-03  3e-03  9e-03 2467:44.1
Iterat #Fevals   function value  axis ratio  sigma  min&max std  t[m:s]
  471   4710 5.232257654952210e+01 2.9e+01 7.55e-03  3e-03  9e-03 2473:16.4
  472   4720 5.228969544158542e+01 3.0e+01 7.73e-03  3e-03  9e-03 2478:50.2
  473   4730 5.235733340009675e+01 3.0e+01 7.95e-03  3e-03  1e-02 2484:12.8
  474   4740 5.233866439154984e+01 3.1e+01 7.86e-03  3e-03  1e-02 2489:41.0
  475   4750 5.231314713729707e+01 3.2e+01 7.88e-03  3e-03  1e-02 2495:14.5
  476   4760 5.231222518363838e+01 3.2e+01 7.63e-03  3e-03  9e-03 2500:46.5
  477   4770 5.229244601924916e+01 3.3e+01 7.50e-03  3e-03  9e-03 2506:08.7
  478   4780 5.233412277853053e+01 3.3e+01 7.25e-03  3e-03  9e-03 2511:36.8
  479   4790 5.226909880600584e+01 3.3e+01 6.82e-03  3e-03  8e-03 2517:09.4
  480   4800 5.227606487225404e+01 3.3e+01 6.53e-03  2e-03  8e-03 2522:41.6
Iterat #Fevals   function value  axis ratio  sigma  min&max std  t[m:s]
  481   4810 5.230030729240242e+01 3.3e+01 6.30e-03  2e-03  8e-03 2528:03.3
  482   4820 5.228113207879544e+01 3.3e+01 6.21e-03  2e-03  8e-03 2533:32.3
  483   4830 5.230642534250156e+01 3.4e+01 6.41e-03  2e-03  8e-03 2539:04.8
  484   4840 5.228555083728177e+01 3.4e+01 6.20e-03  2e-03  8e-03 2544:38.9
  485   4850 5.227787996167135e+01 3.5e+01 5.89e-03  2e-03  7e-03 2550:01.2
  486   4860 5.228556434226294e+01 3.5e+01 5.53e-03  2e-03  7e-03 2555:31.3
  487   4870 5.225356635219954e+01 3.6e+01 5.39e-03  2e-03  7e-03 2561:12.6
  488   4880 5.225607350044170e+01 3.6e+01 5.49e-03  2e-03  7e-03 2566:48.0
  489   4890 5.223215217952239e+01 3.6e+01 5.53e-03  2e-03  7e-03 2572:13.8
  490   4900 5.222038603058613e+01 3.5e+01 5.67e-03  2e-03  7e-03 2577:54.2
Iterat #Fevals   function value  axis ratio  sigma  min&max std  t[m:s]
  491   4910 5.223632025211695e+01 3.6e+01 5.94e-03  2e-03  7e-03 2583:28.5
@nikohansen
Copy link
Contributor

nikohansen commented Nov 18, 2024

Outcomment the timeout line in the cma_signals.in file, which must be in the current folder where the algorithm was launched in.

@Landau1908
Copy link
Author

Except to specifing the timeout to hard stop, is it possible to set some object function value to stop? For example I want the object function value to be <=45, what should I do? Is there a criticism to set in options?

@nikohansen
Copy link
Contributor

nikohansen commented Nov 19, 2024

Except to specifing the timeout to hard stop, is it possible to set some object function value to stop? For example I want the object function value to be <=45, what should I do? Is there a criticism to set in options?

Same answer, you can use the 'ftarget' option instead of the 'timeout'. All "versatile" options (#v) can be dynamically changed in this way. When you know the target value in advance, you can also pass it as an option beforehand via the third or forth argument to CMAEvolutionStrategy or fmin2, respectively.

These versatile options can be displayed like

import cma

{key: val for key, val in cma.CMAOptions().items() if '#v' in val}

gives

{'CMA_active_injected': '0  #v weight multiplier for negative weights of injected solutions',
 'CMA_elitist': 'False  #v or "initial" or True, elitism likely impairs global search performance',
 'CMA_injections_threshold_keep_len': '1  #v keep length if Mahalanobis length is below the given relative threshold',
 'CSA_dampfac': '1  #v positive multiplier for step-size damping, 0.3 is close to optimal on the sphere',
 'CSA_disregard_length': 'False  #v True is untested, also changes respective parameters',
 'CSA_clip_length_value': 'None  #v poorly tested, [0, 0] means const length N**0.5, [-1, 1] allows a variation of +- N/(N+2), etc.',
 'CSA_squared': 'False  #v use squared length for sigma-adaptation ',
 'CSA_invariant_path': 'False  #v pc is invariant and ps (default) is unbiased',
 'stall_sigma_change_on_divergence_iterations': 'False  #v number of iterations of median worsenings threshold at which the sigma change is stalled; the default may become 2',
 'ftarget': '-inf  #v target function value, minimization',
 'is_feasible': 'is_feasible  #v a function that computes feasibility, by default lambda x, f: f not in (None, np.nan)',
 'maxfevals': 'inf  #v maximum number of function evaluations',
 'maxiter': '100 + 150 * (N+3)**2 [//](https://github.com/CMA-ES/pycma/issues/280) popsize**0.5  #v maximum number of iterations',
 'mean_shift_line_samples': 'False #v sample two new solutions colinear to previous mean shift',
 'mindx': '0  #v minimal std in any arbitrary direction, cave interference with tol*',
 'minstd': '0  #v minimal std (scalar or vector) in any coordinate direction, cave interference with tol*',
 'maxstd': 'None  #v maximal std (scalar or vector) in any coordinate direction',
 'pc_line_samples': 'False #v one line sample along the evolution path pc',
 'randn': 'np.random.randn  #v randn(lam, N) must return an np.array of shape (lam, N), see also cma.utilities.math.randhss',
 'termination_callback': '[]  #v a function or list of functions returning True for termination, called in `stop` with `self` as argument, could be abused for side effects',
 'timeout': 'inf  #v stop if timeout seconds are exceeded, the string "2.5 * 60**2" evaluates to 2 hours and 30 minutes',
 'tolconditioncov': '1e14  #v stop if the condition of the covariance matrix is above `tolconditioncov`',
 'tolfacupx': '1e3  #v termination when step-size increases by tolfacupx (diverges). That is, the initial step-size was chosen far too small and better solutions were found far away from the initial solution x0',
 'tolupsigma': '1e20  #v sigma/sigma0 > tolupsigma * max(eivenvals(C)**0.5) indicates "creeping behavior" with usually minor improvements',
 'tolflatfitness': '1  #v iterations tolerated with flat fitness before termination',
 'tolfun': '1e-11  #v termination criterion: tolerance in function value, quite useful',
 'tolfunhist': '1e-12  #v termination criterion: tolerance in function value history',
 'tolfunrel': '0  #v termination criterion: relative tolerance in function value: Delta f current < tolfunrel * (median0 - median_min)',
 'tolstagnation': 'int(100 + 100 * N**1.5 [/](https://file+.vscode-resource.vscode-cdn.net/) popsize)  #v termination if no improvement over tolstagnation iterations',
 'tolxstagnation': '[1e-9, 20, 0.1]  #v termination thresholds for Delta of [mean, iterations, iterations fraction], the latter two are summed; trigger termination if Dmean stays below the threshold over Diter iterations, pass `False` or a negative value to turn off tolxstagnation',
 'tolx': '1e-11  #v termination criterion: tolerance in x-changes',
 'updatecovwait': 'None  #v number of iterations without distribution update, name is subject to future changes',
 'verbose': '3  #v verbosity e.g. of initial/final message, -1 is very quiet, -9 maximally quiet, may not be fully implemented',
 'verb_disp': '100  #v verbosity: display console output every verb_disp iteration',
 'verb_disp_overwrite': 'inf  #v start overwriting after given iteration',
 'verb_log': '1  #v verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions',
 'verb_plot': '0  #v in fmin2(): plot() is called every verb_plot iteration',
 'verb_time': 'True  #v output timings on console'}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants