Menu

#1251 divide by zero

open
5
2011-02-26
2011-02-26
No

nelderMead can attempt to divide by zero. For example (Tcl8.5 tcllib-1.13) math::optimize::nelderMead {apply {{x y} {expr {abs($x-$y)}}}} {1 1}
gives a domain error. The problem is not well formed, as the minimum is a line (x=y), but this could occur in other cases as well.
One solution would be to add param(-ftol) to the denominator where rerror is calculated:
set rerror [expr { 2. * abs( $yTop - $yBot )
/ ( abs( $yTop ) + abs( $yBot ) + $params(-ftol)) }]
This will change the error from relative to absolute with tolerance -ftol^2 for function values much less than -ftol
It will change the relative error tolerance from -ftol to about 0.667*-ftol when the function value is near -ftol
There is little effect when the function value is much larger than -ftol.

-ftol must be larger than 0.
it is already required (in $rerror < $params(-ftol) on the line following rerror calculation)
It might be worth verifying that while checking arguments.

Discussion