CobayaSampler/cobaya

Precision Error makes the minimize break down when input parameters are close to the bounds

M-X-Lin opened this issue · 5 comments

The "minimize" code may break down when the input parameters are close to but not out of bounds.

This is due to the precision error when "minimize" is doing the affine transform "param_input -> param_x" where "param_input" is the input parameter and "param_x" is the transformed parameter used in "bobyqa" code. The same for bounds "bound_input -> bound_x". If param_input is close but not out of bound_input (especially in the case equal to bound), it is possible that param_x is out of bound_x due to a precision error in the affine transform. So bound check will pass in "minimize" but fail in "bobyqa" and return an infinity likelihood, hence breaking down the code during the bobyqa interpolation with LINEAR ALGEBRA error.

One simple way I am using to solve it is to narrow down the transformed bounds a little bit:
bounds[:,0] = bounds[:,0]+1e-7
bounds[:,1] = bounds[:,1]-1e-7
This simple solution works well, but there could be a more elegant way to solve it.

cmbant commented

I'm not sure why affine_transform(initial_point) and affine_transform(bound) would differ, since they should have the same rounding error if the inputs are identical?

cmbant commented

If you have a short reproducible test case that would be helpful

I'm not sure why affine_transform(initial_point) and affine_transform(bound) would differ, since they should have the same rounding error if the inputs are identical?

I think it may be that the inputs are not identical but very close up to a tiny rounding error.

If you have a short reproducible test case that would be helpful

I am not sure if I can still find a short reproducible test case since several months passed and it occurs in an extension model - I will try.
But I think it may be possible to trigger it even in LCDM by simply setting the boundary not including the best-fit value, so minimizer will try to get close to the boundary values.

Closing. Please, do reopen if you can find a reproducible case.