Commit 13447017 authored by Liam Healy's avatar Liam Healy

Added tests of minimization-one setting with values

Two new tests of minimization-one setting values have been added,
duplicating the test which do not set values.  Patch by Evgeniy
Zhemchugov.
SBCL 64:
TOTAL: 1525 assertions passed, 5 failed, 0 execution errors.
parent 4df83bca
......@@ -184,33 +184,43 @@
;;; than given there.
(defun minimization-one-example
(&optional (minimizer-type +brent-fminimizer+) (print-steps t))
(&optional (minimizer-type +brent-fminimizer+)
(print-steps t)
(with-values t))
"Solving a minimum, the example given in Sec. 33.8 of the GSL manual."
(let ((max-iter 100)
(minimizer
(make-one-dimensional-minimizer
minimizer-type (lambda (x) (1+ (cos x))) 2.0d0 0.0d0 6.0d0)))
(when print-steps
(format
t
"iter ~6t [lower ~24tupper] ~36tmin ~44tmin err ~54tupper-lower~&"))
(loop for iter from 0
for min = (solution minimizer)
for lower = (fminimizer-x-lower minimizer)
for upper = (fminimizer-x-upper minimizer)
do (iterate minimizer)
(when print-steps
(format t "~d~6t~10,6f~18t~10,6f~28t~12,9f ~44t~10,4g ~10,4g~&"
iter lower upper
min (- min pi)
(- upper lower)))
while (and (< iter max-iter)
;; abs and rel error swapped in example?
(not (min-test-interval lower upper 0.001d0 0.0d0)))
finally
(return (values iter lower upper min (- min pi) (- upper lower))))))
(flet ((f (x) (1+ (cos x))))
(let ((max-iter 100)
(minimizer
(if with-values
(make-one-dimensional-minimizer
minimizer-type #'f
2.0d0 0.0d0 6.0d0
(f 2.0d0) (f 0.0d0) (f 6.0d0))
(make-one-dimensional-minimizer
minimizer-type #'f 2.0d0 0.0d0 6.0d0))))
(when print-steps
(format
t
"iter ~6t [lower ~24tupper] ~36tmin ~44tmin err ~54tupper-lower~&"))
(loop for iter from 0
for min = (solution minimizer)
for lower = (fminimizer-x-lower minimizer)
for upper = (fminimizer-x-upper minimizer)
do (iterate minimizer)
(when print-steps
(format t "~d~6t~10,6f~18t~10,6f~28t~12,9f ~44t~10,4g ~10,4g~&"
iter lower upper
min (- min pi)
(- upper lower)))
while (and (< iter max-iter)
;; abs and rel error swapped in example?
(not (min-test-interval lower upper 0.001d0 0.0d0)))
finally
(return (values iter lower upper min (- min pi) (- upper lower)))))))
(save-test minimization-one
(minimization-one-example +brent-fminimizer+ nil)
(minimization-one-example +golden-section-fminimizer+ nil))
(minimization-one-example +brent-fminimizer+ nil nil)
(minimization-one-example +golden-section-fminimizer+ nil nil)
(minimization-one-example +brent-fminimizer+ nil t)
(minimization-one-example +golden-section-fminimizer+ nil t))
......@@ -3,14 +3,31 @@
(in-package :gsl)
(LISP-UNIT:DEFINE-TEST MINIMIZATION-ONE
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(LISP-UNIT:ASSERT-NUMERICAL-EQUAL
(LIST 6 3.141474321994987d0 3.1415930343642042d0
3.141592654724622d0 1.134828675475319d-9
1.1871236921701112d-4)
(MULTIPLE-VALUE-LIST (MINIMIZATION-ONE-EXAMPLE +BRENT-FMINIMIZER+ NIL)))
(LISP-UNIT::ASSERT-NUMERICAL-EQUAL
(MULTIPLE-VALUE-LIST
(MINIMIZATION-ONE-EXAMPLE +BRENT-FMINIMIZER+ NIL
NIL)))
(LISP-UNIT:ASSERT-NUMERICAL-EQUAL
(LIST 24 3.1413247152275243d0 3.1419619412229034d0
3.1415652995716155d0 -2.7354018177661032d-5
6.37225995379076d-4)
(MULTIPLE-VALUE-LIST
(MINIMIZATION-ONE-EXAMPLE +GOLDEN-SECTION-FMINIMIZER+
NIL NIL)))
(LISP-UNIT:ASSERT-NUMERICAL-EQUAL
(LIST 6 3.141474321994987d0 3.1415930343642042d0
3.141592654724622d0 1.134828675475319d-9
1.1871236921701112d-4)
(MULTIPLE-VALUE-LIST
(MINIMIZATION-ONE-EXAMPLE +BRENT-FMINIMIZER+ NIL T)))
(LISP-UNIT:ASSERT-NUMERICAL-EQUAL
(LIST 24 3.1413247152275243d0 3.1419619412229034d0
3.1415652995716155d0 -2.7354018177661032d-5
6.37225995379076d-4)
(MULTIPLE-VALUE-LIST
(MINIMIZATION-ONE-EXAMPLE +GOLDEN-SECTION-FMINIMIZER+ NIL))))
(MINIMIZATION-ONE-EXAMPLE +GOLDEN-SECTION-FMINIMIZER+
NIL T))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment