nomad icon indicating copy to clipboard operation
nomad copied to clipboard

How To Test Equals Operators?

Open betanalpha opened this issue 11 years ago • 2 comments

Comparison operators are very bad for autodiff because they admit the construction of discontinuous functions. Equals operators are particularly bad because they can't even be tested with finite differences, as the perturbations cause the comparison to fail. Not sure how these operators would be tested.

  • [ ] src/scalar/operators/nonsmooth_operators/operator_equal_to
  • [ ] src/scalar/operators/nonsmooth_operators/operator_not_equal_to
  • [ ] src/scalar/operators/nonsmooth_operators/operator_unary_not

betanalpha avatar Aug 09 '14 21:08 betanalpha

operator= and operator!= should return int values, so I don't see an issue because there's no derivative created.

It's only the context they're used in that can create problems as in

if (a == b) stmt1 else stmt2;

The problem isn't the comparison operator, it's in its usage.

  • Bob

On Aug 9, 2014, at 5:55 PM, Michael Betancourt [email protected] wrote:

Comparison operators are very bad for autodiff because they admit the construction of discontinuous functions. Equals operators are particularly bad because they can't even be tested with finite differences, as the perturbations cause the comparison to fail. Not sure how these operators would be tested.

• src/scalar/operators/nonsmooth_operators/operator_equal_to • src/scalar/operators/nonsmooth_operators/operator_not_equal_to • src/scalar/operators/nonsmooth_operators/operator_unary_not — Reply to this email directly or view it on GitHub.

bob-carpenter avatar Aug 10 '14 18:08 bob-carpenter

The comparison operators return bools, and it’s the usage they admit that is exactly the problem. You can’t differentiate through the comparison analytically or approximately (which is why the finite difference fails) so the very existence of var-valued equals operators is ill-posed. Ill-defined tests are just a side effect of this — I’m not sure if there is a solution.

On Aug 10, 2014, at 7:00 PM, Bob Carpenter [email protected] wrote:

operator= and operator!= should return int values, so I don't see an issue because there's no derivative created.

It's only the context they're used in that can create problems as in

if (a == b) stmt1 else stmt2;

The problem isn't the comparison operator, it's in its usage.

  • Bob

On Aug 9, 2014, at 5:55 PM, Michael Betancourt [email protected] wrote:

Comparison operators are very bad for autodiff because they admit the construction of discontinuous functions. Equals operators are particularly bad because they can't even be tested with finite differences, as the perturbations cause the comparison to fail. Not sure how these operators would be tested.

• src/scalar/operators/nonsmooth_operators/operator_equal_to • src/scalar/operators/nonsmooth_operators/operator_not_equal_to • src/scalar/operators/nonsmooth_operators/operator_unary_not — Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

betanalpha avatar Aug 10 '14 20:08 betanalpha