egobox_doe/traits.rs
1use linfa::Float;
2use ndarray::Array2;
3
4/// Sampling method allowing to generate a DoE in a given sample space
5///
6/// A sampling method is able to generate a set of `ns` samples in a given sample space.
7/// where the sample space is defined by `[lower_bound_xi, upper_bound_xi]^nx`
8/// within `R^nx` where `nx` is the dimension of the sample space: x = (x_i) with i in [1, nx].
9pub trait SamplingMethod<F: Float> {
10 /// Returns the bounds of the sample space
11 ///
12 /// # Returns
13 ///
14 /// * A (nx, 2) matrix where the ith row is the interval of the ith components of a sample.
15 fn sampling_space(&self) -> &Array2<F>;
16
17 /// Generates a (ns, nx)-shaped array of samples belonging to `[0., 1.]^nx`
18 ///
19 /// # Parameters
20 ///
21 /// * `ns`: number of samples
22 ///
23 /// # Returns
24 ///
25 /// * A (ns, nx) matrix of samples where nx is the dimension of the sample space
26 /// each sample belongs to `[0., 1.]^nx` hypercube
27 fn normalized_sample(&self, ns: usize) -> Array2<F>;
28
29 /// Generates a (ns, nx)-shaped array of samples belonging to `[lower_bound_xi, upper_bound_xi]^nx`
30 ///
31 /// # Parameters
32 ///
33 /// * `ns`: number of samples
34 ///
35 /// # Returns
36 ///
37 /// * A (ns, nx) matrix where nx is the dimension of the sample space.
38 /// each sample belongs to `[lower_bound_xi, upper_bound_xi]^nx` where bounds
39 /// are defined as returned values of `sampling_space` function.
40 fn sample(&self, ns: usize) -> Array2<F> {
41 let xlimits = self.sampling_space();
42 let lower = xlimits.column(0);
43 let scaler = &xlimits.column(1) - &lower;
44 self.normalized_sample(ns) * scaler + lower
45 }
46}