Skip to content

Commit 1be0adf

Browse files
committed
feat: transformations base primitives
1 parent 1533dd2 commit 1be0adf

12 files changed

Lines changed: 1447 additions & 14 deletions

File tree

src/pysatl_core/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from .distributions import __all__ as _distr_all
1515
from .families import *
1616
from .families import __all__ as _family_all
17+
from .transformations import *
18+
from .transformations import __all__ as _transformations_all
1719
from .types import *
1820
from .types import __all__ as _types_all
1921

@@ -23,8 +25,10 @@
2325
*_distr_all,
2426
*_family_all,
2527
*_types_all,
28+
*_transformations_all,
2629
]
2730

2831
del _distr_all
2932
del _family_all
3033
del _types_all
34+
del _transformations_all

src/pysatl_core/distributions/distribution.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ def computation_strategy(self) -> ComputationStrategy: ...
7474
@property
7575
def support(self) -> Support | None: ...
7676

77+
def _new_computation_strategy(
78+
self, computation_strategy: ComputationStrategy | None | object = _KEEP
79+
) -> ComputationStrategy | None:
80+
return (
81+
self.computation_strategy
82+
if computation_strategy is _KEEP
83+
else cast(ComputationStrategy | None, computation_strategy)
84+
)
85+
86+
def _new_sampling_strategy(
87+
self, sampling_strategy: SamplingStrategy | None | object = _KEEP
88+
) -> SamplingStrategy | None:
89+
return (
90+
self.sampling_strategy
91+
if sampling_strategy is _KEEP
92+
else cast(SamplingStrategy | None, sampling_strategy)
93+
)
94+
7795
def _clone_with_strategies(
7896
self,
7997
*,

src/pysatl_core/families/distribution.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,13 @@ def _clone_with_strategies(
197197
computation_strategy: ComputationStrategy | None | object = _KEEP,
198198
) -> ParametricFamilyDistribution:
199199
"""Return a copy of this distribution with updated strategies."""
200-
new_sampling: SamplingStrategy | None = (
201-
self._sampling_strategy
202-
if sampling_strategy is _KEEP
203-
else cast(SamplingStrategy | None, sampling_strategy)
204-
)
205-
206-
new_computation: ComputationStrategy | None = (
207-
self._computation_strategy
208-
if computation_strategy is _KEEP
209-
else cast(ComputationStrategy | None, computation_strategy)
210-
)
211-
212200
return ParametricFamilyDistribution(
213201
family_name=self._family_name,
214202
distribution_type=self._distribution_type,
215203
parametrization=self._parametrization,
216204
support=self._support,
217-
sampling_strategy=new_sampling,
218-
computation_strategy=new_computation,
205+
sampling_strategy=self._new_sampling_strategy(sampling_strategy),
206+
computation_strategy=self._new_computation_strategy(computation_strategy),
219207
)
220208

221209
@property
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Transformations framework for derived probability distributions.
3+
4+
This package provides the base primitives for constructing distributions
5+
obtained from other distributions, together with approximation interfaces
6+
and concrete transformation implementations.
7+
"""
8+
9+
__author__ = "Leonid Elkin, Mikhail Mikhailov, Fedor Myznikov"
10+
__copyright__ = "Copyright (c) 2025 PySATL project"
11+
__license__ = "SPDX-License-Identifier: MIT"
12+
13+
from .approximations import *
14+
from .approximations import __all__ as _approximations_all
15+
from .distribution import *
16+
from .distribution import __all__ as _distribution_all
17+
from .operations import *
18+
from .operations import __all__ as _operations_all
19+
from .transformation_method import *
20+
from .transformation_method import __all__ as _methods_all
21+
22+
__all__ = [
23+
*_approximations_all,
24+
*_distribution_all,
25+
*_operations_all,
26+
*_methods_all,
27+
]
28+
29+
del _approximations_all
30+
31+
del _distribution_all
32+
33+
del _operations_all
34+
35+
del _methods_all
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Approximation utilities for transformed distributions.
3+
4+
This subpackage contains approximation interfaces and concrete
5+
approximators that can materialize analytical characteristics for
6+
complex transformation trees.
7+
"""
8+
9+
__author__ = "Leonid Elkin"
10+
__copyright__ = "Copyright (c) 2025 PySATL project"
11+
__license__ = "SPDX-License-Identifier: MIT"
12+
13+
from .approximation import *
14+
from .approximation import __all__ as _approximation_all
15+
from .chebyshev import *
16+
from .chebyshev import __all__ as _chebyshev_all
17+
18+
__all__ = [
19+
*_approximation_all,
20+
*_chebyshev_all,
21+
]
22+
23+
del _approximation_all
24+
25+
del _chebyshev_all
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Approximation interfaces for derived distributions.
3+
4+
This module intentionally keeps the approximation layer minimal.
5+
At this stage the public abstraction is a single protocol describing
6+
objects that can materialize an :class:`ApproximatedDistribution`
7+
from a :class:`DerivedDistribution`.
8+
"""
9+
10+
from __future__ import annotations
11+
12+
__author__ = "Leonid Elkin"
13+
__copyright__ = "Copyright (c) 2025 PySATL project"
14+
__license__ = "SPDX-License-Identifier: MIT"
15+
16+
from typing import TYPE_CHECKING, Any, Protocol
17+
18+
if TYPE_CHECKING:
19+
from pysatl_core.transformations.distribution import (
20+
ApproximatedDistribution,
21+
DerivedDistribution,
22+
)
23+
24+
25+
class DistributionApproximator(Protocol):
26+
"""
27+
Protocol for objects approximating a derived distribution.
28+
29+
Implementations may use interpolation, tabulation, polynomial
30+
approximation, or any other technique, as long as they return a new
31+
derived distribution with materialized analytical computations.
32+
"""
33+
34+
def approximate(
35+
self,
36+
distribution: DerivedDistribution,
37+
**options: Any,
38+
) -> ApproximatedDistribution:
39+
"""
40+
Build an approximated distribution.
41+
42+
Parameters
43+
----------
44+
distribution : DerivedDistribution
45+
Distribution to approximate.
46+
**options : Any
47+
Extra approximation options.
48+
49+
Returns
50+
-------
51+
ApproximatedDistribution
52+
Materialized approximation of the input distribution.
53+
"""
54+
...
55+
56+
57+
__all__ = [
58+
"DistributionApproximator",
59+
]

0 commit comments

Comments
 (0)