TuringLang / AdvancedPS.jl

Implementation of advanced Sequential Monte Carlo and particle MCMC algorithms
https://turinglang.org/AdvancedPS.jl/
MIT License
56 stars 9 forks source link

PGAS errors out when adpting for nonlinear time series example #77

Closed YSanchezAraujo closed 1 year ago

YSanchezAraujo commented 1 year ago

Working through this example, and it suggests using PGAS to help with sample impoverishment. I've tried only replacing pgas = AdvancedPS.PG(n_particles) with pgas = AdvancedPS.PGAS(n_particles) as is done here , while keeping all else the same but am met with this error

ERROR: MethodError: no method matching step(::MersenneTwister, ::NonLinearTimeSeries, ::AdvancedPS.PGAS{AdvancedPS.ResampleWithESSThreshold{typeof(resample_systematic), Float64}})
Closest candidates are:
  step(::AbstractRNG, ::AdvancedPS.AbstractStateSpaceModel, ::AdvancedPS.PGAS) at ~/.julia/packages/AdvancedPS/Vox9w/src/smc.jl:130
  step(::AbstractRNG, ::AdvancedPS.AbstractStateSpaceModel, ::AdvancedPS.PGAS, ::Union{Nothing, AdvancedPS.PGState}; kwargs...) at ~/.julia/packages/AdvancedPS/Vox9w/src/smc.jl:130
  step(::AbstractRNG, ::AbstractMCMC.AbstractModel, ::AdvancedPS.PG) at ~/.julia/packages/AdvancedPS/Vox9w/src/smc.jl:88
  ...
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/AbstractMCMC/fWWW0/src/sample.jl:125 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/ProgressLogging/6KXlp/src/ProgressLogging.jl:328 [inlined]
  [3] (::AbstractMCMC.var"#21#22"{Bool, String, Nothing, Int64, Int64, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, MersenneTwister, NonLinearTimeSeries, AdvancedPS.PGAS{AdvancedPS.ResampleWithESSThreshold{typeof(resample_systematic), Float64}}, Int64, Int64})()
    @ AbstractMCMC ~/.julia/packages/AbstractMCMC/fWWW0/src/logging.jl:12
  [4] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:511
  [5] with_logger(f::Function, logger::LoggingExtras.TeeLogger{Tuple{LoggingExtras.EarlyFilteredLogger{TerminalLoggers.TerminalLogger, AbstractMCMC.var"#1#3"{Module}}, LoggingExtras.EarlyFilteredLogger{Logging.ConsoleLogger, AbstractMCMC.var"#2#4"{Module}}}})
    @ Base.CoreLogging ./logging.jl:623
  [6] with_progresslogger(f::Function, _module::Module, logger::Logging.ConsoleLogger)
    @ AbstractMCMC ~/.julia/packages/AbstractMCMC/fWWW0/src/logging.jl:36
  [7] macro expansion
    @ ~/.julia/packages/AbstractMCMC/fWWW0/src/logging.jl:11 [inlined]
  [8] mcmcsample(rng::MersenneTwister, model::NonLinearTimeSeries, sampler::AdvancedPS.PGAS{AdvancedPS.ResampleWithESSThreshold{typeof(resample_systematic), Float64}}, N::Int64; progress::Bool, progressname::String, callback::Nothing, discard_initial::Int64, thinning::Int64, chain_type::Type, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ AbstractMCMC ~/.julia/packages/AbstractMCMC/fWWW0/src/sample.jl:116
  [9] sample(rng::MersenneTwister, model::NonLinearTimeSeries, sampler::AdvancedPS.PGAS{AdvancedPS.ResampleWithESSThreshold{typeof(resample_systematic), Float64}}, N_or_isdone::Int64; kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:progress,), Tuple{Bool}}})
    @ AbstractMCMC ~/.julia/packages/AbstractMCMC/fWWW0/src/sample.jl:51
 [10] top-level scope
    @ REPL[35]:1

could someone help with how to resolve this?

FredericWantiez commented 1 year ago

Apologies for the delay I was travelling. I suspect you need to change your model type to an AdvancedPS.AbstractStateSpaceModel instead of the more general AbstractMCMC.AbstractModel. #79 might be helpful

YSanchezAraujo commented 1 year ago

Thanks for the reply! that does fix that portion. One of the things that I found really helpful about this particular tutorial (compared to say the GP one) was that it showed how to describe a model that allows for more complicated processes. That seems to have been removed in #79 because AdvancedPS.AbstractStateSpaceModel looks like it requires the definitions of the addition functions (e.g. isdone , initialization) ?