(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)