You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
as(Real, left, right) can return a value greater than right #183
as(Real, left, right) is TVShift(left) ∘ TVScale(right - left) ∘ TVLogistic(). When logistic(x) rounds to 1.0, the result is left + (right - left), which in floating point need not equal right and can exceed it:
julia>using TransformVariables
julia> t =as(Real, -1.0, 0.1)
as(Real, -1.0, 0.10000000000000009) (dimension 1)
julia> y =transform(t, 40.0)
0.10000000000000009
julia> y >0.1true
The lower end is exact (logistic(x) underflows to 0.0 and the result is left), and so are the one-sided transforms. The show output above has the same rounding, since it reconstructs right as shift + scale.
Downstream code that checks the result against the bounds it passed in then rejects it.
The composite only stores left and right - left, so right cannot be recovered exactly from it (left + (right - left) is the rounded value above). A fix could be to keep both endpoints and evaluate from the nearer one, e.g.
x <0? left + (right - left) *logistic(x) : right - (right - left) *logistic(-x)
which returns exactly left or right at saturation and is also more accurate near right. Clamping left + (right - left) * p to [left, right] would also work.
Yes, the whole transformation pipeline for the above used to be a single one, but #128 broke it up to the components above. Now they are used in the wild (see eg) so we should find a way to avoid the numerical issues while preserving the API.
I am still thinking about the right solution, so just brainstorming: maybe we could
make TVScale ∘ TVShift fuse into a single TVShiftScale,
replace CompositeScalarTransform with a left-associative nested implementation (currently it is flat),
have that specialize on fields {TVShiftScale,TVLogistic} which would implement the logistic(-x) branch recommended above (which I think is the nicest solution).
Activity
tpapp commentedon Nov 6, 2026
Yes, the whole transformation pipeline for the above used to be a single one, but #128 broke it up to the components above. Now they are used in the wild (see eg) so we should find a way to avoid the numerical issues while preserving the API.
I am still thinking about the right solution, so just brainstorming: maybe we could
TVScale ∘ TVShiftfuse into a singleTVShiftScale,CompositeScalarTransformwith a left-associative nested implementation (currently it is flat),{TVShiftScale,TVLogistic}which would implement thelogistic(-x)branch recommended above (which I think is the nicest solution).Fix `as(Real, left, right)` exceeding `right` (#183) (#184)