mccube._utils
Helpful utilities used throughout MCCube.
nop
¤
Callable which accepts any arguments and does nothing.
pack_particles
¤
pack_particles(particles: Particles, weights: Weights | None) -> Particles | PackedParticles
Packs particles and normalized weights into a single
Particles PyTree.
Example
particles = {"y1": jnp.ones((10, 2))} # Shape: [n=10, d=2]
weights = {"y1": jnp.ones(10)} # Shape: [n=10]
packed_particles = mccube.pack_particles(particles, weights)
# {"y1": jnp.c_[particles["y1"], weights["y1"]i / 10]} Shape: [n=n, d=d+1]
weights = {"y1": None}
packed_particles = mccube.pack_particles(particles, weights)
# {"y1": particles["y1"]} Shape: [n=n, d=d]
Parameters:
Returns:
Source code in mccube/_utils.py
unpack_particles
¤
unpack_particles(particles: Particles, weighted: bool = False) -> tuple[Particles, None] | tuple[UnpackedParticles, Weights]
Unpacks PackedParticles into separate
PyTrees of Particles and Weights.
Example
particles = jnp.ones((10,2)) # Shape: [n=10, d=2]
weights = jnp.full(10, 1/10) # Shape: [n=10]
packed_particles = pack_particles(particles, weights) # Shape: [n=n, d=d+1]
result = unpack_particles(packed_particles, weighted=True)
# (particles, weights) Shape: [n=n, d=d], [n=n]
result = unpack_particles(packed_particles)
# (jnp.c_[particles, weights], None) Shape: [n=n, d=d+1], None
Parameters:
-
particles(Particles) –is a
ParticlesPyTree. -
weighted(bool, default:False) –indicates if to treat the
particlesasPackedParticles(weighted==True), or standardParticles(weighted==False).
Returns:
-
tuple[Particles, None] | tuple[UnpackedParticles, Weights]–A tuple of the unpacked
particlesand weights (weighted==True), or a tuple ofparticlesandNone(weighted==False).
Source code in mccube/_utils.py
all_subclasses
¤
Recursively identifies all subclasses of a class in the current scope.