Skip to content

Commit

Permalink
promote at start, try to fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
acertain committed Aug 19, 2024
1 parent 213328d commit 1438fcd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bijectors/truncated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,26 @@ end
with_logabsdet_jacobian(b::TruncatedBijector, x) = transform(b, x), logabsdetjac(b, x)

function truncated_inv_logabsdetjac(y, a, b)
y, a, b = promote(y, a, b)
lowerbounded, upperbounded = isfinite(a), isfinite(b)
if lowerbounded && upperbounded
abs_y = abs(y)
return log(b - a) - abs_y + 2 * LogExpFunctions.log1pexp(-abs_y)
elseif lowerbounded || upperbounded
return convert(promote_type(typeof(y), typeof(a), typeof(b)), y)
return y
else
return zero(y)
end
end

function logabsdetjac(ib::Inverse{<:TruncatedBijector}, y)
a, b = ib.orig.lb, ib.orig.ub
return truncated_inv_logabsdetjac.(y, a, b)
return sum(truncated_inv_logabsdetjac.(y, a, b))
end

with_logabsdet_jacobian(ib::Inverse{<:TruncatedBijector}, y) = transform(ib, y), logabsdetjac(ib, y)
function with_logabsdet_jacobian(ib::Inverse{<:TruncatedBijector}, y)
return transform(ib, y), logabsdetjac(ib, y)
end

# It's only monotonically decreasing if it's only upper-bounded.
# In the multivariate case, we can only say something reasonable if entries are monotonic.
Expand Down

0 comments on commit 1438fcd

Please sign in to comment.