Replies: 2 comments 2 replies
-
What I mean is this: Say I have the following GMM with two components: @model GMM(y)
mu ~ filldist(Normal(), 2)
sigma ~ filldist(LogNormal(), 2)
eta ~ Dirichlet(2, 0.5)
y .~ UnivariateGMM(mu, sigma, Categorical(eta))
end In addition, I would like to impose that |
Beta Was this translation helpful? Give feedback.
-
We don't, though we have specific instance(s) implemented I believe (e.g. Turing.jl/src/stdlib/distributions.jl Line 134 in 8886d35 But for the specific stuff you're mentioning here, you could implemented it as a @model function GMM(y)
mu ~ transform(filldist(Normal(), 2), OrderedBijector())
sigma ~ filldist(LogNormal(), 2)
eta ~ Dirichlet(2, 0.5)
y .~ UnivariateGMM(mu, sigma, Categorical(eta))
end We could also just add in a convenience function, e.g. ordered(d::Distribution) = Bijectors.transformed(d, OrderedBijector()) An implementation of import Bijectors: Bijector, Inverse, logabsdetjac
struct OrderedBijector <: Bijector{1} end
function (b::OrderedBijector)(x::AbstractVector)
y = similar(x)
y[1] = x[1]
@. y[2:end] = log(x[2:end] - x[1:end - 1])
return y
end
function (ib::Inverse{<:OrderedBijector})(y::AbstractVector)
x = similar(y)
x[1] = y[1]
x[2:end] = y[1] .+ cumsum(exp.(y[2:end]))
return x
end
logabsdetjac(ib::Inverse{<:OrderedBijector}, y::AbstractVector) = sum(y[2:end])
logabsdetjac(b::OrderedBijector, x) = -logabsdetjac(inv(b), b(x)) The annoying bit is that we also need to implement custom adjoints for Zygote.jl and ReverseDiff.jl due to the fact that here we're using mutation. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In Turing, do we currently have something like ordered vectors from STAN?
What I mean is this:
Say I have the following GMM with two components:
In addition, I would like to impose that
mu[1] < mu[2]
. In STAN, I would accomplish this by defining mu as anordered
vector. What is the recommended way of doing this in Turing?Beta Was this translation helpful? Give feedback.
All reactions