sheap.MasterSampler.Samplers.MonteCarloSampler module
Monte Carlo Sampler
This module implements the MonteCarloSampler, a simple
posterior approximation for spectral fits based on randomized parameter
initialization and local re-optimization.
Main Features
Generates random draws of parameter vectors within their constraints.
Converts parameters to raw space and re-optimizes them with
Minimizer.Handles tied/fixed parameters through
build_Parameters()and dependency flattening utilities.Reconstructs physical parameters from optimized raw vectors.
Computes physical quantities (fluxes, FWHM, luminosities, etc.) for each draw using
SheaProducts.
Public API
MonteCarloSamplerMonteCarloSampler.sample_params()— run the Monte Carlo sampler and return posterior dictionaries.MonteCarloSampler.make_minimizer()— construct aMinimizerconfigured with penalties/weights.MonteCarloSampler._build_tied()— convert tied-parameter specifications into dependency strings.
Notes
This method approximates the posterior distribution by repeatedly optimizing from random starts (sometimes called a “poor man’s MCMC”).
Actual uncertainty propagation is performed by analyzing the distribution of optimized solutions.
Dependencies are flattened so that all tied parameters ultimately reference free parameters only.
- class MonteCarloSampler(estimator)[source]
Bases:
objectMontecarlo sampler still under developmen.
- Parameters:
estimator (MasterSampler)
- sample_params(num_samples=100, key_seed=0, summarize=True, **kwargs)[source]
- Parameters:
num_samples (int)
key_seed (int)
- Return type:
jax.numpy.ndarray
- sample_params_st(num_samples=100, key_seed=0, summarize=True, **kwargs)[source]
stable start from the best result.
- Parameters:
num_samples (int)
key_seed (int)
- Return type:
jax.numpy.ndarray