Resamplings.jl is a Julia package implementing resampling algorithms intended to be used with (conditional) particle filters. The package aims to provide reasonably fast and easy to use functionality for resampling within performance-critical particle filtering code. The implementations of the resamplings are based on [Chopin, Singh, Soto and Vihola; 2022] and [Karppinen, Singh and Vihola; 2022] and references therein.
Currently, the package provides the following resampling algorithms:
-
multinomial
-
stratified
-
killing
-
systematic
-
residual
-
Srinivasan sampling process (SSP)
The behaviour of each resampling may additionally be altered with additional options (see "Constructing Resampling objects" below).
All resamplings support unconditional resampling that draws indices
To install Resamplings.jl, just run the following commands in the Julia REPL:
import Pkg
Pkg.add(url = "https://github.com/skarppinen/Resamplings.jl.git")
Resamplings.jl exports two main in place functions:
-
resample!(res, ind, w, rng)
does unconditional resampling in place toind
given normalised weightsw
. -
conditional_resample!(res, ind, w, k, i, rng)
does conditional resampling in place toind
givenind[k] = i
and normalised weightsw
.
These functions do not modify w
. After calling conditional_resample!
, the condition ind[k] = i
holds.
The types of the arguments should be as follows:
-
The argument
res
should be a subtype ofResampling
. (see below) -
ind
should be a subtype ofAbstractVector{<: Integer}
. -
w
should be a subtype ofAbstractVector{<: AbstractFloat}
. -
k
andi
should be subtypes ofInteger
. -
rng
should be a subtype ofAbstractRNG
from the packageRandom
.rng
defaults toRandom.GLOBAL_RNG
.
Furthermore, resample!
and conditional_resample!
assume that:
-
(not checked!)
w
is normalised. -
(checked) the vectors
ind
andw
are both of lengthN >= 2
.N
must match with the number of particles used to construct the resampling (see "Constructing Resampling objects" below). AnAssertionError
is raised if either of these conditions does not hold. -
(checked)
$i, k \in {1:N}$ . AnAssertionError
is raised if either of these does not hold.
Additionally, conditional_resample!
assumes (and checks) that w[i]
is strictly positive.
Attempting to call conditional_resample!
for resamplings not implementing conditional resampling raises a MethodError
.
The call list_conditional_resamplings()
may be used to print constructors for resamplings that implement conditional resampling (see also below).
The function has_conditional
can be called on a Resampling object to check whether it can be used for conditional resampling.
Resamplings may be constructed with the following kind of syntax:
res_mult = Resampling{:multinomial}(10);
res_strat = Resampling{:stratified}(128);
where the numbers refer to the numbers of particles used.
Resamplings.jl also provides the following aliases to refer to each resampling:
-
MultinomialResampling === Resampling{:multinomial}
-
StratifiedResampling === Resampling{:stratified}
-
KillingResampling === Resampling{:killing}
-
SystematicResampling === Resampling{:systematic}
-
ResidualResampling === Resampling{:residual}
-
SSPResampling === Resampling{:ssp}
That is, for example, to construct an object for systematic resampling, the constructor SystematicResampling(N)
may be used instead of Resampling{:systematic}(N)
.
The user facing constructor for each resampling is of the form:
Resampling{S}(N; randomisation, order, intent)
where S
is a Symbol
corresponding to a particular resampling (see above).
The arguments are:
-
N
: The number of particles used. -
randomisation
: ASymbol
specifying the type of randomisation applied to the indices which are sampled internally in ascending order. May be:default
(default),:none
,:shuffle
or:circular
.:shuffle
shuffles the indices randomly and:circular
applies a random circular shift.:default
uses the argumentintent
(see below) to choose a sensible default for the resampling being constructed. -
order
: specifies an order for the weightsw
. May be:default
(default),:none
,:sort
or:partition
. The default is:default
, which usesintent
to choose a sensible default for the resampling being constructed. This argument is available only in the constructors excluding multinomial and killing resampling. -
intent
: May be:unconditional
or:conditional
, default is:unconditional
. Specifies how:default
in argumentsrandomisation
andorder
should be resolved (if either is set to:default
). The default values produced depend on the resampling being constructed.:unconditional
uses a sensible default from the perspective of unconditional resampling, and:conditional
from the perspective of conditional resampling. Furthermore, settingintent = :conditional
ensures that the output object can implement conditional resampling. If values forrandomisation
andorder
are passed such that this can not be guaranteed, anArgumentError
is thrown.
- Resampling.jl also features a so-called single-even systematic resampling (SSS), which is included for research purposes (type
SSSResampling
). The SSS resampling may be used when the weights are nearly constant, otherwise it falls back to systematic resampling (cf. [Chopin, Singh, Soto and Vihola; 2022], Remark 18).
-
Santeri Karppinen ([email protected])
-
Matti Vihola
University of Jyväskylä, Finland, Department of Mathematics and Statistics
MIT