Sampling
SRToolkit.dataset.sampling
Sampling strategies for variable generation in symbolic regression benchmarks.
Sampler
Bases: ABC
Abstract base class for variable samplers.
Concrete subclasses must implement __call__,
to_dict, and
from_dict. The dictionary produced by
to_dict must include a "sampler_class"
key holding the fully-qualified class path (e.g.
"SRToolkit.dataset.sampling.UniformSampling"), so that
sampling_from_dict can reconstruct any
subclass — including user-defined ones — via importlib without a central registry.
__call__
abstractmethod
to_dict
abstractmethod
Serialize this sampler to a JSON-compatible dictionary.
The returned dict must include "sampler_class" set to the
fully-qualified class path of this sampler.
from_dict
abstractmethod
classmethod
Reconstruct a sampler from a dictionary produced by to_dict.
LogUniformSampling
LogUniformSampling(min_value: float, max_value: float, uses_positive: bool = True, uses_negative: bool = True)
Bases: Sampler
Log-uniform sampler with configurable sign constraints.
Samples from U(\log_{10}(\text{min}), \log_{10}(\text{max})) in log space,
optionally drawing from positive and/or negative ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_value
|
float
|
Lower bound of the log-uniform range (must be > 0). |
required |
max_value
|
float
|
Upper bound of the log-uniform range (must be > 0). |
required |
uses_positive
|
bool
|
If |
True
|
uses_negative
|
bool
|
If |
True
|
Source code in SRToolkit/dataset/sampling.py
to_dict
Serialize this sampler to a JSON-compatible dictionary.
Source code in SRToolkit/dataset/sampling.py
from_dict
classmethod
Deserialize a LogUniformSampling from a dictionary produced by to_dict.
Source code in SRToolkit/dataset/sampling.py
UniformSampling
UniformSampling(min_value: float, max_value: float, uses_positive: bool = True, uses_negative: bool = True)
Bases: Sampler
Linear uniform sampler with configurable sign constraints.
Samples fromU(\text{min}, \text{max}), optionally drawing from positive
and/or negative ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_value
|
float
|
Lower bound of the uniform range. |
required |
max_value
|
float
|
Upper bound of the uniform range. |
required |
uses_positive
|
bool
|
If |
True
|
uses_negative
|
bool
|
If |
True
|
Source code in SRToolkit/dataset/sampling.py
to_dict
Serialize this sampler to a JSON-compatible dictionary.
Source code in SRToolkit/dataset/sampling.py
from_dict
classmethod
Deserialize a UniformSampling from a dictionary produced by to_dict.
Source code in SRToolkit/dataset/sampling.py
IntegerUniformSampling
IntegerUniformSampling(min_value: int, max_value: int, uses_positive: bool = True, uses_negative: bool = True)
Bases: Sampler
Integer uniform sampler with configurable sign constraints.
Samples integers from :math:\{\text{min}, ..., \text{max}-1\}, optionally drawing
from positive and/or negative ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_value
|
int
|
Lower bound of the integer range. |
required |
max_value
|
int
|
Upper bound (exclusive) of the integer range. |
required |
uses_positive
|
bool
|
If |
True
|
uses_negative
|
bool
|
If |
True
|
Source code in SRToolkit/dataset/sampling.py
to_dict
Serialize this sampler to a JSON-compatible dictionary.
Source code in SRToolkit/dataset/sampling.py
from_dict
classmethod
Deserialize a IntegerUniformSampling from a dictionary produced by to_dict.
Source code in SRToolkit/dataset/sampling.py
log_uniform_sampling
Sample from log-uniform distribution over both positive and negative ranges.
Source code in SRToolkit/dataset/sampling.py
log_uniform_positive_sampling
Sample from log-uniform distribution over the positive range.
Source code in SRToolkit/dataset/sampling.py
log_uniform_negative_sampling
Sample from log-uniform distribution over the negative range.
Source code in SRToolkit/dataset/sampling.py
uniform_sampling
Sample from linear uniform distribution over both positive and negative ranges.
Source code in SRToolkit/dataset/sampling.py
uniform_positive_sampling
Sample from linear uniform distribution over the positive range.
uniform_negative_sampling
Sample from linear uniform distribution over the negative range.
integer_uniform_sampling
Sample integers from both positive and negative ranges.
Source code in SRToolkit/dataset/sampling.py
integer_uniform_positive_sampling
integer_uniform_negative_sampling
sampling_from_dict
Deserialize a sampler from a dictionary produced by its to_dict method.
Uses importlib to load the class from the "sampler_class" key, so any
user-defined Sampler subclass round-trips without a central registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
dict
|
Dictionary with a |
required |
Returns:
| Type | Description |
|---|---|
Sampler
|
A reconstructed Sampler instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ImportError
|
If the module cannot be imported. |
AttributeError
|
If the class cannot be found in the module. |