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 toindgiven normalised weightsw. -
conditional_resample!(res, ind, w, k, i, rng)does conditional resampling in place toindgivenind[k] = iand 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
resshould be a subtype ofResampling. (see below) -
indshould be a subtype ofAbstractVector{<: Integer}. -
wshould be a subtype ofAbstractVector{<: AbstractFloat}. -
kandishould be subtypes ofInteger. -
rngshould be a subtype ofAbstractRNGfrom the packageRandom.rngdefaults toRandom.GLOBAL_RNG.
Furthermore, resample! and conditional_resample! assume that:
-
(not checked!)
wis normalised. -
(checked) the vectors
indandware both of lengthN >= 2.Nmust match with the number of particles used to construct the resampling (see "Constructing Resampling objects" below). AnAssertionErroris raised if either of these conditions does not hold. -
(checked)
$i, k \in {1:N}$ . AnAssertionErroris 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: ASymbolspecifying the type of randomisation applied to the indices which are sampled internally in ascending order. May be:default(default),:none,:shuffleor:circular.:shuffleshuffles the indices randomly and:circularapplies a random circular shift.:defaultuses 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,:sortor:partition. The default is:default, which usesintentto 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:unconditionalor:conditional, default is:unconditional. Specifies how:defaultin argumentsrandomisationandordershould be resolved (if either is set to:default). The default values produced depend on the resampling being constructed.:unconditionaluses a sensible default from the perspective of unconditional resampling, and:conditionalfrom the perspective of conditional resampling. Furthermore, settingintent = :conditionalensures that the output object can implement conditional resampling. If values forrandomisationandorderare passed such that this can not be guaranteed, anArgumentErroris 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