Skip to content

values_as_in_model doesn't pick up prefixes #788

@penelopeysm

Description

@penelopeysm

MWE

using DynamicPPL, Distributions

@model function submodel()
  x ~ Normal(0, 1)
  return x
end

@model function parentmodel()
  x1 ~ to_submodel(prefix(submodel(), :a), false)
  x2 ~ to_submodel(prefix(submodel(), :b), false)
  return x1 + x2
end

m = parentmodel()
vi = VarInfo(m)
values_as_in_model(m, false, vi)
# OrderedDict{Any, Any} with 1 entry:
#   x => -1.28582

This leads to the following issue when sampling in Turing:

using Turing

@model function submodel()
  x ~ Normal(0, 1)
  return x
end

@model function parentmodel()
  x1 ~ to_submodel(DynamicPPL.prefix(submodel(), :a), false)
  x2 ~ to_submodel(DynamicPPL.prefix(submodel(), :b), false)
  return x1 + x2
end

sample(parentmodel(), NUTS(), 1000; check_model=false)
┌ Info: Found initial step size
└   ϵ = 3.2
Sampling 100%|████████████████████████████████████████████████████████████████████| Time: 0:00:04
Chains MCMC chain (1000×13×1 Array{Float64, 3}):

Iterations        = 501:1:1500
Number of chains  = 1
Samples per chain = 1000
Wall duration     = 5.01 seconds
Compute duration  = 5.01 seconds
parameters        = x
internals         = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size

Summary Statistics
  parameters      mean       std      mcse    ess_bulk   ess_tail      rhat   ess_per_sec
      Symbol   Float64   Float64   Float64     Float64    Float64   Float64       Float64

           x    0.0263    0.9781    0.0294   1095.9498   817.8880    1.0003      218.6652

Quantiles
  parameters      2.5%     25.0%     50.0%     75.0%     97.5%
      Symbol   Float64   Float64   Float64   Float64   Float64

           x   -1.8107   -0.6148    0.0471    0.6746    1.9686

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions