Skip to content

mccube._kernels.random

MonteCarloKernel ¤

Bases: AbstractRecombinationKernel

Monte Carlo particle sub-sampling/recombination.

Example
import jax.numpy as jnp
import jax.random as jr

key = jr.key(42)
kernel = mccube.MonteCarloKernel({"y": 3}, key=key)
y0 = {"y": jnp.ones((10,2))}
result = kernel(..., y0, ...)
# {"y": jnp.ones((3,2))}

Attributes:

  • recombination_count

    indicates the requested size of the recombined dimension.

  • with_replacement (bool) –

    if to perform sub-sampling with or without replacement.

  • weighting_function (Callable[[Weights], Weights | None]) –

    allows particle weights to be transformed. If the transform returns :code:None then the weights are assumed/implicitly uniform.

  • key (PRNGKeyArray) –

    the base PRNGKey required for Monte Carlo sampling.

MonteCarloPartitioningKernel ¤

Bases: AbstractPartitioningKernel

Monte carlo particle resampling/partitioning.

Rather than using the Monte Carlo method to reduce/recombine the particles, as in mccube.MonteCarloKernel, here the method is used simply to assign particles to \(m\) equally sized partitions.

Example
import jax.numpy as jnp
import jax.random as jr

key = jr.key(42)
kernel = mccube.MonteCarloKernel(..., key=key)
partitioning_kernel = mccube.MonteCarloPartitioningKernel(4, kernel)
y0 = jnp.ones((12,2))
result = partitioning_kernel(..., y0, ...)
# jnp.ones((4,3,2))

Attributes:

  • partition_count

    indicates the requested number of partitions, \(m\).

  • monte_carlo_kernel (MonteCarloKernel) –

    the base monte carlo kernel used for random partition assignment, with arbitrary recombination_count (as this count is overriden based on the partition_count).