src.functions_sampler module
- class src.functions_sampler.LatinHypercube(bounds: list[tuple[float, float]], precision: float | None = None, seed: int | None = None, constraint_fns: list[Callable[[ndarray], bool]] | None = None, logger: Logger | None = None, silent: bool = True, log_dev: bool = False)[source]
Bases:
objectOptimized Latin Hypercube Sampling with constraints and precision handling.
- bounds
List of (min, max) tuples for each parameter.
- Type:
List[Tuple[float, float]]
- precision
Decimal precision (e.g., 0.1 for 1-decimal-place precision).
- Type:
float
- seed
Random seed for reproducibility.
- Type:
Optional[int]
- constraint_fns
List of constraint functions. Each function takes a sample as input and returns True if the sample satisfies the constraint.
- Type:
Optional[List[Callable[[np.ndarray], bool]]]
- sampler
Instance of the Latin Hypercube sampler from scipy.stats.qmc.
- Type:
qmc.LatinHypercube
- generate_samples(n_samples
int) -> np.ndarray: Generate Latin Hypercube Samples within specified bounds, ensuring the samples have the desired precision and satisfy constraints.
- extend_samples(existing_samples
np.ndarray, n_samples: int, only_new: bool = False) -> np.ndarray: Extend the existing samples with new, unique samples.
- extend_samples(existing_samples: ndarray, n_samples: int, only_new: bool = False) ndarray[source]
Extend the existing samples with new, unique samples.
- Parameters:
existing_samples (np.ndarray) – Existing samples to extend.
n_samples (int) – Number of new samples to generate.
only_new (bool) – If True, return only the new samples.
- Returns:
Array of unique, constrained, and precision-rounded samples.
- Return type:
np.ndarray
- generate_samples(n_samples: int, samples: ndarray | None = None, stop_on_fail: bool = False) ndarray[source]
Generate constrained, unique samples using Latin Hypercube Sampling.
- Parameters:
n_samples (int) – Number of samples to generate.
samples (np.array) – Existing samples to extend.
stop_on_fail (bool) – If True, raise an error if the desired number of samples cannot be generated.
- Returns:
Array of unique, constrained, and precision-rounded samples.
- Return type:
np.ndarray
- class src.functions_sampler.SOBOL_sampler(n_dim: int, bounds: list[tuple[float, float]], precision: float | None = None, seed: int | None = None)[source]
Bases:
objectSobol Sampler for generating low-discrepancy samples within specified bounds.
- n_dim
Number of dimensions for the samples.
- Type:
int
- bounds
List of (min, max) tuples for each parameter.
- Type:
List[Tuple[float, float]]
- precision
Decimal precision (e.g., 0.1 for 1-decimal-place precision).
- Type:
float
- seed
Random seed for reproducibility.
- Type:
Optional[int]
- generate_samples(n_samples
int) -> np.ndarray: Generate low-discrepancy samples within specified bounds and precision.
- class src.functions_sampler.Uniform_sampler(n_dim: int, bounds: list[tuple[float, float]], precision: float | None = None, seed: int | None = None)[source]
Bases:
objectUniform Sampler for generating random samples within specified bounds.
- n_dim
Number of dimensions for the samples.
- Type:
int
- bounds
List of (min, max) tuples for each parameter.
- Type:
List[Tuple[float, float]]
- precision
Decimal precision (e.g., 0.1 for 1-decimal-place precision).
- Type:
float
- seed
Random seed for reproducibility.
- Type:
Optional[int]
- generate_samples(n_samples
int) -> np.ndarray: Generate uniformly distributed samples within specified bounds and precision.