How this skill is triggered — by the user, by Claude, or both
Slash command
/bayesflow-skills:bayesflow-simulatorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
---
Simulator (variable-size data)Use when the data dimensions vary across batches (e.g., different numbers of
items/persons per batch in IRT). Subclass bayesflow.simulators.Simulator and
implement sample().
from bayesflow.simulators import Simulator
from bayesflow.utils.decorators import allow_batch_size
class _MySimulator(Simulator):
def __init__(self, n_obs: tuple[int, int], prior_spec):
self._n_obs_range = (n_obs[0], n_obs[1]) # (lo, hi)
self._sample_param = resolve_prior(prior_spec)
self._rng = np.random.default_rng()
@allow_batch_size
def sample(self, batch_shape, **kwargs) -> dict[str, np.ndarray]:
rng = self._rng
B = int(np.prod(batch_shape))
# Sizes drawn ONCE per batch, not per sample
N = int(rng.integers(self._n_obs_range[0], self._n_obs_range[1] + 1))
params = self._sample_param((B,), rng).astype(np.float32)
data = self._generate_data(params, N, rng).astype(np.float32)
return dict(
params=params,
data=data,
n_obs=np.full((B, 1), N, dtype=np.float32),
)
Key rules:
@allow_batch_size decorator is REQUIRED — it handles batch_shape normalizationclone_with_sizes() method for creating validation simulators with different rangesmake_simulator() (fixed-size data)Use when dimensions are constant or set by meta-parameters.
import bayesflow as bf
def prior(shape, rng):
return rng.normal(size=shape).astype(np.float32)
def likelihood(params, n_total, rng):
# params from prior, n_total from meta
data = rng.normal(loc=params, size=(*params.shape[:-1], n_total))
return data.astype(np.float32)
def meta(shape, rng):
n = rng.integers(50, 200, size=(*shape, 1)).astype(np.float32)
return n
simulator = bf.simulators.make_simulator(
prior_fn=prior,
likelihood_fn=likelihood,
meta_fn=meta,
)
(shape: tuple, rng: np.random.Generator) -> np.ndarrayrng(shape: tuple, rng: np.random.Generator) -> np.ndarrayrng: np.random.Generator — never use global np.randomself._rng = np.random.default_rng() in __init__np.random.default_rng(seed)inference_variables mappingsummary_variables mappinginference_conditions mappingnp.float32 — use .astype(np.float32)Group hyperparameters into frozen dataclasses for serialization:
@dataclass
class PriorConfig:
scale: float = 1.0
df: float = 5.0
Use PriorSpec = Prior | Callable for flexible prior definitions:
Prior("normal", loc=0, scale=1.0) # Named distribution
Prior("lognormal", loc=0, scale=0.3) # Lognormal
lambda shape, rng: rng.gamma(2, 1, shape) # Custom callable
Never use silent defaults for critical priors — force explicit specification to prevent train/validation prior mismatches.
@allow_batch_size decorator → batch_shape errorsnp.random.normal() instead of rng.normal() → non-reproduciblefloat64 instead of float32 → dtype mismatch in adapter/networknpx claudepluginhub matthiaskloft/claude-skills --plugin bayesflow-skillsProvides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.