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
I often have components of models where I need to parameterize a categorical probability distribution. I use the following trick:
σ(z::Real) =one(z) / (one(z) +exp(-z))
functionunconstrained2probvec(v)
l =length(v)
remaining =1.0
o =zeros(l+1)
for i in1:l
#log(l+1-i) is a "balancing" shift to ensure that a vector of zeros givens you [1/N ... 1/N]
o[i] = remaining*σ(v[i] -log(l+1-i))
remaining -= o[i]
end
o[end] =max(0.0,remaining)
return o
end
This takes a vector of N-1 unbounded values and returns a vector of N values, bounded between 0 and 1, that sums to 1. When input is all zeros, the output is all 1/N.
I'm too stupid to figure out how to build this into your package, but if you think it would be sensible to do so, please consider this a feature request.
The text was updated successfully, but these errors were encountered:
Love the package.
I often have components of models where I need to parameterize a categorical probability distribution. I use the following trick:
This takes a vector of N-1 unbounded values and returns a vector of N values, bounded between 0 and 1, that sums to 1. When input is all zeros, the output is all 1/N.
I'm too stupid to figure out how to build this into your package, but if you think it would be sensible to do so, please consider this a feature request.
The text was updated successfully, but these errors were encountered: