commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Neidhart <thomas.neidh...@gmail.com>
Subject [math] Problem with parsing of OptimizationData arguments in optim package
Date Sat, 16 Nov 2013 17:17:15 GMT
Hi,

while working on MATH-970, I realized that the current way of handling
all the OptimizationData arguments for the optimize and
parseOptimizationData methods is somehow flawed.

All the OptimizationData is parsed and stored in the instance itself,
but not reset between subsequent calls of optimize.

This behavior is described in BaseOptimizer#optimize:

When the method is called multiple times, instance data is overwritten
only when actually present in the list of arguments: when not specified,
data set in a previous call is retained (and thus is optional in
subsequent calls).

This can lead to subtle errors/mistakes that are difficult to track
down, especially when optional flags have a default value, like for the
SimplexSolver:

SimplexSolver solver = new SimplexSolver();

solution = solver.optimize(DEFAULT_MAX_ITER, f, new
           LinearConstraintSet(constraints),
           GoalType.MINIMIZE,
           new NonNegativeConstraint(true));

solution = solver.optimize(DEFAULT_MAX_ITER, f, new
           LinearConstraintSet(constraints),
           GoalType.MINIMIZE);

The default value for nonNegative = false, thus one could think that the
second call would enforce no nonNegative solution, but in fact will
return the same result as the first call.

This can be easily solved by making sure that the parseOptimizationData
is resetting any optional arguments, but I wanted to get some feedback
first and whether this behavior is really desired.

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message