uvex_transients.phase_space.sampling.base#

The core of the sampling infrastructure: the sampler contract, its products and the stopping rule.

This module knows nothing about surveys. The samplers that simulate one are in core and breakout.

Products: the quantities of a map, each of which owns how it is made.

A fitted map is of one thing, the success fraction \(f\) over the space. Everything else a figure or a table shows is made from it and from the point: the fraction times a volume-time is an expected yield, the fraction times a rate on top of that is an expected count, and a redshift limit does not involve the fraction at all. A Product is one of those quantities. It is a callable that takes the points and the map”s Estimate of the success fraction there and returns the columns it creates, so it is free to combine them however the quantity needs. Nothing else has to know what a volume-time or a rate is.

A sampler supplies its own products (products), which are built around whatever machinery of the sampler they need. Scale and Weighted cover the two common cases, a quantity of the point alone and the success fraction times one.

The sampler: how many detections in n tries at a point of the space.

A phase-space map asks one question of the world, again and again: at this point x, of n independent tries, how many succeed? A Sampler answers it, and nothing else. It does not decide how many tries to make (that is the StoppingRule) and it does not know about the Gaussian process that models the answers (that is the map). What it does know is the physics of one kind of experiment:

  • Sampler.space is the Space the experiment is over, with its axes and their default ranges;

  • Sampler.draw makes n tries at a point and returns the number of successes;

  • Sampler.products are the quantities of its map beyond the success fraction (a redshift limit, a recovered volume-time), each a Product that owns how it is made.

Every sampler has a kind, a name under which it is registered, so that a file can record which sampler made it and get_sampler() can find the class again without importing it by path. A subclass registers itself by naming its kind in the class statement,

class MySampler(Sampler, kind="my_sampler"): ...

and an abstract intermediate class leaves it out.

Everything beyond those four members is an optional hook with a default, so that the code that consumes a sampler (the experiment, the stages that write and draw a map, the CLI) never has to ask what kind it is: Sampler.rate_products and Sampler.table_meta extend the table of the map, Sampler.describe titles its figure, Sampler.draw_map draws it and Sampler.annotate_map decorates it, Sampler.HAS_OVERLAY and Sampler.measure_overlay supply a population to shade on it, and Sampler.from_run_config builds the sampler from a run-config. A sampler that has something to say overrides the hook; one that does not inherits an answer that says nothing. The default figure is of a plane, so a map over more than two axes is not drawn.

The stopping rule: how many tries a point gets.

A sampler makes however many tries it is asked for. How many to ask for is a question of statistics, not of physics: a point where the success fraction is high needs few tries to pin it down, and one where it is small needs many, so a point is sampled in chunks until it has enough successes or has used its budget. StoppingRule is that rule, and it is a separate object because two parties need it: the campaign applies it, and the map”s acquisition predicts from it the noise of a point it has not measured yet.

Attributes

LOWER

a product that carries one names them <name>_lo and <name>_hi.

Functions

available_samplers()

Return the kinds of every registered sampler.

get_sampler(kind)

Return the registered sampler class of a kind.

Classes

Estimate(p, p_lo, p_hi)

The map's estimate of the success fraction at points: a value with an interval.

Outcome(k, n, extras, ~typing.Any] =)

The result of sampling one point: k successes of n tries, and whatever else was worth recording.

Product(name[, label, unit, draw])

A quantity of the map, and how it is made from the points and the estimate of the success fraction.

Sampler()

Answer "how many detections in n tries at a point?" for one kind of experiment.

Scale(name, function[, label, unit, draw])

A quantity of the point alone, which does not involve the success fraction.

StoppingRule(chunk_size, k_target, n_max)

Sample a point in chunks of tries until it has k_target successes or has used n_max tries.

Weighted(name, weight[, label, unit, draw])

The success fraction times a quantity of the point, with its interval.