1111__copyright__ = "Copyright (c) 2025 PySATL project"
1212__license__ = "SPDX-License-Identifier: MIT"
1313
14- from typing import TYPE_CHECKING , Protocol
14+ from typing import TYPE_CHECKING , Protocol , cast
1515
1616import numpy as np
1717
1818from pysatl_core .distributions .registry import characteristic_registry
19- from pysatl_core .distributions . sampling import ArraySample
19+ from pysatl_core .types import CharacteristicName , NumericArray
2020
2121if TYPE_CHECKING :
2222 from typing import Any
2323
2424 from pysatl_core .distributions .computation import AnalyticalComputation , FittedComputationMethod
2525 from pysatl_core .distributions .distribution import Distribution
26- from pysatl_core .distributions .sampling import Sample
2726 from pysatl_core .types import GenericCharacteristicName
2827
2928type Method [In , Out ] = AnalyticalComputation [In , Out ] | FittedComputationMethod [In , Out ]
@@ -186,25 +185,27 @@ def query_method(
186185class SamplingStrategy (Protocol ):
187186 """Protocol for strategies that generate samples from distributions."""
188187
189- def sample (self , n : int , distr : Distribution , ** options : Any ) -> Sample : ...
188+ def sample (self , n : int , distr : Distribution , ** options : Any ) -> NumericArray : ...
190189
191190
192191class DefaultSamplingUnivariateStrategy (SamplingStrategy ):
193192 """
194- Default univariate sampler using inverse transform sampling.
193+ Default univariate sampler based on inverse transform sampling.
195194
196195 This strategy generates samples by applying the PPF (inverse CDF)
197- to uniform random variables.
196+ to uniformly distributed random variables.
198197
199198 Notes
200199 -----
201200 - Requires the distribution to provide a PPF computation method.
202- - Returns samples as a 2D array of shape (n, 1).
201+ - Assumes that the PPF follows NumPy semantics (vectorized evaluation).
202+ - Graph-derived PPFs (scalar-only) are currently not supported.
203+ - Returns a NumPy array containing the generated samples.
203204 """
204205
205- def sample (self , n : int , distr : Distribution , ** options : Any ) -> ArraySample :
206+ def sample (self , n : int , distr : Distribution , ** options : Any ) -> NumericArray :
206207 """
207- Generate n samples from the distribution.
208+ Generate samples from the distribution.
208209
209210 Parameters
210211 ----------
@@ -213,15 +214,19 @@ def sample(self, n: int, distr: Distribution, **options: Any) -> ArraySample:
213214 distr : Distribution
214215 Distribution to sample from.
215216 **options : Any
216- Additional options passed to the PPF computation.
217+ Additional options forwarded to the PPF computation.
217218
218219 Returns
219220 -------
220- ArraySample
221- Samples as a 2D array of shape (n, 1).
221+ NumericArray
222+ NumPy array containing ``n`` generated samples.
223+ The exact array shape depends on the distribution and sampling strategy.
222224 """
223- ppf = distr .query_method ("ppf" , ** options )
225+ ppf = distr .query_method (CharacteristicName . PPF , ** options )
224226 rng = np .random .default_rng ()
225227 U = rng .random (n )
226- vals = np .array ([ppf (Ui ) for Ui in U ], dtype = np .float64 ).reshape (n , 1 )
227- return ArraySample (vals )
228+ # TODO: Now it will be based on the fact that the characteristic
229+ # has NumPy semantics (It is much more faster), that is,
230+ # it will not work with the graph computed characteristics currently.
231+ samples = ppf (U )
232+ return cast (NumericArray , samples )
0 commit comments