distribution
Distribution Interface
This module defines the public Distribution protocol that serves as the abstract interface for all probability distributions in the system.
- class pysatl_core.distributions.distribution.Distribution(distribution_type, analytical_computations, support=None, sampling_strategy=None, computation_strategy=None)[source]
Bases:
ABCProtocol defining the interface for probability distributions.
This protocol is the central abstraction used throughout the system. Concrete distribution implementations must provide the properties and methods defined here.
- Parameters:
distribution_type (DistributionType)
analytical_computations (Mapping[GenericCharacteristicName, AnalyticalComputation[Any, Any] | Mapping[LabelName, AnalyticalComputation[Any, Any]]])
support (Support | None)
sampling_strategy (SamplingStrategy | None)
computation_strategy (ComputationStrategy | None)
- distribution_type
Type information about the distribution (kind, dimension, etc.).
- Type:
DistributionType
- analytical_computations
Distribution-provided characteristic methods. For non-transformed distributions every method in this mapping is fully analytical, so this mapping matches the set of loops with
is_analytical=Truein the graph view.- Type:
Mapping
- sampling_strategy
Strategy for generating random samples.
- Type:
SamplingStrategy
- computation_strategy
Strategy for computing characteristics and conversions.
- Type:
ComputationStrategy
Notes
Array semantics for analytical characteristics
Analytical characteristic methods (e.g.
pdf,cdf) should be implemented to accept and return NumPy arrays directly (array semantics). This is the recommended approach because it enables efficient vectorised evaluation.If a method accepts only scalar inputs, the computation infrastructure will wrap it automatically via
numpy.vectorize, but this incurs a per-element Python call overhead and is significantly slower for large inputs.- __init__(distribution_type, analytical_computations, support=None, sampling_strategy=None, computation_strategy=None)[source]
Initialize common distribution state.
- Parameters:
distribution_type (
DistributionType) – Type information about the distribution (kind, dimension, etc.).analytical_computations (
Mapping) –Distribution-provided characteristic methods. For non-transformed distributions these methods are fully analytical.
Note
Each characteristic callable should accept and return NumPy arrays (array semantics). Scalar-only callables are wrapped automatically via
numpy.vectorize, but at a significant per-element overhead cost.support (
SupportorNone, defaultNone) – Support of the distribution.sampling_strategy (
SamplingStrategyorNone, defaultNone) – Sampling strategy instance. If omitted, univariate default is used.computation_strategy (
ComputationStrategyorNone, defaultNone) – Computation strategy instance. If omitted, default strategy is used.
- Return type:
None
- property distribution_type: pysatl_core.types.DistributionType
Return type metadata of the distribution (kind, dimension, etc.).
- property analytical_computations: Mapping[GenericCharacteristicName, Mapping[LabelName, AnalyticalComputation[Any, Any]]]
Return distribution-provided characteristic methods.
For non-transformed distributions this mapping coincides with graph loops marked as
is_analytical=True.
- loop_is_analytical(characteristic_name, label_name)[source]
Tell whether a self-loop method is fully analytical in the graph.
- Parameters:
characteristic_name (
GenericCharacteristicName) – Characteristic name of the self-loop.label_name (
LabelName) – Label of the analytical computation variant.
- Returns:
Truewhen every required predecessor in the transformation chain is analytical.- Return type:
Notes
Presence in
analytical_computationsmeans that a characteristic has at least one analytical ancestor in its derivation chain. For non-transformed distributions these notions coincide, therefore this method always returnsTrue.
- property sampling_strategy: pysatl_core.distributions.strategies.SamplingStrategy
Return the currently attached sampling strategy.
- property computation_strategy: pysatl_core.distributions.strategies.ComputationStrategy
Return the currently attached computation strategy.
- with_sampling_strategy(sampling_strategy)[source]
Return a copy of this distribution with an updated sampling strategy.
- Return type:
Self
- Parameters:
sampling_strategy (SamplingStrategy | None)
- with_computation_strategy(computation_strategy)[source]
Return a copy of this distribution with an updated computation strategy.
- Return type:
Self
- Parameters:
computation_strategy (ComputationStrategy | None)
- with_strategies(*, sampling_strategy=<object object>, computation_strategy=<object object>)[source]
Return a copy of this distribution with updated strategies.
- Return type:
Self
- Parameters:
sampling_strategy (SamplingStrategy | None | object)
computation_strategy (ComputationStrategy | None | object)
- query_method(characteristic_name, options=None, *, characteristic_options=None, computation_defaults=None)[source]
Query a computation method for a specific characteristic.
- Parameters:
characteristic_name (
str) – Name of the characteristic to compute (e.g., “pdf”, “cdf”).options (
StepOptions | None, defaultNone) – Per-step options built viaComputationPlan.with_options(). WhenNone, every edge uses its declared defaults.characteristic_options (
Mapping[str,Any] | None, defaultNone) – Shared characteristic options broadcast to every step that declares a matchingCharacteristicOption. These are intrinsic to the characteristic (e.g.eps,x0for PPF) and affect the meaning of the result and the cache key.computation_defaults (
Mapping[str,Any] | None, defaultNone) – Per-call computation option defaults. Override the strategy-level defaults and hardcoded descriptor defaults, but are overridden by per-step values inoptions. Do not affect the cache key.
- Returns:
Callable method that computes the characteristic.
- Return type:
Method
- explain_computation_path(characteristic_name)[source]
Describe how the attached computation strategy will compute a characteristic.
Returns an
ComputationPlanlisting every step (loop or conversion edge) and the option descriptors that will be consulted at each step. The plan is also pinned by the strategy, so a subsequentquery_method()/calculate_characteristic()call for the samecharacteristic_namefollows exactly the same edges – which is useful for introspection and protects against non-deterministic strategy choices.- Parameters:
characteristic_name (
str) – Name of the characteristic to introspect.- Returns:
The plan describing the resolution path.
- Return type:
ComputationPlan
- calculate_characteristic(characteristic_name, value, options=None, *, characteristic_options=None, computation_defaults=None)[source]
Calculate a characteristic at the given value.
- Parameters:
characteristic_name (
str) – Name of the characteristic to compute.value (
Any) – Point(s) at which to evaluate the characteristic.options (
StepOptions | None, defaultNone) – Per-step options built viaComputationPlan.with_options().characteristic_options (
Mapping[str,Any] | None, defaultNone) – Shared characteristic options broadcast to every step that declares a matchingCharacteristicOption.computation_defaults (
Mapping[str,Any] | None, defaultNone) – Per-call computation option defaults.
- Returns:
Value of the characteristic at the given point(s).
- Return type:
Any
- sample(n, **options)[source]
Generate random samples from the distribution.
- Parameters:
n (
int) – Number of samples to generate.**options (
Any) – Additional sampling options forwarded to the underlying sampling strategy.
- Returns:
NumPy array containing
ngenerated samples. The exact array shape depends on the distribution and the sampling strategy.- Return type:
NumericArray