Tcl Library Source Code

View Ticket
Login
Ticket UUID: 3193459
Title: divide by zero
Type: Bug Version: None
Submitter: jdbr Created on: 2011-02-26 18:35:01
Subsystem: math :: optimize Assigned To: arjenmarkus
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2014-09-21 12:59:31
Resolution: Fixed Closed By:
    Closed on:
Description:
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.
User Comments: arjenmarkus added on 2014-09-21 12:59:31:
Fixed by applying the suggested code change

aku added on 2014-07-21 20:05:52:
Any progress?