scimba_torch.integration.monte_carlo_parameters¶
Parameter samplers for Monte Carlo simulations.
Classes
|
Abstract base class for parametric samplers. |
|
Sample from a Sobol sequence within given bounds for each dimension. |
|
Sample uniformly from given bounds for each dimension. |
|
Sample uniformly the velocities in a circle of radius r. |
|
Sample uniformly the velocities in a cuboid. |
- class ParametricSampler(bounds, **kwargs)[source]¶
Bases:
ABCAbstract base class for parametric samplers.
- Parameters:
bounds (
list[tuple[float,float]]) – A list of tuples, containing the lower and upper bounds.**kwargs – Keyword arguments including: - pre-sampling: whether to pre-sample points before training; - n_pre_sampled: the number of pre-sampled points to generate if so.
- Raises:
TypeError –
If parameters domain is not a list of tuples of two floats. - If n_pre_sampled is not an integer.
ValueError – If any bound has lower value greater than upper value.
- set_new_bounds(nbounds)[source]¶
Updates the bounds of the parameters in the approximation space.
- Parameters:
nbounds (
list[tuple[float,float]]) – A list of tuples containing the new bounds for each parameter.- Return type:
None
- abstract sample_new_points(n)[source]¶
Generates samples within the specified bounds for each dimension.
- Parameters:
n (
int) – The number of samples to generate.- Return type:
- Returns:
A tensor containing the generated samples and corresponding labels.
- sample_from_pre_sampled_points(n)[source]¶
Samples from the pre-sampled points.
- Parameters:
n (
int) – The number of samples to generate.- Return type:
- Returns:
A tensor containing the generated samples and corresponding labels.
- check_sample_size(n)[source]¶
Checks if the sample size is a non-negative integer.
- Parameters:
n (
int) – The number of samples to generate.- Raises:
TypeError – If argument is not an integer.
ValueError – If argument is negative.
- rescale_samples(samples)[source]¶
Rescales the samples to fit within the specified bounds.
This function assumes that the samples are generated in the unit hypercube \([0, 1]^{\text{dim}}\) and rescales them to fit within the bounds specified for each dimension. It also: - make the samples require gradients; - converts the samples to a LabelTensor with zero labels.
- Parameters:
samples (
Tensor) – A tensor containing the generated samples.- Return type:
- Returns:
A tensor containing the rescaled samples.
- class UniformParametricSampler(bounds, **kwargs)[source]¶
Bases:
ParametricSamplerSample uniformly from given bounds for each dimension.
- Parameters:
bounds (
list[tuple[float,float]]) – A list of tuples, containing the lower and upper bounds.
- class SobolParametricSampler(bounds, **kwargs)[source]¶
Bases:
ParametricSamplerSample from a Sobol sequence within given bounds for each dimension.
- Parameters:
bounds (
list[tuple[float,float]]) – A list of tuples, containing the lower and upper bounds.**kwargs – Keyword arguments including: - pre-sampling: whether to pre-sample points before training; - n_pre_sampled: the number of pre-sampled points to generate if so.
- Raises:
TypeError – If bounds is not a list of tuples of two floats.
- class UniformVelocitySampler(velocity_domain)[source]¶
Bases:
objectSample uniformly the velocities in a circle of radius r.
- Parameters:
velocity_domain (
Circle2D) – Velocity domain in which the velocity will be drawn.- Raises:
TypeError – If velocity domain is not an object of class Circle2D.
- dim¶
The number of dimensions, here equal to 2.
- sample(n)[source]¶
Generates samples uniformly within the specified bounds for each dimension.
- Parameters:
n (
int) – The number of samples to generate.- Return type:
- Returns:
A tensor containing the generated samples and corresponding labels.
- Raises:
TypeError – If argument is not an integer.
ValueError – If argument is negative.
- class UniformVelocitySamplerOnCuboid(velocity_domain)[source]¶
Bases:
objectSample uniformly the velocities in a cuboid.
- Parameters:
velocity_domain (
Segment1D|Square2D|Cube3D) – Velocity domain in which the velocity will be drawn.- Raises:
TypeError – If velocity domain is not an object of class Segment1D, Square2D or Cube3D.
- dim¶
The number of dimensions.
- domain_size¶
The size of the domain in each dimension.
- lower_bound¶
The lower bound of the domain.
- sample(n)[source]¶
Generates samples uniformly within the specified bounds for each dimension.
- Parameters:
n (
int) – The number of samples to generate.- Return type:
- Returns:
A tensor containing the generated samples and corresponding labels.
- Raises:
TypeError – If argument is not an integer.
ValueError – If argument is negative.