Inference with the SampleListFormConstraint #340
-
|
Hi, I'm trying to do inference in a continuous multivariate model. I want to estimate a parameter belief from a Gaussian prior and log-pdfs for the likelihood. I want to approximate the posterior by a using RxInfer
struct Observation end
@node Observation Stochastic [ out, x ]
@rule Observation(:x, Marginalisation) (q_out::PointMass,) = begin
y = mean(q_out)
log_mu(x) = -0.5*(y - x)'*(y - x) # Some function
return ContinuousMultivariateLogPdf(UnspecifiedDomain(), log_mu)
end
@model function mwe(y)
x ~ MvNormalMeanCovariance(zeros(2), diageye(2)) # Parameter prior
for i in eachindex(y)
y[i] ~ Observation(x)
end
end
constraints = @constraints begin
q(x) :: SampleListFormConstraint(20)
end
# Generate some data
Y_hat = rand(MvNormalMeanPrecision(zeros(2), diageye(2)), 20)
y_hat = [y_i for y_i in eachcol(Y_hat)]
result = infer(
model = mwe(),
data = (y = y_hat,),
constraints = constraints
)gives MethodError: no method matching __approximate(::SampleListFormConstraint{20, Random._GLOBAL_RNG, AutoProposal, BayesBase.BootstrapImportanceSampling}, ::MvNormalMeanCovariance{Float64, Vector{Float64}, Matrix{Float64}}, ::LinearizedProductOf{ContinuousMultivariateLogPdf{UnspecifiedDomain}})
Closest candidates are:
__approximate(!Matched::SampleListFormConstraint{N, R, S, M}, ::Any, ::Any) where {N, R, S<:RightProposal, M}
@ RxInfer C:\Users\tvdlaar\.julia\packages\RxInfer\iG4wU\src\constraints\form\form_sample_list.jl:44
__approximate(::SampleListFormConstraint{N, R, S, M}, ::Any, !Matched::BayesBase.AbstractContinuousGenericLogPdf) where {N, R, S<:AutoProposal, M}
@ RxInfer C:\Users\tvdlaar\.julia\packages\RxInfer\iG4wU\src\constraints\form\form_sample_list.jl:56
__approximate(::SampleListFormConstraint{N, R, S, M}, !Matched::BayesBase.AbstractContinuousGenericLogPdf, ::Any) where {N, R, S<:AutoProposal, M}
@ RxInfer C:\Users\tvdlaar\.julia\packages\RxInfer\iG4wU\src\constraints\form\form_sample_list.jl:52
... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
An implicit optimization of constraints = @constraints begin
q(x) :: SampleListFormConstraint(20, LeftProposal())
endNow if you rerun you'll still run into an error, but this is in the actual sampling, so we're further down the line. The problem is that the domain of @rule Observation(:x, Marginalisation) (q_out::PointMass,) = begin
y = mean(q_out)
log_mu(x) = -0.5*(y - x)'*(y - x) # Some function
return ContinuousMultivariateLogPdf(RxInfer.BayesBase.DomainSets.RealNumbers() ^ length(y), log_mu)
endWith this rule, inference runs for me. Still we should fix the bug where |
Beta Was this translation helpful? Give feedback.
An implicit optimization of
RxInferseems to be causing a bug here. What happens is the following:RxInferis trying to multiply all incoming messages toxbefore approximating with a sample list. The problem is thatRxInferfirst tries to multiply allContinuousMultivariateLogPdf's (storing them in aLinearizedProductOf) and tries to multiply this result with aMvNormalMeanCovariance. This is a problem because according toRxInfer,aLinearizedProductOfis not anAbstractContinuousGenericLogPdf,so we do not know which distribution to use as a reference distribution. Let's first propose toRxInferto use theMvNormalMeanCovarianceas it's reference distribution: