Direct sampling & plots

Sample distribution

Every distribution in m.dist can be sampled directly, outside of a model, by passing sample=True. This is useful for prior predictive checks, simulating data, or quickly inspecting a distribution’s shape.

Code
from BayesForge import bf
m = bf()
# Draw 1000 samples from a standard normal
m.dist.normal(0, 1, shape=(4,), sample=True)
An NVIDIA GPU may be present on this machine, but a CUDA-enabled jaxlib is not installed. Falling back to cpu.
bf v 0.0.60 package loaded
jax.local_device_count 16
Array([-0.26306708, -1.2538079 ,  1.03392064, -0.29905866], dtype=float64)
library(BayesForge)
m <- importBF()
# Draw 1000 samples from a standard normal
m$dist$normal(0, 1, shape = reticulate::tuple(4L), sample=TRUE)
using PyBayesForge
using PythonCall
m = importBF()
# Draw 1000 samples from a standard normal
m.dist.normal(0, 1, shape = (4,), sample=true)

By using (to_jax=False), a direct sample is returned as a SampledData object — a thin wrapper around a JAX array. It behaves like a JAX array everywhere (arithmetic, indexing, jnp.* functions, jit/vmap/grad, use as a distribution parameter), and its repr reports the dtype so you can see the kind and precision at a glance:

The extra thing a SampledData gives you over a raw array is a set of built-in plotting methods and built-in helper functions.

Plotting helpers

Each plotting method is called directly on the sampled object. Most accept interactive=True (the default, Plotly) or interactive=False (matplotlib / seaborn):

The available methods depend on the shape of the sampled array.

1D-(n_samples,)

Code
m.dist.normal(0, 1, shape=(1000,), sample=True, to_jax=False).hist() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L), sample=TRUE, to_jax=FALSE)$hist()
m.dist.normal(0, 1, shape = (1000,), sample=true, to_jax=false).hist()
Code
m.dist.normal(0, 1, shape=(1000,), sample=True, to_jax=False).density()
m$dist$normal(0, 1, shape = reticulate::tuple(1000L), sample=TRUE, to_jax=FALSE)$density()
m.dist.normal(0, 1, shape = (1000,), sample=true, to_jax=false).density()

Treat the second axis as time and summarise across draws.

Code
m.dist.gaussian_random_walk(scale=0.5, num_steps=50, shape=(500,), sample=True, to_jax=False).timeseries(credible_interval=0.9)
m$dist$gaussian_random_walk(scale=0.5, num_steps = 50L, shape = reticulate::tuple(500L), sample=TRUE, to_jax=FALSE)$timeseries(credible_interval=0.9)
m.dist.gaussian_random_walk(scale=0.5, num_steps=50, shape = (500,), sample=true, to_jax=false).timeseries(credible_interval=0.9)

2D-(n_samples, n_variables)

Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).hist() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$hist()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).hist()
Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).density() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$density()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).density()
Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).boxplot() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$boxplot()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).boxplot()
Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).violinplot() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$violinplot()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).violinplot()
Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).pairplot() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$pairplot()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).pairplot()
Code
m.dist.lkj_cholesky(4, 2, name = 'a', sample = True, to_jax=False).corr_heatmap() 
m$dist$lkj_cholesky(4L, 2, name = 'a', sample = TRUE, to_jax=FALSE)$corr_heatmap()
m.dist.lkj_cholesky(4, 2, name = "a", sample = true, to_jax=false).corr_heatmap()
Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).traceplot() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$traceplot()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).traceplot()

Computes a 2D Kernel Density Estimate (KDE) using the first two variables. It plots a 3D surface where the X and Y axes represent the variables and the Z axis represents the estimated probability density.

Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).surface_3d() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$surface_3d()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).surface_3d()

Takes the first three variables (columns) and plots them directly as points in a 3D space (X, Y, and Z axes). Requires the array to have at least 3 variables (columns).

Code
m.dist.normal(0, 1, shape=(1000,4), sample=True, to_jax=False).scatter3d() 
m$dist$normal(0, 1, shape = reticulate::tuple(1000L, 4L), sample=TRUE, to_jax=FALSE)$scatter3d()
m.dist.normal(0, 1, shape = (1000, 4), sample=true, to_jax=false).scatter3d()

Compare draws against observed data.

3D-(n_samples, n_groups, n_times)

Code
m.dist.normal(0,1, name = 'a', shape=(100,4, 5), sample = True, to_jax=False).hist()
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L, 5L), sample = TRUE, to_jax=FALSE)$hist()
m.dist.normal(0,1, name = "a", shape = (100, 4, 5), sample = true, to_jax=false).hist()

Non-plot helper

In addition to plot helper functions, there are several other helper functions that can be used to compute summaries or transform the sampled array. For reduction operations (like mean, std, sum), you can pass an axis argument to reduce along specific dimensions. For example, passing axis=0 will reduce across the sample dimension.

mean

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).mean(axis=0)
SampledData([-0.06488969,  0.08455174, -0.19233163, -0.02897578], dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$mean(axis = 0L)
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).mean(axis=0)

std

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).std()
Array(0.98180266, dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$std()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).std()

variance

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).var()
Array(0.86305143, dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$var()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).var()

hdi

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).hdi(cred_mass=0.95)
(Array([-1.52283677, -1.20296693, -0.8468707 ,  0.88459643], dtype=float64),
 Array([-0.56191601, -0.36173829,  0.16279729,  0.40338408], dtype=float64))
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$hdi(cred_mass=0.95)
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).hdi(cred_mass=0.95)

sum

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).sum()
Array(-5.85177531, dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$sum()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).sum()

prod

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).prod()
Array(9.07886099e-97, dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$prod()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).prod()

min

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).min()
Array(-2.64763982, dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$min()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).min()

max

Code
m.dist.normal(0,1, name = 'a', shape=(100,4, 5), sample = True, to_jax=False).max()
Array(3.43074916, dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L, 5L), sample = TRUE, to_jax=FALSE)$max()
m.dist.normal(0,1, name = "a", shape = (100, 4, 5), sample = true, to_jax=false).max()

argmin

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).argmin()
Array(114, dtype=int64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$argmin()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).argmin()

argmax

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).argmax()
Array(263, dtype=int64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$argmax()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).argmax()

all

Code
m.dist.normal(0,1, name = 'a', shape=(100,4, 5), sample = True, to_jax=False).all()
Array(True, dtype=bool)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L, 5L), sample = TRUE, to_jax=FALSE)$all()
m.dist.normal(0,1, name = "a", shape = (100, 4, 5), sample = true, to_jax=false).all()

any

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).any()
Array(True, dtype=bool)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$any()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).any()

cumsum

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).cumsum()
SampledData([-1.98893260e-01, -1.88411053e+00, -3.43908159e-01,  7.25863335e-01,
       -1.56672811e+00, -5.59107629e-01,  2.51643685e-01, -1.43272344e-01,
        1.41205097e+00,  3.24853429e+00,  3.29485339e+00,  3.15151929e+00,
        3.82728775e+00,  4.68047425e+00,  4.84113183e+00,  4.34539313e+00,
        4.86946374e+00,  6.70729460e+00,  4.71267541e+00,  6.31432547e+00,
        6.55202462e+00,  6.33864035e+00,  5.37433816e+00,  4.99029410e+00,
        3.93084198e+00,  2.87572503e+00,  1.73012753e+00,  2.12672272e+00,
        1.82211090e+00,  2.12588673e+00,  2.79789807e+00,  4.66395946e+00,
        3.97107148e+00,  3.56106258e+00,  1.63430199e+00,  3.41839727e-01,
       -1.42237908e-01, -1.11606798e+00, -9.45765480e-01, -5.45041676e-01,
       -1.37267107e-01,  1.14668876e+00,  1.87814537e+00,  2.22331199e+00,
        3.79075507e+00,  3.58605554e+00,  5.68637590e+00,  5.31215047e+00,
        4.78154314e+00,  2.62435842e+00,  1.43781804e+00,  1.21651404e+00,
        2.27124233e+00,  1.25000152e+00,  9.95721322e-01, -9.08926631e-01,
       -2.92082905e+00, -1.41974857e+00, -1.69887058e+00,  4.03885118e-01,
       -4.09037328e-02,  4.35040659e-01,  1.11537841e+00,  4.74153135e-01,
        1.28470387e+00,  1.97695533e+00,  2.97156694e-01,  1.11426506e+00,
        1.90232864e+00,  3.26036242e+00,  3.56570838e+00,  5.78087311e+00,
        6.41323200e+00,  5.43817543e+00,  5.96258045e+00,  3.44606043e+00,
        1.85740401e+00,  2.89430958e+00,  3.16845399e+00,  3.95350532e+00,
        5.76796774e+00,  6.67602474e+00,  5.17448829e+00,  7.39109016e+00,
        7.96386494e+00,  7.92395877e+00,  7.46601032e+00,  6.46323159e+00,
        6.55520567e+00,  4.70076402e+00,  3.48998827e+00,  1.45902711e+00,
        1.32969041e+00,  2.84251227e+00,  2.56142724e+00,  2.03978170e+00,
        1.85301277e+00, -7.25185964e-01, -1.64952277e+00, -1.30203618e+00,
       -1.82089620e+00, -2.16624188e+00, -1.70438936e+00, -3.25888252e+00,
       -1.94423654e+00, -2.69811171e-01, -2.12689295e-01,  1.82302394e-01,
        1.98179601e+00,  7.45099512e-01,  2.43366679e+00,  3.49956726e+00,
        2.73737713e+00,  2.28026718e+00,  1.85656021e+00,  2.79600863e+00,
        4.30009496e+00,  3.48374984e+00,  3.68164151e+00,  4.76782756e+00,
        1.96742007e+00,  2.74368068e+00,  3.92268725e+00,  4.15666753e+00,
        4.18741026e+00,  1.69982835e+00,  9.62321195e-01, -1.62224025e-01,
       -1.06799636e+00, -9.04136487e-01,  8.39646929e-01,  1.36622867e+00,
        1.69854456e+00,  6.99852447e-01,  3.28520899e-01,  3.86794841e-01,
        1.71867284e+00,  9.75856510e-01,  6.66382196e-01,  5.63303738e-01,
        7.81895309e-01,  2.46779124e+00,  1.51598215e+00,  1.16623882e+00,
        2.84977983e+00,  9.83402191e-01,  2.45560556e-02, -4.41324157e-01,
        2.50975242e-01,  4.57280837e-01,  4.13205907e-01, -4.19356243e-01,
       -1.72612537e+00, -2.97802643e+00, -2.47922324e+00, -3.37521457e+00,
       -2.42336312e+00, -1.77883492e+00, -2.68438302e-01, -7.22146555e-01,
       -1.81044982e+00, -1.96810511e+00, -1.26298838e+00, -1.37191240e+00,
       -7.81709682e-01, -1.06181034e+00, -5.37726164e-01, -1.35652130e+00,
       -1.60728990e+00,  3.46022593e-01,  1.86229608e-01,  1.69433848e+00,
        1.98395060e+00,  2.36371381e+00,  1.66438032e+00,  2.34383926e+00,
        1.15212351e+00,  1.16770373e+00, -1.46175189e+00, -2.64605905e+00,
       -4.12159641e+00, -4.12010040e+00, -4.93655477e+00, -3.65741282e+00,
       -4.69481780e+00, -2.50449972e+00, -2.02846658e+00, -2.38809893e+00,
       -3.73813439e+00, -3.28721045e+00, -3.87478450e+00, -1.81442653e+00,
       -1.95935290e+00, -2.64204442e+00, -2.15554408e+00, -6.67206885e-01,
        9.31145549e-01,  1.74880910e+00,  3.15615545e+00,  4.40820132e+00,
        4.21458618e+00,  4.36642711e+00,  3.94640877e+00,  4.92913287e+00,
        5.57059514e+00,  5.88185182e+00,  7.24339505e+00,  7.64123511e+00,
        7.27583732e+00,  6.45351172e+00,  7.42939360e+00,  8.10904646e+00,
        8.15562736e+00,  7.57871381e+00,  8.48634578e+00,  1.14771623e+01,
        1.12014124e+01,  1.07825369e+01,  1.08977907e+01,  1.08700326e+01,
        1.10336455e+01,  1.18020771e+01,  1.09652588e+01,  1.21993877e+01,
        1.23743200e+01,  1.11488907e+01,  1.21198910e+01,  1.31541029e+01,
        1.18959745e+01,  1.13012200e+01,  1.09343151e+01,  1.06297373e+01,
        9.37255769e+00,  1.03768603e+01,  8.52553038e+00,  8.17006236e+00,
        7.61871732e+00,  9.61002581e+00,  9.97163091e+00,  1.02177075e+01,
        1.10203952e+01,  1.08019681e+01,  1.16322540e+01,  9.84102243e+00,
        1.01514899e+01,  9.95484557e+00,  8.09023473e+00,  1.05501532e+01,
        1.14658852e+01,  1.34297429e+01,  1.48614573e+01,  1.59353620e+01,
        1.52116694e+01,  1.83365028e+01,  1.94150696e+01,  1.91304165e+01,
        1.97067479e+01,  1.93005705e+01,  1.98123687e+01,  1.83286911e+01,
        1.68790826e+01,  1.80122243e+01,  1.93044999e+01,  2.08008625e+01,
        1.88254206e+01,  1.82900798e+01,  1.80868248e+01,  1.76622324e+01,
        1.79020884e+01,  1.72698662e+01,  1.89392902e+01,  1.99663967e+01,
        1.94345119e+01,  2.04802718e+01,  1.95805677e+01,  2.01957328e+01,
        2.12712032e+01,  2.04615951e+01,  2.06408771e+01,  1.91533127e+01,
        1.88115303e+01,  1.81477445e+01,  1.99913738e+01,  2.05626038e+01,
        2.09783135e+01,  2.31785448e+01,  2.26621180e+01,  2.22120758e+01,
        2.28923789e+01,  2.47414524e+01,  2.71372914e+01,  2.68736084e+01,
        2.61666356e+01,  2.54410209e+01,  2.42333537e+01,  2.45605671e+01,
        2.45314140e+01,  2.69452091e+01,  2.78307622e+01,  2.94033099e+01,
        2.96491474e+01,  2.89623464e+01,  2.96020374e+01,  3.10914850e+01,
        3.02697541e+01,  3.01922292e+01,  3.00104055e+01,  3.03872451e+01,
        3.03394810e+01,  3.01179428e+01,  3.06349684e+01,  2.93515639e+01,
        3.02576377e+01,  2.78508398e+01,  2.94399266e+01,  2.96980986e+01,
        3.03418799e+01,  3.02856801e+01,  3.15709443e+01,  3.11454533e+01,
        3.12999875e+01,  3.07883662e+01,  3.21082979e+01,  3.29741931e+01,
        3.22707483e+01,  3.19908000e+01,  3.21570165e+01,  3.35468421e+01,
        3.27399790e+01,  3.25367524e+01,  3.13150837e+01,  3.29429675e+01,
        3.37161864e+01,  3.57128113e+01,  3.57606544e+01,  3.50918223e+01,
        3.55203150e+01,  3.63907587e+01,  3.62325257e+01,  3.46487080e+01,
        3.43640976e+01,  3.50182875e+01,  3.59757491e+01,  3.58445439e+01,
        3.47177028e+01,  3.52270898e+01,  3.45814713e+01,  3.49900356e+01,
        3.55283807e+01,  3.57580175e+01,  3.48486279e+01,  3.45180039e+01,
        3.26031008e+01,  3.15732076e+01,  3.16190925e+01,  3.03134984e+01,
        3.04284738e+01,  3.06264791e+01,  3.03608762e+01,  3.00493849e+01,
        3.00726217e+01,  3.03852583e+01,  3.25075283e+01,  3.10489002e+01,
        3.07456526e+01,  3.12979496e+01,  3.18205677e+01,  3.27034828e+01,
        3.15311062e+01,  3.04906464e+01,  3.03451158e+01,  2.90343860e+01,
        3.03446698e+01,  3.03195196e+01,  3.18220439e+01,  3.05697848e+01,
        3.18572576e+01,  3.35827324e+01,  3.22837712e+01,  3.12644550e+01,
        3.19454953e+01,  3.24670032e+01,  3.23331797e+01,  3.12448613e+01,
        3.24807044e+01,  3.26920438e+01,  3.33312556e+01,  3.37840843e+01,
        3.34531175e+01,  3.39291385e+01,  3.43696189e+01,  3.41543346e+01,
        3.33448687e+01,  3.17435036e+01,  3.30673331e+01,  3.25336660e+01,
        3.26167326e+01,  3.25300877e+01,  3.30485845e+01,  3.35610063e+01],      dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$cumsum()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).cumsum()

round

Code
m.dist.normal(0,1, name = 'a', shape=(100,4, 5), sample = True, to_jax=False).round()
SampledData([[[ 0., -2.,  0.,  1., -0.],
        [-1., -1., -1.,  1., -0.],
        [ 2., -0., -1., -0.,  1.],
        [ 0., -0., -1.,  1., -1.]],

       [[-1.,  1.,  1.,  1., -1.],
        [-0., -1.,  0., -1.,  0.],
        [-1.,  1., -0., -1., -1.],
        [ 1., -0., -1.,  1., -1.]],

       [[ 2., -0.,  0., -1.,  1.],
        [-2., -0.,  1., -0., -1.],
        [-0.,  1., -0.,  2.,  0.],
        [-1., -1., -1.,  1.,  1.]],

       ...,

       [[ 0., -2., -1., -1.,  2.],
        [-0.,  0.,  0., -2.,  1.],
        [ 0.,  0.,  1., -0.,  1.],
        [-1.,  0.,  0., -1., -1.]],

       [[ 1.,  1., -1.,  0.,  1.],
        [-0., -0., -0., -0., -1.],
        [ 0.,  2.,  1.,  0.,  1.],
        [ 0.,  0.,  2., -1., -1.]],

       [[ 0., -1.,  0.,  1., -2.],
        [ 0., -2.,  0.,  2.,  1.],
        [ 1., -0.,  1., -0., -1.],
        [-0., -1.,  0., -1., -0.]]], dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L, 5L), sample = TRUE, to_jax=FALSE)$round()
m.dist.normal(0,1, name = "a", shape = (100, 4, 5), sample = true, to_jax=false).round()

clip

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).clip(0, 1)
SampledData([[1.        , 0.        , 0.        , 1.        ],
       [0.        , 0.        , 0.59620197, 1.        ],
       [0.        , 0.        , 0.        , 0.        ],
       [1.        , 0.56747244, 0.        , 0.        ],
       [1.        , 0.        , 0.        , 0.        ],
       [0.        , 0.89635759, 0.11477457, 0.22299951],
       [0.76324816, 0.        , 0.        , 1.        ],
       [0.75793577, 1.        , 0.        , 0.        ],
       [1.        , 0.        , 0.30745333, 0.13209964],
       [0.19165843, 0.        , 1.        , 0.        ],
       [1.        , 0.59474032, 0.1798888 , 0.        ],
       [0.        , 0.        , 1.        , 0.69035917],
       [0.        , 0.        , 1.        , 0.        ],
       [0.        , 0.        , 0.80028271, 0.65176835],
       [0.        , 0.        , 0.        , 0.65846121],
       [0.        , 0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.94380033, 0.        ],
       [0.        , 0.        , 0.6901438 , 0.        ],
       [1.        , 0.        , 0.        , 1.        ],
       [0.80454701, 0.        , 0.        , 0.29966508],
       [0.01693606, 0.        , 0.        , 0.        ],
       [0.        , 1.        , 0.        , 0.        ],
       [0.        , 1.        , 0.        , 0.        ],
       [0.        , 1.        , 0.02934437, 0.24545546],
       [0.        , 0.        , 0.        , 1.        ],
       [0.        , 0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.50291213, 1.        ],
       [0.        , 0.        , 0.        , 0.        ],
       [0.        , 0.        , 1.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        ],
       [0.        , 1.        , 0.        , 0.        ],
       [0.9575945 , 0.        , 0.        , 0.96175041],
       [0.68456903, 0.08631939, 0.        , 0.5500867 ],
       [0.        , 0.        , 0.97164914, 0.        ],
       [0.        , 1.        , 0.        , 0.        ],
       [0.77683155, 0.        , 0.        , 0.        ],
       [0.        , 0.09048724, 0.1097437 , 0.        ],
       [0.0325098 , 0.76412371, 0.        , 1.        ],
       [0.        , 0.        , 0.31327538, 0.31618174],
       [0.        , 1.        , 0.15143991, 0.87623415],
       [0.84622165, 0.        , 0.        , 0.43824124],
       [0.        , 0.72403624, 0.        , 0.2592113 ],
       [0.04077591, 0.59827973, 0.        , 0.        ],
       [0.        , 0.        , 0.24500829, 0.        ],
       [0.        , 0.        , 0.        , 0.33249099],
       [0.        , 0.78694667, 0.        , 1.        ],
       [1.        , 1.        , 1.        , 0.        ],
       [0.        , 0.70811773, 0.        , 0.        ],
       [0.        , 0.        , 0.25966173, 1.        ],
       [1.        , 0.        , 0.        , 0.        ],
       [0.73648518, 1.        , 0.8353652 , 0.        ],
       [0.15973589, 0.        , 0.        , 0.        ],
       [0.        , 0.        , 1.        , 0.        ],
       [0.59115296, 0.85889143, 0.30919132, 0.51655434],
       [0.        , 0.        , 0.18018742, 0.        ],
       [0.        , 1.        , 0.        , 0.        ],
       [1.        , 0.27545302, 0.98898642, 0.32126961],
       [1.        , 0.        , 0.        , 0.        ],
       [0.        , 0.1876815 , 0.70968435, 0.        ],
       [0.13757641, 0.        , 0.4222299 , 0.0350866 ],
       [1.        , 0.02237338, 0.        , 0.16626453],
       [0.        , 1.        , 0.        , 0.        ],
       [0.61289693, 0.        , 1.        , 0.        ],
       [0.38535013, 0.        , 0.        , 1.        ],
       [0.15253554, 0.        , 0.20572152, 0.14842758],
       [0.        , 0.79095945, 1.        , 0.47048052],
       [0.74472463, 0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        ],
       [0.66257794, 0.        , 0.3273876 , 1.        ],
       [0.        , 0.6726211 , 0.        , 0.        ],
       [1.        , 0.59218998, 0.7152595 , 0.        ],
       [0.        , 0.        , 0.        , 0.89900486],
       [0.60076436, 0.        , 0.        , 0.        ],
       [0.37954077, 0.06948574, 0.        , 0.        ],
       [1.        , 1.        , 0.20964893, 0.51078281],
       [0.30468845, 0.24618904, 0.        , 0.        ],
       [0.        , 0.        , 0.        , 1.        ],
       [0.        , 1.        , 0.        , 0.        ],
       [0.        , 0.2975272 , 0.67369196, 0.49834995],
       [0.        , 0.        , 0.        , 0.9602602 ],
       [0.        , 0.83345821, 0.95674608, 0.        ],
       [0.        , 0.91835124, 1.        , 0.08700828],
       [0.95129482, 0.        , 0.61077175, 1.        ],
       [0.        , 0.        , 0.10007548, 0.        ],
       [1.        , 0.81663725, 0.        , 1.        ],
       [0.        , 0.        , 0.        , 0.        ],
       [0.62977255, 0.05058136, 0.        , 1.        ],
       [0.88355105, 0.        , 0.        , 0.33057692],
       [0.0446955 , 0.        , 0.        , 0.03429369],
       [0.        , 0.        , 0.        , 0.20072091],
       [1.        , 0.51805691, 1.        , 0.        ],
       [0.        , 0.90222324, 0.74956746, 0.        ],
       [0.50763069, 0.        , 0.        , 0.        ],
       [0.37816333, 0.        , 0.        , 0.46558826],
       [0.        , 0.        , 0.21550081, 1.        ],
       [1.        , 0.20598883, 0.        , 0.        ],
       [0.        , 1.        , 0.        , 0.        ],
       [0.        , 0.        , 0.91165196, 0.        ],
       [0.        , 0.4972496 , 0.        , 1.        ],
       [0.        , 0.61668836, 1.        , 0.1465443 ]], dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$clip(0, 1)
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).clip(0, 1)

ptp

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).ptp()
Array(4.91195357, dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$ptp()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).ptp()

sort

Code
m.dist.normal(0,1, name = 'a', shape=(100,4), sample = True, to_jax=False).sort()
SampledData([[-8.70570715e-01, -7.99939428e-01, -7.96401628e-01,
         5.38358917e-01],
       [-3.85017269e-01,  7.12501072e-01,  7.23623005e-01,
         7.33712314e-01],
       [-1.79172025e-01, -9.15387128e-02,  2.66117693e-01,
         7.55837207e-01],
       [-6.81547059e-01, -3.17786878e-01, -1.22623290e-01,
         3.64822927e-01],
       [-1.40270557e+00,  6.42749844e-01,  8.52882475e-01,
         1.43345655e+00],
       [ 4.21624722e-01,  4.56246102e-01,  5.81319654e-01,
         8.12779642e-01],
       [-1.07148564e+00,  3.17882122e-01,  9.48171202e-01,
         1.65344959e+00],
       [-2.95131520e+00, -1.68622715e+00, -2.80534715e-01,
         4.49925265e-01],
       [-6.99927160e-01, -2.72232660e-01,  5.08318520e-01,
         1.56504880e+00],
       [-8.50019082e-01, -2.07049974e-03,  1.25159982e-01,
         4.55071206e-01],
       [-1.32968935e+00, -1.31540124e+00, -8.62818824e-01,
         7.33209121e-01],
       [-1.25328736e+00, -1.23777284e+00,  2.01356921e-01,
         6.00040168e-01],
       [-1.38885003e+00, -8.54234278e-01, -6.90829698e-01,
        -5.25210496e-02],
       [-7.97706591e-01,  1.44551334e-01,  4.94965165e-01,
         7.62430346e-01],
       [-1.58398952e+00, -7.66066229e-01, -5.32754089e-01,
         5.28265108e-01],
       [-8.30124527e-01, -1.01454235e-01,  6.89051488e-02,
         7.29468760e-01],
       [-4.06868077e-01, -2.81422617e-01, -2.40241818e-01,
        -1.26452188e-01],
       [-1.23859354e+00, -7.63297231e-01,  1.22042413e-01,
         6.56946299e-01],
       [-1.02426992e+00, -8.81441246e-02,  1.44156182e-02,
         3.22913521e+00],
       [-9.92595431e-01, -9.48938320e-01,  4.70766970e-01,
         1.18869876e+00],
       [-1.08333325e+00,  6.26514057e-01,  9.17964071e-01,
         1.94055459e+00],
       [ 2.51650821e-02,  3.08599873e-01,  5.43280602e-01,
         6.42556158e-01],
       [ 2.73616051e-02,  6.73672873e-01,  1.95572442e+00,
         2.50899644e+00],
       [-6.97069034e-01,  1.84127210e-01,  4.33986431e-01,
         1.02774884e+00],
       [-5.36811122e-01, -2.54705034e-01,  4.30598085e-01,
         4.44059352e-01],
       [-1.21253656e+00, -8.81290308e-01,  3.31622995e-01,
         1.16690924e+00],
       [ 3.05400701e-01,  6.12918482e-01,  9.48756684e-01,
         1.71469910e+00],
       [-1.00400110e+00, -4.26116831e-01, -2.98879502e-01,
         7.66211437e-01],
       [-1.57856482e+00, -7.96373764e-01, -7.85713842e-01,
        -2.79734850e-01],
       [-1.23572210e+00, -4.81164980e-01, -7.35408561e-02,
         2.47916593e-01],
       [-9.10140803e-02,  2.13068398e-02,  2.09892456e-01,
         7.57517943e-01],
       [-6.57676163e-01, -6.57373810e-01,  6.44846492e-03,
         6.90417826e-01],
       [-8.61693877e-01, -5.63352368e-01,  6.53064044e-01,
         8.90875398e-01],
       [-1.04979491e+00, -7.28296891e-01, -2.93125179e-01,
         1.62482920e+00],
       [-2.14595051e-01, -1.21830770e-02,  4.88092199e-01,
         5.16276973e-01],
       [-6.51909626e-01, -1.00483885e-03,  3.70103751e-02,
         2.10743938e+00],
       [-1.11637958e+00, -8.26095116e-01,  6.23323202e-02,
         4.78589694e-01],
       [-6.61436257e-01, -1.21151936e-01, -1.09866739e-01,
         6.68358854e-01],
       [-1.16389941e+00, -2.51263079e-01,  1.93393085e-01,
         2.79524263e-01],
       [-1.62051820e+00,  5.22709515e-01,  6.07794113e-01,
         1.20194253e+00],
       [-1.25332579e+00,  5.55940855e-01,  5.67167057e-01,
         7.26418166e-01],
       [-1.25338137e+00, -1.02951003e+00, -8.42343341e-01,
        -7.98850500e-01],
       [-8.77345131e-01,  2.71102030e-01,  5.77448157e-01,
         6.48063568e-01],
       [-1.97797639e-01,  2.39218924e-01,  3.66032433e-01,
         2.07498960e+00],
       [-8.45730370e-01,  7.94681959e-01,  8.88015448e-01,
         9.86588612e-01],
       [-1.07116792e+00, -3.06050318e-01,  2.06451646e-01,
         2.83074075e-01],
       [-4.48227730e-01,  3.78148158e-01,  8.95212270e-01,
         1.41427042e+00],
       [-2.10042298e+00, -1.84089013e-01,  8.66953497e-02,
         7.71508362e-01],
       [-1.13346630e+00, -1.08893508e+00, -6.10681160e-01,
         1.39528148e+00],
       [-1.72452925e+00, -5.39193687e-01,  5.84569386e-01,
         1.14727828e+00],
       [-1.40054946e+00, -2.58543772e-01,  6.38232589e-01,
         9.97707533e-01],
       [-1.13830707e+00,  2.73300473e-01,  8.54510818e-01,
         1.06158003e+00],
       [-1.50396165e+00, -8.31542340e-01, -3.74446006e-01,
         4.51332370e-01],
       [-1.47383683e+00,  1.45315555e-01,  1.81508686e-01,
         1.18836002e+00],
       [-1.95473522e+00, -3.35160005e-01,  8.27046991e-01,
         1.56537073e+00],
       [-1.19469915e+00, -1.76400267e-02,  8.60660501e-02,
         5.28789182e-01],
       [-1.40255824e+00, -2.70180088e-01,  1.24195965e-01,
         1.45922995e+00],
       [-8.94312465e-01, -3.40051885e-01, -2.20951800e-04,
         1.19002100e+00],
       [-8.49411686e-01, -7.61083596e-01, -4.46082702e-01,
         2.04777817e+00],
       [-7.35416500e-01, -6.02008175e-01,  1.00681591e-01,
         2.59998638e-01],
       [-7.97733918e-01, -4.43081596e-01, -6.80830544e-02,
         1.48663601e+00],
       [-1.20400756e+00, -3.08094817e-01, -1.00217401e-01,
         3.15716764e-01],
       [-7.85148823e-01, -5.82657342e-01, -4.03132428e-01,
        -3.30527575e-01],
       [-8.95302467e-01, -3.84364960e-01,  4.23462529e-02,
         8.13418785e-01],
       [-8.59910771e-01, -8.59610713e-01, -6.43902083e-01,
         6.99354144e-01],
       [-2.85472083e-01, -1.07027308e-01, -5.00827482e-02,
         3.13546712e-01],
       [-1.83262306e-01,  7.00375685e-02,  4.24364572e-01,
         8.96360354e-01],
       [-7.70222208e-01, -6.59442789e-01,  1.08324736e+00,
         1.53456066e+00],
       [-6.34734150e-01,  6.35940562e-01,  7.68102806e-01,
         1.70367713e+00],
       [-4.26816633e-01,  2.70538288e-01,  5.36502179e-01,
         8.17830843e-01],
       [-2.32930712e+00, -1.40817401e+00, -1.00837763e+00,
        -3.17668026e-01],
       [-1.71303685e+00, -7.89088482e-01,  1.72122744e-01,
         8.70969453e-01],
       [-1.53931765e+00, -1.43582223e+00,  5.65059715e-01,
         7.23738745e-01],
       [-1.87433155e+00, -1.22683719e+00, -3.17532907e-01,
         8.96048179e-02],
       [-1.24599479e+00, -8.13650189e-01, -2.86509586e-02,
         2.36317748e+00],
       [-1.45828650e+00, -1.30898152e+00, -6.13953622e-01,
        -2.09651379e-01],
       [-1.03034681e+00, -6.57689819e-01, -1.40457511e-01,
         1.72189456e+00],
       [-4.59536300e-01, -1.64525281e-03,  1.80063937e+00,
         2.40387918e+00],
       [-1.28588570e+00, -3.13243362e-01,  1.54684048e+00,
         2.14970525e+00],
       [ 1.03052985e-01,  3.41535610e-01,  1.26904045e+00,
         1.33072320e+00],
       [-1.07159470e+00, -6.38313803e-01, -7.42844887e-02,
        -6.43982231e-02],
       [-1.72138535e+00,  1.32226522e-01,  7.27206777e-01,
         1.48716296e+00],
       [-1.41143108e+00, -1.12280419e-01,  1.95103525e-02,
         2.09281729e+00],
       [-1.02061846e+00, -8.36941588e-01, -3.34516765e-01,
         1.06221866e+00],
       [-6.01312795e-01, -5.62698106e-01, -3.02514804e-01,
        -7.72343761e-02],
       [-2.24343026e+00, -8.69509460e-01, -3.03383397e-01,
         9.67266512e-01],
       [-1.23252444e+00, -2.74832369e-01,  1.40981370e-01,
         4.00283478e-01],
       [-1.40458834e+00, -1.67151594e-01,  4.25752819e-01,
         4.51681433e-01],
       [-3.08034621e-01,  3.95111862e-02,  6.15799986e-01,
         6.44248836e-01],
       [-1.57215802e+00, -8.22898626e-01, -6.15512589e-01,
         8.30398314e-02],
       [-3.99185100e-01, -3.41715372e-01,  6.28666078e-01,
         1.26044121e+00],
       [-1.25058615e+00, -8.07440759e-01, -4.35651573e-01,
        -9.67859513e-02],
       [-1.71578380e+00, -5.39425016e-01,  7.35333331e-01,
         1.55265690e+00],
       [-1.32428211e+00, -1.77271371e-01,  6.44190008e-01,
         1.66407006e+00],
       [-1.27924657e+00,  5.23070283e-02,  2.56971334e-01,
         1.23498498e+00],
       [-2.65290225e+00, -4.45728521e-01, -1.31214293e-01,
         9.14743606e-02],
       [-1.34455240e+00,  1.74654336e-01,  4.14298852e-01,
         2.13355762e+00],
       [-9.86537317e-01, -7.93892378e-01, -4.50655853e-01,
         8.81154340e-01],
       [-2.05363690e+00,  7.75757889e-02,  3.02729442e-01,
         4.87487506e-01],
       [-1.63922414e+00, -9.19840926e-01, -7.58275081e-01,
        -1.19085853e-01]], dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L), sample = TRUE, to_jax=FALSE)$sort()
m.dist.normal(0,1, name = "a", shape = (100, 4), sample = true, to_jax=false).sort()

.at[]

Since the sampled object wraps a JAX array, you can use JAX’s .at[] syntax for in-place style updates (which return a new object):

Code
s = m.dist.normal(0,1, name = 'a', shape=(100,4, 5), sample = True, to_jax=False)
s_new = s.at[0, 0, 0].set(0.0)
s <- m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L, 5L), sample = TRUE, to_jax=FALSE)
s_new <- s$at[0L, 0L, 0L]$set(0.0)
s = m.dist.normal(0,1, name = "a", shape = (100, 4, 5), sample = true, to_jax=false)
s_new = s.at[0, 0, 0].set(0.0)

reshape

Code
m.dist.normal(0,1, name = 'a', shape=(100,4, 5), sample = True, to_jax=False).reshape((100, 20))
SampledData([[ 1.69652085e+00, -1.75490518e+00,  1.02760596e+00, ...,
        -6.91440287e-01,  6.42939990e-01,  1.66586156e-01],
       [-2.89647993e-01, -6.48828596e-02,  1.16589165e+00, ...,
         1.25789106e+00,  1.38468665e-02, -8.71832881e-02],
       [-3.37077187e-01, -2.68259436e+00, -3.12020784e-01, ...,
         1.78419701e+00, -7.40856921e-01, -5.11152133e-01],
       ...,
       [-1.29811868e+00, -1.49271609e+00,  3.78565296e-01, ...,
         4.54287922e-01, -3.10837017e-01,  1.16516093e+00],
       [-5.67633473e-01,  9.70290519e-01, -1.19223595e+00, ...,
        -1.59519601e+00,  7.27676520e-01, -8.52524425e-04],
       [ 1.54203121e+00,  6.19266161e-02,  1.94916240e+00, ...,
        -9.25026000e-01,  1.02783792e+00,  3.39193345e-01]],      dtype=float64)
m$dist$normal(0,1, name = 'a', shape = reticulate::tuple(100L, 4L, 5L), sample = TRUE, to_jax=FALSE)$reshape(reticulate::tuple(100L, 20L))
m.dist.normal(0,1, name = "a", shape = (100, 4, 5), sample = true, to_jax=false).reshape((100, 20))

And many other standard NumPy/JAX array methods like .flatten(), .squeeze(), .astype(), etc., are also available directly on the sampled object.

Notes

Note
  • density, surface_3d, and ppc_plot are Plotly-only — passing interactive=False has no effect on them.
  • The dimensional requirement is enforced: e.g. corr_heatmap, boxplot, violinplot, pairplot, traceplot, scatter3d, and timeseries raise a ValueError if the array is not the expected shape.
  • Plotting methods live on the SampledData wrapper only. If you sampled with to_jax=True (or later called .to_jax()), convert back with SampledData(arr) to plot, or re-sample without to_jax.