The ParticleFilter Module
ParticleFilter
— ModuleParticleFilter.jl
This is the bones for a discrete-time particle filter that I built to infer the infection numbers based on wastewater surveillance data
Module Index
ParticleFilter.Filter
ParticleFilter.FilterHistory
ParticleFilter.Particle
ParticleFilter.Particle
ParticleFilter.average_particle
ParticleFilter.average_particle
ParticleFilter.avg_pars
ParticleFilter.avg_pars
ParticleFilter.iterated_filtering!
ParticleFilter.log_likelihood
ParticleFilter.max_weight
ParticleFilter.multinomial_sampling!
ParticleFilter.normalize_weights!
ParticleFilter.percentile_sampling!
ParticleFilter.propogate_sample!
ParticleFilter.quant
ParticleFilter.reinitialize!
ParticleFilter.run_filter!
ParticleFilter.systematic_resampling!
ParticleFilter.update!
ParticleFilter.update_history!
ParticleFilter.update_likelihood!
ParticleFilter.varypars!
Detailed API
ParticleFilter.Filter
— TypeFilter(T::Real,particles::Vector{Particle},Measurements::DataFrame,MeasurementModel::Function,DynamicModel::Function)
- T - Time
- particles - Vector of particles
- Measurements - DataFrame of measurements
- MeasurementModel - A function that takes a DataFrameRow and a particle and outputs a real number
- DynamicModel - An inplace function that mutates a particle
ParticleFilter.FilterHistory
— TypeFilterHistory(T::Vector{Real},particles::Vector{Vector{Particle}})
ParticleFilter.Particle
— TypeParticle(weight::Float64,state::Vector{:<Real},pars::NamedTuple)
ParticleFilter.Particle
— MethodParticle(w::Float64,p::Particle)
Construct a particle using a new weight and an old particle
ParticleFilter.average_particle
— Methodaverage_particle(p::Filter)
Determines the average particle from given particle filter
ParticleFilter.average_particle
— Methodaverage_particle(p::Vector{Particle})
Find the average particle from a vector of particles
ParticleFilter.avg_pars
— Methodavg_pars(p::Filter)
Find the average of the parameters
ParticleFilter.avg_pars
— Methodavg_pars(p::Vector{Particle})
Compute the average parameters from a vector of particles
ParticleFilter.iterated_filtering!
— Methoditerated_filtering(p::Filter,)
Implements an iterated particle filter, which varies the parameters along with the state variables to try to converge to parameters that give the maximum log likelihood.
Returns parameters
ParticleFilter.log_likelihood
— Methodlikelihood(H::FilterHistory)
Computes an estimate of the log likelihood of the filter.
ParticleFilter.max_weight
— Methodmax_weight(p::Filter)
Return the particle with the highest weight
ParticleFilter.multinomial_sampling!
— Methodmultinomial_sampling!(p::Filter)
Resamples particles using a multinomial sampling procedure. If n is the number of particles, then this draws n samples from a multinomial distribution defined using the weights of the particles
ParticleFilter.normalize_weights!
— Methodnormalize_weights(p::Filter)
Normalize the weights
ParticleFilter.percentile_sampling!
— Methodpercentile_sampling(particle_filter,measurement;q::Float64)
resamples the particles based on the current measurement. Particles with a weight in the lowest q-th percentile are dropped and replaced by particles with the highest percentile.
ParticleFilter.propogate_sample!
— Methodpropogate_sample!(p::Filter,sample::Particle)
Uses the dynamic model to push particles forward one time step.
ParticleFilter.quant
— Methodquant(particle_filter,q::Float64)
Determines the weight that separates the particles into two groups
ParticleFilter.reinitialize!
— Methodreinitialize!(p::Filter)
Restarts the particle filter in the case that the filter
deviates too much from predictions.
ParticleFilter.run_filter!
— Methodrun_filter!(p::Filter)
updates the filter so that T is equal to the number of rows in the measurements dataframe. Returns a FilterHistory
ParticleFilter.systematic_resampling!
— Methodsystematic_resampling!(p::Filter)
Applies the systematic resampling procedure described in the POMP documentation by Aaron King et al.
ParticleFilter.update!
— Methodupdate!(p::Filter)
Move the particle filter forward one time-step. The particles are propogated using the dynamic model, and their weights updated using the measurement model. The particle weights are normalized so that they sum to 1, and then particles are resampled from a multinomial distribution.
ParticleFilter.update_history!
— Methodupdate_history!(History::FilterHistory,p::Filter)
Adds the current state of the particle filter to the filter history.
ParticleFilter.update_likelihood!
— Methodupdate_likelihood!(p::filter,sample::particle)
Changes the weight of the particle to its likelihood according to the measurement model
ParticleFilter.varypars!
— Methodvarypars!(p::Filter,V::Vector{Distribution})
For the iterated filtering algorithm.