Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

cmaes

CMA-ES (Evolution Strategy with Covariance Matrix Adaptation) optimization library.

  1. Outdated egg!
  2. cmaes
  3. Usage
  4. Documentation
    1. High-level procedures
    2. Initialization procedures
    3. Core procedures
    4. Support procedures
  5. Examples
    1. High-level procedures
    2. Core procedures
  6. About this egg
    1. Author
    2. Version history
    3. License

Usage

(require-extension cmaes)

Documentation

The CMA-ES CMA-ES (Covariance Matrix Adaptation Evolution Strategy) is an evolutionary algorithm for difficult non-linear non-convex optimization problems in a continuous domain.

The Chicken cmaes library provides a Scheme interface to the core procedures of CMA-ES.

High-level procedures

[procedure] init:: PARAMETERS -> [H FUNVALS]

Creates a new optimization problem based on the given parameters. PARAMETERS is an alist of parameter values, as defined in the CMA-ES documentation.

[procedure] run:: FN * H * FUNVALS * SIGNALS [output-file: "all.dat"] [result-values: '(xbest xmean)] -> RESULT

Executes the optimizer and returns the solution. FN is the objective function: it must take an SRFI-4 f64vector of state value and return the objective value corresponding to this state fector. H is the problem handle returned by init. FUNVALS is the initial state vector (must be SRFI-4 f64vector). SIGNALS is an alist of runtime signals to be evaluated.

Initialization procedures

[procedure] init-from-file:: FILEPATH -> [H FUNVALS]
[procedure] read-signals:: H * [PARAMETER1 ...] -> VOID
[procedure] read-signals-from-file:: H * FILEPATH -> VOID

Core procedures

[procedure] sample-population:: H -> VECTOR

Computes a population of lambda N-dimensional multivariate normally distributed samples.

[procedure] update-distribution:: H -> F64VECTOR

Sets a new mean value and estimates the new covariance matrix and a new step size for the normal search distribution. Returns the new mean value.

Support procedures

Examples

High-level procedures


 (use srfi-4 cmaes)
 
 (define (minimize f N)
   (let-values (((h funvals) (init `((N .  ,N) ;; Problem dimension
 
 				    (initialX 0.5e0)  ;; Initial search point
 				    
 				    (typicalX 0.0) ;; Typical search point (useful for restarts)
 				    
 				    (initialStandardDeviations  0.3)
 				    ;; numbers should not differ by orders of magnitude
 				    ;; should be roughly 1/4 of the search interval
 				    ;; this number essentially influences the global 
 				    ;; search ability (ie. the horizon where to search
 				    ;; at all) on multimodal functions
 				    
 				    (stopMaxFunEvals   . 1e299) ;; max number of f-evaluations, 900*(N+3)*(N+3) is default
 				    (stopMaxIter       . 1e299) ;; max number of iterations (generations), inf is default
 				    
 				    (stopTolFun . 1e-12) ;; stop if function value differences are 
 				    ;; smaller than stopTolFun, default=1e-12
 				    
 				    (stopTolFunHist . 1e-13) ;; stop if function value differences of best values are 
 				    ;; smaller than stopTolFunHist, default was 0
 				    
 				    (stopTolX . 1e-11) ;; stop if step sizes/steps in x-space are 
 				    ;; smaller than TolX, default=0
 				    
 				    (stopTolUpXFactor . 1e3) ;; stop if std dev increases more than by TolUpXFactor, default 1e3
 				    
 				    (seed . 0) 
 				    ))))
     
     (pp 
     (run f h funvals 
 	  `((print  fewinfo    200) ;; print every 200 seconds
 	    (print  few+clock  2  ) ;; clock: used processor time since start
 	    (write "iter+eval+sigma+0+0+xmean"                           outcmaesxmean.dat )
  	    (write "iter+eval+sigma+0+fitness+xbest"                     outcmaesxrecentbest.dat )
 	    )))
     ))
 
 
 ;; an objective (fitness) function to be minimized 
 (define (f1 x)
   (let ((N (f64vector-length x)))
     (let recur ((i 2) (sum (+ (* 1e4 (f64vector-ref x 0) (f64vector-ref x 0)) 
 			      (* 1e4 (f64vector-ref x 1) (f64vector-ref x 1)) )))
       (if (< i N)
 	  (recur (+ 1 i) (+ sum (* (f64vector-ref x i) (f64vector-ref x i))))
 	  sum))
     ))
 
 (minimize f1 22)

Core procedures

 (use srfi-4 cmaes)
 
 
 ;; the objective (fitness) function to be minimized 
 (define (fitfun x N)
   (let recur ((i 2) (sum (+ (* 1e4 (f64vector-ref x 0) (f64vector-ref x 0)) 
 			    (* 1e4 (f64vector-ref x 1) (f64vector-ref x 1)) )))
     (if (< i N)
 	(recur (+ 1 i) (+ sum (* (f64vector-ref x i) (f64vector-ref x i))))
  	sum))
   )
 
 
 (let-values (((h funvals) (init-from-file "initials.par")))
   
   (read-signals-from-file h "signals.par") 
 
   (let recur ((h h))
 
     (let ((stop (terminated? h)))
 
       (if (not stop)
 
 	  (let ((pop (sample-population h))
 		(lam (get-parameter h 'lambda))
 		(n (get-parameter h 'dim)))
 	    
 	    (let inner-recur ((i 0))
 	      (if (< i lam)
 		  (begin
 		    (f64vector-set! funvals i (fitfun (vector-ref pop i) n))
 		    (inner-recur (+ 1 i)))))
 	    
 	    (update-distribution h funvals)
 	    
 	    (read-signals-from-file h "signals.par")
 	    
 	    (recur h)
 	    
 	    )
 	  
 	  (print stop)
 	  )))
 
  (write-to-file h 'all "allcmaes.dat")
  
   (let ((xfinal (get-new h "xmean")))
 
     (printf "xmean = ~A~%" xfinal)
 
     (terminate h)
 
     (free h)
     ))

About this egg

Author

The CMA-ES C library was written by Nikolaus Hansen. The Chicken Scheme cmaes library was written by Ivan Raikov.

Version history

1.0
Initial release

License

CMA-ES C library is copyright 1996, 2003, 2007 Nikolaus Hansen.
Chicken Scheme bindings for CMA-ES are copyright 2012 Ivan Raikov.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

A full copy of the GPL license can be found at
<http://www.gnu.org/licenses/>.