utils.integral_validation module

Generic facilities to validate integrals

class Sampler(*args, **kwargs)[source]

Bases: better_abc.ABC

Sampling tool for integral validation that mimics the behavior of sample_survey/sample_refine from Integrators

get_history()[source]

Return stored training history from the sampler This abstract class has no training history and returns an empty history

Returns

empty dataframe

Return type

pandas.Dataframe

abstract sample(f, n_batch=10000, *args, **kwargs)[source]
Parameters
  • f (utils.integrands.Integrand) –

  • n_batch (int) –

Returns

  • tuple of torch.Tensor

  • x,px,fx (points, pdfs, function values)

compare_integral_result(result1, result2, sigma_cutoff=2, keep_history=False)[source]

Compute an integral in two different ways and compare

Parameters
Returns

Return type

utils.record.ComparisonRecord

compare_integrals(integrand1, sampler1, sampler2, integrand2=None, n_batch=10000, sigma_cutoff=2, keep_history=False)[source]

Compute an integral in two different ways and compare

Parameters
  • integrand1 (callable) –

  • integrand2 (None callable) – if not None, use integrand1 with sampler1 and integrand2 with sampler2, else use integrand1 for both

  • sampler1 (Sampler) –

  • sampler2 (Sampler) –

  • n_batch (int) –

  • sigma_cutoff (float) –

  • keep_history (bool) –

Returns

Return type

utils.record.ComparisonRecord

evaluate_integral(integrand, sampler, n_batch=10000, keep_history=False)[source]

Evaluate an integral

Parameters
  • integrand (utils.integrands.KnownIntegrand) –

  • sampler (Sampler) –

  • n_batch (int) –

  • keep_history (bool) –

Returns

Return type

utils.record.EvaluationRecord

evaluate_integral_stratified(integrand, sampler, n_batch=10000, keep_history=False)[source]

Evaluate an integral with a stratified sampling sampler

Parameters
  • integrand (utils.integrands.KnownIntegrand) –

  • sampler (Sampler) –

  • n_batch (int) –

  • keep_history (bool) –

Returns

Return type

utils.record.EvaluationRecord

validate_integral(integrand, sampler, n_batch=10000, sigma_cutoff=2, keep_history=False)[source]

Compute the integral and check whether it matches the known value

Parameters
  • integrand (utils.integrands.KnownIntegrand) –

  • sampler (Sampler) –

  • n_batch (int) –

  • sigma_cutoff (float) –

  • keep_history (bool) –

Returns

Return type

utils.record.EvaluationRecord