((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/cmaes" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "cmaes" (p "CMA-ES (Evolution Strategy with Covariance Matrix Adaptation) optimization library.") (toc)) (section 2 "Usage" (p "(require-extension cmaes)")) (section 2 "Documentation" (p "The " (link "http://www.lri.fr/~hansen/cmaesintro.html/" "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.") (p "The Chicken " (tt "cmaes") " library provides a Scheme interface to the core procedures of CMA-ES.") (section 3 "High-level procedures" (def (sig (procedure "init:: PARAMETERS -> [H FUNVALS]" (id init))) (p "Creates a new optimization problem based on the given parameters. " (tt "PARAMETERS") " is an alist of parameter values, as defined in the CMA-ES documentation.")) (def (sig (procedure "run:: FN * H * FUNVALS * SIGNALS [output-file: \"all.dat\"] [result-values: '(xbest xmean)] -> RESULT  " (id run))) (p "Executes the optimizer and returns the solution. " (tt "FN") " is the objective function: it must take an SRFI-4 " (tt "f64vector") " of state value and return the objective value corresponding to this state fector. " (tt "H") " is the problem handle returned by " (tt "init") ". " (tt "FUNVALS") " is the initial state vector (must be SRFI-4 " (tt "f64vector") "). " (tt "SIGNALS") " is an alist of runtime signals to be evaluated."))) (section 3 "Initialization  procedures" (def (sig (procedure "init-from-file:: FILEPATH -> [H FUNVALS]" (id init-from-file)))) (def (sig (procedure "read-signals:: H * [PARAMETER1 ...] -> VOID" (id read-signals)))) (def (sig (procedure "read-signals-from-file:: H * FILEPATH -> VOID" (id read-signals-from-file))))) (section 3 "Core  procedures" (def (sig (procedure "sample-population:: H -> VECTOR" (id sample-population))) (p "Computes a population of lambda N-dimensional multivariate normally distributed samples.")) (def (sig (procedure "update-distribution:: H -> F64VECTOR" (id update-distribution))) (p "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."))) (section 3 "Support procedures")) (section 2 "Examples" (section 3 "High-level procedures" (highlight scheme "\n (use srfi-4 cmaes)\n \n (define (minimize f N)\n   (let-values (((h funvals) (init `((N .  ,N) ;; Problem dimension\n \n \t\t\t\t    (initialX 0.5e0)  ;; Initial search point\n \t\t\t\t    \n \t\t\t\t    (typicalX 0.0) ;; Typical search point (useful for restarts)\n \t\t\t\t    \n \t\t\t\t    (initialStandardDeviations  0.3)\n \t\t\t\t    ;; numbers should not differ by orders of magnitude\n \t\t\t\t    ;; should be roughly 1/4 of the search interval\n \t\t\t\t    ;; this number essentially influences the global \n \t\t\t\t    ;; search ability (ie. the horizon where to search\n \t\t\t\t    ;; at all) on multimodal functions\n \t\t\t\t    \n \t\t\t\t    (stopMaxFunEvals   . 1e299) ;; max number of f-evaluations, 900*(N+3)*(N+3) is default\n \t\t\t\t    (stopMaxIter       . 1e299) ;; max number of iterations (generations), inf is default\n \t\t\t\t    \n \t\t\t\t    (stopTolFun . 1e-12) ;; stop if function value differences are \n \t\t\t\t    ;; smaller than stopTolFun, default=1e-12\n \t\t\t\t    \n \t\t\t\t    (stopTolFunHist . 1e-13) ;; stop if function value differences of best values are \n \t\t\t\t    ;; smaller than stopTolFunHist, default was 0\n \t\t\t\t    \n \t\t\t\t    (stopTolX . 1e-11) ;; stop if step sizes/steps in x-space are \n \t\t\t\t    ;; smaller than TolX, default=0\n \t\t\t\t    \n \t\t\t\t    (stopTolUpXFactor . 1e3) ;; stop if std dev increases more than by TolUpXFactor, default 1e3\n \t\t\t\t    \n \t\t\t\t    (seed . 0) \n \t\t\t\t    ))))\n     \n     (pp \n     (run f h funvals \n \t  `((print  fewinfo    200) ;; print every 200 seconds\n \t    (print  few+clock  2  ) ;; clock: used processor time since start\n \t    (write \"iter+eval+sigma+0+0+xmean\"                           outcmaesxmean.dat )\n  \t    (write \"iter+eval+sigma+0+fitness+xbest\"                     outcmaesxrecentbest.dat )\n \t    )))\n     ))\n \n \n ;; an objective (fitness) function to be minimized \n (define (f1 x)\n   (let ((N (f64vector-length x)))\n     (let recur ((i 2) (sum (+ (* 1e4 (f64vector-ref x 0) (f64vector-ref x 0)) \n \t\t\t      (* 1e4 (f64vector-ref x 1) (f64vector-ref x 1)) )))\n       (if (< i N)\n \t  (recur (+ 1 i) (+ sum (* (f64vector-ref x i) (f64vector-ref x i))))\n \t  sum))\n     ))\n \n (minimize f1 22)")) (section 3 "Core procedures" (highlight scheme " (use srfi-4 cmaes)\n \n \n ;; the objective (fitness) function to be minimized \n (define (fitfun x N)\n   (let recur ((i 2) (sum (+ (* 1e4 (f64vector-ref x 0) (f64vector-ref x 0)) \n \t\t\t    (* 1e4 (f64vector-ref x 1) (f64vector-ref x 1)) )))\n     (if (< i N)\n \t(recur (+ 1 i) (+ sum (* (f64vector-ref x i) (f64vector-ref x i))))\n  \tsum))\n   )\n \n \n (let-values (((h funvals) (init-from-file \"initials.par\")))\n   \n   (read-signals-from-file h \"signals.par\") \n \n   (let recur ((h h))\n \n     (let ((stop (terminated? h)))\n \n       (if (not stop)\n \n \t  (let ((pop (sample-population h))\n \t\t(lam (get-parameter h 'lambda))\n \t\t(n (get-parameter h 'dim)))\n \t    \n \t    (let inner-recur ((i 0))\n \t      (if (< i lam)\n \t\t  (begin\n \t\t    (f64vector-set! funvals i (fitfun (vector-ref pop i) n))\n \t\t    (inner-recur (+ 1 i)))))\n \t    \n \t    (update-distribution h funvals)\n \t    \n \t    (read-signals-from-file h \"signals.par\")\n \t    \n \t    (recur h)\n \t    \n \t    )\n \t  \n \t  (print stop)\n \t  )))\n \n  (write-to-file h 'all \"allcmaes.dat\")\n  \n   (let ((xfinal (get-new h \"xmean\")))\n \n     (printf \"xmean = ~A~%\" xfinal)\n \n     (terminate h)\n \n     (free h)\n     ))") (pre ""))) (section 2 "About this egg" (section 3 "Author" (p "The CMA-ES C library was written by Nikolaus Hansen.  The Chicken Scheme " (tt "cmaes") " library was written by " (int-link "/users/ivan-raikov" "Ivan Raikov") ".")) (section 3 "Version history" (dl (dt "1.0") (dd "Initial release"))) (section 3 "License" (pre "CMA-ES C library is copyright 1996, 2003, 2007 Nikolaus Hansen.\nChicken Scheme bindings for CMA-ES are copyright 2012 Ivan Raikov.\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License version 2 as published by\nthe Free Software Foundation.\n\nThis program is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\nGeneral Public License for more details.\n\nA full copy of the GPL license can be found at\n<http://www.gnu.org/licenses/>."))))