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

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: object

Montecarlo 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

sample_params_experimental(num_samples=100, key_seed=0, summarize=True, return_only_draws=False, frac_box_sigma=0.5, k_sigma=0.5)[source]
Parameters:
  • num_samples (int)

  • key_seed (int)

Return type:

jax.numpy.ndarray

make_minimizer(model, non_optimize_in_axis, num_steps, learning_rate, method, penalty_weight, curvature_weight, smoothness_weight, max_weight, penalty_function=None, weighted=True, **kwargs)[source]