Perturbations¶
dicex.GaussianPerturbation(mu, sigma=None, *, cov=None, d=None, env_mean=None, env_cov=None, seed=None) ¶
Bases: BasePerturbation
Gaussian perturbation for the pair (T, ε).
T is Gaussian directional execution noise. ε ~ N(env_mean, env_cov) is the additive environmental noise.
Initialize with Gaussian directional noise and additive noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu | float | ndarray | Mean parameter of T. Scalar for shared mean, vector otherwise. | required |
sigma | float | ndarray | None | Standard deviation parameter of T. Scalar for iid noise, vector for diagonal covariance. Mutually exclusive with | None |
cov | ndarray | None | Covariance parameter of T. Can be diagonal | None |
d | int | None | Optional dimensionality of T when it cannot be inferred later. | None |
env_mean | ndarray | None | Mean vector m_ε of the additive noise (d,). If None, defaults to zero vector. | None |
env_cov | ndarray | None | Covariance matrix Σ_ε of the additive noise (d, d). If None, defaults to zero matrix. | None |
seed | int | None | Optional seed for the random number generator. | None |
Source code in src/dicex/distributions/gaussian.py
params property ¶
Return the parameters of the distribution.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | dict[str, Any]: Dictionary containing the perturbation configuration. |
sample(n, d=None, rng=None) ¶
Sample n directional perturbation vectors from the configured Gaussian law.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Number of samples. | required |
d | int | None | Optional feature-space dimension. | None |
rng | Generator | None | Optional random number generator. | None |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: 2D array of shape (n, dim). |
Source code in src/dicex/distributions/gaussian.py
sample_env(n, d, rng=None) ¶
Sample n additive perturbation vectors ε_i from N(m_ε, Σ_ε).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Number of samples. | required |
d | int | Dimensionality of the feature space. | required |
rng | Generator | None | Optional random number generator. | None |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: 2D array of shape (n, d). |
Source code in src/dicex/distributions/gaussian.py
dicex.UniformPerturbation(mu, delta, *, d=None, env_mean=None, env_cov=None, seed=None) ¶
Bases: BasePerturbation
Uniform perturbation for the pair (T, ε).
T has iid coordinates distributed as Unif[mu - delta, mu + delta]. ε ~ N(env_mean, env_cov) is the additive environmental noise.
Initialize with scalar noise parameters and additive noise parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu | float | ndarray | Mean of the distribution. | required |
delta | float | ndarray | Half-width of the distribution (radius). | required |
d | int | None | Optional dimensionality of T when it cannot be inferred later. | None |
env_mean | ndarray | None | Mean vector m_ε of the additive noise (d,). If None, defaults to zero vector. | None |
env_cov | ndarray | None | Covariance matrix Σ_ε of the additive noise (d, d). If None, defaults to zero matrix. | None |
seed | int | None | Optional seed for the random number generator. | None |
Source code in src/dicex/distributions/uniform.py
params property ¶
Return the parameters of the distribution.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | dict[str, Any]: Dictionary containing the perturbation configuration. |
sample(n, d=None, rng=None) ¶
Sample n directional perturbation vectors with iid uniform coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Number of samples. | required |
d | int | None | Optional feature-space dimension. | None |
rng | Generator | None | Optional random number generator. | None |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: 2D array of shape (n, dim). |
Source code in src/dicex/distributions/uniform.py
sample_env(n, d, rng=None) ¶
Sample n additive perturbation vectors ε_i from N(m_ε, Σ_ε).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Number of samples. | required |
d | int | Dimensionality of the feature space. | required |
rng | Generator | None | Optional random number generator. | None |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: 2D array of shape (n, d). |
Source code in src/dicex/distributions/uniform.py
dicex.CustomPerturbation(sample_fn, sample_env_fn=None, env_mean=None, env_cov=None, params=None) ¶
Bases: BasePerturbation
Perturbation distribution defined by user-provided sampling callables.
Initialize with user-provided callables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_fn | Callable | Callable that returns an array of directional samples of shape (n, d). | required |
sample_env_fn | Callable | None | Optional callable (n, d) -> (n, d) array for ε samples. | None |
env_mean | ndarray | None | Mean vector m_ε of the additive noise (d,). | None |
env_cov | ndarray | None | Covariance matrix Σ_ε of the additive noise (d, d). | None |
params | dict[str, Any] | None | Optional dict of parameters describing the distribution. | None |
Source code in src/dicex/distributions/custom.py
params property ¶
Return the parameters of the distribution.
sample(n, d=None, rng=None) ¶
Sample n directional perturbation vectors T_i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Number of samples. | required |
d | int | None | Optional feature-space dimension. | None |
rng | Generator | None | Optional random number generator. | None |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Array of shape (n,) when d is None or the callable ignores d, or (n, d) otherwise. |
Source code in src/dicex/distributions/custom.py
sample_env(n, d, rng=None) ¶
Sample n additive perturbation vectors ε_i ∈ R^d.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Number of samples. | required |
d | int | Dimensionality of the feature space. | required |
rng | Generator | None | Optional random number generator. | None |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Array of shape (n, d). |