You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Thomas Neidhart <th...@gmail.com> on 2013/01/17 14:28:56 UTC
[math] OptimizationData and LinearConstraintSet
Hi,
by investigating a recent issue (MATH-930), I discovered that the newly
introduced LinearConstraintSet stores the constraints internally in a
HashSet.
This leads to undeterministic behavior as the iteration order of
constraints is not fixed (especially between different JRE versions).
TBH, I never reviewed this change and I am a bit surprised to see it. Imho
there is no need to have a Set here, and would prefer to change this to a
list implementation.
Thomas
Re: [math] OptimizationData and LinearConstraintSet
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Thu, Jan 17, 2013 at 09:04:55PM +0100, Thomas Neidhart wrote:
> On 01/17/2013 08:24 PM, Gilles Sadowski wrote:
> >>> [...]
> >>>
> >>> If we do not have the resources to dig further into the real problem, we can
> >>> circumscribe it by indicating which interval of epsilon values are
> >>> considered trustworthy (and declining all resposibility if user try pushing
> >>> the implementation too far).
> >>
> >> Well, I do disagree.
> >> I do not want to have a situation where users get different results with
> >> each run. I want to have deterministic behavior for deterministic
> >> algorithms.
> >
> > Do you suggest that the JVM algorithm is not deterministic? ;-)
>
> The iteration order of HashSet entries is based on the hash code of the
> entries and the number of buckets in the underlying HashMap. As the hash
> code of a LinearConstraint is derived from its values (including an enum
> - Relationship) it may change, and in fact does (the enum has no
> overridden hashCode method, and Java 6+ does not seem to guarantee the
> same hashCode for the same enum every time contrary to what Java 5 seems
> to do).
>
> So every time you run, your iteration order could be different (and you
> can see it with the test case).
It's fair to add "hashCode" and "equals" methods to class "Relationship",
and if the side-effect disappear as a consequence then good for you!
I'm just saying that it will not solve the real problem (not anymore than
replacing "Set" with "List" would).
>
> >> Yes, there are numerical stability issues, which in this case can be
> >> treated by relaxing the convergence criteria as the user did.
> >
> > Then, I propose that lower bound of the convergence criterion be set as a
> > precondition and the algorithm will be deterministic in a more obvious way.
> >
> >> Otoh, we should have thorough testing where a permutation of the linear
> >> constraints could be a useful addition to detect more such issues. For
> >> such a flexible tool like the SimplexSolver, there will always be
> >> problems where the solution is difficult to find, and will require some
> >> tuning. Even octave (using the very good and mature glpk library) did
> >> not find the optimal solution in this case.
> >
> > This even further convinces me that we should not change an implementation
> > detail: such details simply must not have visible side-effects.
> > It has a visible effect here because the precondition is not satisfied.
>
> I do not fully understand, about which precondition do we talk here?
The real protection would be to forbid epsilon values that lead to
instability. Maybe that the lower bound depends on the problem (?).
If so, then maybe that the algorithm can, at some point, perform an
auto-diagnostic and detect that the solution, even if found, may be
fragile. If none of this is possible then just mentions in the Javadoc that
the stability critically depend on the choice of epsilon (up to raising an
exception if set to low, since that will happen if people set the
constraints on the "wrong" order, even with the above fix).
Regards,
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] OptimizationData and LinearConstraintSet
Posted by Thomas Neidhart <th...@gmail.com>.
On 01/17/2013 08:24 PM, Gilles Sadowski wrote:
>>> [...]
>>>
>>> If we do not have the resources to dig further into the real problem, we can
>>> circumscribe it by indicating which interval of epsilon values are
>>> considered trustworthy (and declining all resposibility if user try pushing
>>> the implementation too far).
>>
>> Well, I do disagree.
>> I do not want to have a situation where users get different results with
>> each run. I want to have deterministic behavior for deterministic
>> algorithms.
>
> Do you suggest that the JVM algorithm is not deterministic? ;-)
The iteration order of HashSet entries is based on the hash code of the
entries and the number of buckets in the underlying HashMap. As the hash
code of a LinearConstraint is derived from its values (including an enum
- Relationship) it may change, and in fact does (the enum has no
overridden hashCode method, and Java 6+ does not seem to guarantee the
same hashCode for the same enum every time contrary to what Java 5 seems
to do).
So every time you run, your iteration order could be different (and you
can see it with the test case).
>> Yes, there are numerical stability issues, which in this case can be
>> treated by relaxing the convergence criteria as the user did.
>
> Then, I propose that lower bound of the convergence criterion be set as a
> precondition and the algorithm will be deterministic in a more obvious way.
>
>> Otoh, we should have thorough testing where a permutation of the linear
>> constraints could be a useful addition to detect more such issues. For
>> such a flexible tool like the SimplexSolver, there will always be
>> problems where the solution is difficult to find, and will require some
>> tuning. Even octave (using the very good and mature glpk library) did
>> not find the optimal solution in this case.
>
> This even further convinces me that we should not change an implementation
> detail: such details simply must not have visible side-effects.
> It has a visible effect here because the precondition is not satisfied.
I do not fully understand, about which precondition do we talk here?
Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] OptimizationData and LinearConstraintSet
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
> > [...]
> >
> > If we do not have the resources to dig further into the real problem, we can
> > circumscribe it by indicating which interval of epsilon values are
> > considered trustworthy (and declining all resposibility if user try pushing
> > the implementation too far).
>
> Well, I do disagree.
> I do not want to have a situation where users get different results with
> each run. I want to have deterministic behavior for deterministic
> algorithms.
Do you suggest that the JVM algorithm is not deterministic? ;-)
> Yes, there are numerical stability issues, which in this case can be
> treated by relaxing the convergence criteria as the user did.
Then, I propose that lower bound of the convergence criterion be set as a
precondition and the algorithm will be deterministic in a more obvious way.
> Otoh, we should have thorough testing where a permutation of the linear
> constraints could be a useful addition to detect more such issues. For
> such a flexible tool like the SimplexSolver, there will always be
> problems where the solution is difficult to find, and will require some
> tuning. Even octave (using the very good and mature glpk library) did
> not find the optimal solution in this case.
This even further convinces me that we should not change an implementation
detail: such details simply must not have visible side-effects.
It has a visible effect here because the precondition is not satisfied.
Regards,
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] OptimizationData and LinearConstraintSet
Posted by Thomas Neidhart <th...@gmail.com>.
On 01/17/2013 04:21 PM, Gilles Sadowski wrote:
> Hi Thomas.
>
> On Thu, Jan 17, 2013 at 03:59:20PM +0100, Thomas Neidhart wrote:
>> On Thu, Jan 17, 2013 at 3:52 PM, Gilles Sadowski <
>> gilles@harfang.homelinux.org> wrote:
>>
>>> On Thu, Jan 17, 2013 at 02:28:56PM +0100, Thomas Neidhart wrote:
>>>> Hi,
>>>>
>>>> by investigating a recent issue (MATH-930), I discovered that the newly
>>>> introduced LinearConstraintSet stores the constraints internally in a
>>>> HashSet.
>>>> This leads to undeterministic behavior as the iteration order of
>>>> constraints is not fixed (especially between different JRE versions).
>>>>
>>>> TBH, I never reviewed this change and I am a bit surprised to see it.
>>> Imho
>>>> there is no need to have a Set here, and would prefer to change this to a
>>>> list implementation.
>>>
>>> -1
>>> Unless the order of iteration is a requirement of the mathematical
>>> description of the algorithm.
>>> If so:
>>> * This requirement should appear prominently in the Javadoc.[1]
>>> * Please discard the rest of this mail.
>>> If not, then the order is only an implementation detail (IOW, with infinite
>>> precision, the solution would not change with different iteration orders),
>>> I would be cautious to rely on a specific implementation of the container
>>> used to store input data.
>>>
>>> Maybe that the behaviour described in MATH-930 indicates an inherent
>>> weakness of the algorithm (or too stringent requirements); if so, the
>>> better
>>> solution is probably not to rely on whether side-effects are visible or
>>> not.
>>>
>>> Also, I note that in the (deprecated) package
>>> "o.a.c.m.optimization.linear",
>>> the constraints are passed to "optimize" as a
>>> Collection<LinearConstraint>
>>> IIUC, the same behaviour could thus be produced by a user who'd call
>>> optimize several times, passing the same set of constraints but stored in a
>>> different order in the Collection.
>>>
>>
>> Hi Gilles,
>>
>> yes I understand your concerns, and the problem is two-fold:
>>
>> * make the algorithm behave deterministic in all environments
>> (I do not want to spend each time 1 day debugging why it works in one
>> case or another)
>
> I can understand; but the suggested fix is not a fix (IIUC), it only hides
> the problem.
>
>> * fix the obvious numerical stability problem with certain ordering of
>> constraints
>>
>> Although before the parameter was passed as a Collection, most people
>> actually used a List or something similar.
>> At least you had control over it,
>
> I think that this is called "false sense of security".
> In this instance you run a program in its unstable regime, and feel secure
> that the List container will not show you how untrustworthy the result is.
>
>> now it is just a HashSet, inside a CM
>> class which you can not control.
>
> As an implementation detail, this is all for the better.
>
>> So I would really prefer to at least change it to a LinkedHashSet with
>> deterministic iteration order, and investigate further the other problem.
>
> Feel free to use whatever in order to investigate, but don't bury the
> problem by changing the implementation. IMHO, it is a _feature_ if the
> current implementation uncovered a numerical bug.
>
> If we do not have the resources to dig further into the real problem, we can
> circumscribe it by indicating which interval of epsilon values are
> considered trustworthy (and declining all resposibility if user try pushing
> the implementation too far).
Well, I do disagree.
I do not want to have a situation where users get different results with
each run. I want to have deterministic behavior for deterministic
algorithms.
Yes, there are numerical stability issues, which in this case can be
treated by relaxing the convergence criteria as the user did.
Otoh, we should have thorough testing where a permutation of the linear
constraints could be a useful addition to detect more such issues. For
such a flexible tool like the SimplexSolver, there will always be
problems where the solution is difficult to find, and will require some
tuning. Even octave (using the very good and mature glpk library) did
not find the optimal solution in this case.
Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] OptimizationData and LinearConstraintSet
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hi Thomas.
On Thu, Jan 17, 2013 at 03:59:20PM +0100, Thomas Neidhart wrote:
> On Thu, Jan 17, 2013 at 3:52 PM, Gilles Sadowski <
> gilles@harfang.homelinux.org> wrote:
>
> > On Thu, Jan 17, 2013 at 02:28:56PM +0100, Thomas Neidhart wrote:
> > > Hi,
> > >
> > > by investigating a recent issue (MATH-930), I discovered that the newly
> > > introduced LinearConstraintSet stores the constraints internally in a
> > > HashSet.
> > > This leads to undeterministic behavior as the iteration order of
> > > constraints is not fixed (especially between different JRE versions).
> > >
> > > TBH, I never reviewed this change and I am a bit surprised to see it.
> > Imho
> > > there is no need to have a Set here, and would prefer to change this to a
> > > list implementation.
> >
> > -1
> > Unless the order of iteration is a requirement of the mathematical
> > description of the algorithm.
> > If so:
> > * This requirement should appear prominently in the Javadoc.[1]
> > * Please discard the rest of this mail.
> > If not, then the order is only an implementation detail (IOW, with infinite
> > precision, the solution would not change with different iteration orders),
> > I would be cautious to rely on a specific implementation of the container
> > used to store input data.
> >
> > Maybe that the behaviour described in MATH-930 indicates an inherent
> > weakness of the algorithm (or too stringent requirements); if so, the
> > better
> > solution is probably not to rely on whether side-effects are visible or
> > not.
> >
> > Also, I note that in the (deprecated) package
> > "o.a.c.m.optimization.linear",
> > the constraints are passed to "optimize" as a
> > Collection<LinearConstraint>
> > IIUC, the same behaviour could thus be produced by a user who'd call
> > optimize several times, passing the same set of constraints but stored in a
> > different order in the Collection.
> >
>
> Hi Gilles,
>
> yes I understand your concerns, and the problem is two-fold:
>
> * make the algorithm behave deterministic in all environments
> (I do not want to spend each time 1 day debugging why it works in one
> case or another)
I can understand; but the suggested fix is not a fix (IIUC), it only hides
the problem.
> * fix the obvious numerical stability problem with certain ordering of
> constraints
>
> Although before the parameter was passed as a Collection, most people
> actually used a List or something similar.
> At least you had control over it,
I think that this is called "false sense of security".
In this instance you run a program in its unstable regime, and feel secure
that the List container will not show you how untrustworthy the result is.
> now it is just a HashSet, inside a CM
> class which you can not control.
As an implementation detail, this is all for the better.
> So I would really prefer to at least change it to a LinkedHashSet with
> deterministic iteration order, and investigate further the other problem.
Feel free to use whatever in order to investigate, but don't bury the
problem by changing the implementation. IMHO, it is a _feature_ if the
current implementation uncovered a numerical bug.
If we do not have the resources to dig further into the real problem, we can
circumscribe it by indicating which interval of epsilon values are
considered trustworthy (and declining all resposibility if user try pushing
the implementation too far).
Best,
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] OptimizationData and LinearConstraintSet
Posted by Thomas Neidhart <th...@gmail.com>.
On Thu, Jan 17, 2013 at 3:52 PM, Gilles Sadowski <
gilles@harfang.homelinux.org> wrote:
> On Thu, Jan 17, 2013 at 02:28:56PM +0100, Thomas Neidhart wrote:
> > Hi,
> >
> > by investigating a recent issue (MATH-930), I discovered that the newly
> > introduced LinearConstraintSet stores the constraints internally in a
> > HashSet.
> > This leads to undeterministic behavior as the iteration order of
> > constraints is not fixed (especially between different JRE versions).
> >
> > TBH, I never reviewed this change and I am a bit surprised to see it.
> Imho
> > there is no need to have a Set here, and would prefer to change this to a
> > list implementation.
>
> -1
> Unless the order of iteration is a requirement of the mathematical
> description of the algorithm.
> If so:
> * This requirement should appear prominently in the Javadoc.[1]
> * Please discard the rest of this mail.
> If not, then the order is only an implementation detail (IOW, with infinite
> precision, the solution would not change with different iteration orders),
> I would be cautious to rely on a specific implementation of the container
> used to store input data.
>
> Maybe that the behaviour described in MATH-930 indicates an inherent
> weakness of the algorithm (or too stringent requirements); if so, the
> better
> solution is probably not to rely on whether side-effects are visible or
> not.
>
> Also, I note that in the (deprecated) package
> "o.a.c.m.optimization.linear",
> the constraints are passed to "optimize" as a
> Collection<LinearConstraint>
> IIUC, the same behaviour could thus be produced by a user who'd call
> optimize several times, passing the same set of constraints but stored in a
> different order in the Collection.
>
Hi Gilles,
yes I understand your concerns, and the problem is two-fold:
* make the algorithm behave deterministic in all environments
(I do not want to spend each time 1 day debugging why it works in one
case or another)
* fix the obvious numerical stability problem with certain ordering of
constraints
Although before the parameter was passed as a Collection, most people
actually used a List or something similar.
At least you had control over it, now it is just a HashSet, inside a CM
class which you can not control.
So I would really prefer to at least change it to a LinkedHashSet with
deterministic iteration order, and investigate further the other problem.
Thomas
Re: [math] OptimizationData and LinearConstraintSet
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Thu, Jan 17, 2013 at 02:28:56PM +0100, Thomas Neidhart wrote:
> Hi,
>
> by investigating a recent issue (MATH-930), I discovered that the newly
> introduced LinearConstraintSet stores the constraints internally in a
> HashSet.
> This leads to undeterministic behavior as the iteration order of
> constraints is not fixed (especially between different JRE versions).
>
> TBH, I never reviewed this change and I am a bit surprised to see it. Imho
> there is no need to have a Set here, and would prefer to change this to a
> list implementation.
-1
Unless the order of iteration is a requirement of the mathematical
description of the algorithm.
If so:
* This requirement should appear prominently in the Javadoc.[1]
* Please discard the rest of this mail.
If not, then the order is only an implementation detail (IOW, with infinite
precision, the solution would not change with different iteration orders),
I would be cautious to rely on a specific implementation of the container
used to store input data.
Maybe that the behaviour described in MATH-930 indicates an inherent
weakness of the algorithm (or too stringent requirements); if so, the better
solution is probably not to rely on whether side-effects are visible or not.
Also, I note that in the (deprecated) package "o.a.c.m.optimization.linear",
the constraints are passed to "optimize" as a
Collection<LinearConstraint>
IIUC, the same behaviour could thus be produced by a user who'd call
optimize several times, passing the same set of constraints but stored in a
different order in the Collection.
Best regards,
Gilles
[1] So that developers are aware of the limitations and can choose
appropriate data structures.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org