meslas package¶
Subpackages¶
- meslas.covariance package
- meslas.external_dependencies package
- Submodules
- meslas.external_dependencies.numpytorch module
WrapTorch
aggregate()
append_dim()
append_to_ndim()
attach_dim()
block_diag()
block_diag_irregular()
bootstrap()
categrnd()
circdiff()
conv_t()
crossvalincl()
deg2rad()
delta()
enforce_tensor()
entropy()
expand_all()
expand_batch()
expand_upto_dim()
float()
freeze()
get_jacobian()
interp1d()
inv_gaussian_cdf()
inv_gaussian_mean_std2params()
inv_gaussian_pdf()
inv_gaussian_pmf_mean_stdev()
inv_gaussian_variance()
inv_gaussian_variance2lam()
isnan()
kron()
kw_np2torch()
log_normpdf()
logistic()
logit()
lognorm_params_given_mean_stdev()
lognorm_pmf()
lognormal_params2mean_stdev()
m2v()
m2v0()
mat2vec0()
matmul0()
matmul2vec()
matsum()
matvecmul0()
max_distrib()
max_shape()
mean_distrib()
min_distrib()
mm0()
mvm0()
mvnpdf_log()
mvnrnd()
nan2v()
nanmean()
nansum()
normrnd()
npy()
npys()
numpy()
onehotrnd()
p2en()
p2st()
pconc2conc()
permute2en()
permute2st()
prad2unitvec()
prepend_dim()
prepend_to_ndim()
rad2deg()
rand()
ravel_multi_index()
repeat_all()
repeat_batch()
repeat_dim()
repeat_to_shape()
scatter_add()
sem()
sem_distrib()
shiftdim()
softmax_bias()
softmax_mask()
std_distrib()
sumto1()
t()
tensor()
test_kron()
test_softmax_bias()
unblock_diag()
unravel_index()
v2m()
v2m0()
var_distrib()
vec2mat0()
vec2matmul()
vec_on()
vec_on_dim()
vmpdf()
vmpdf_a_given_b()
vmpdf_prad_pconc()
- Module contents
- meslas.geometry package
Submodules¶
meslas.excursion module¶
Compute coverage function, excursion sets and related quantities.
- meslas.excursion.coverage_fct_fixed_location(mean_vec, cov_mat, lower, upper=None)¶
Computes coverage function at a fixed set of location.
Ths function should be used when a mean vector and covariance matrix for a set of locations have been precomputed.
Uses the torch implementation of the multivariate CDF by Sebastien Marmin, see torch-mvn.
- Parameters:
- mean_vec: (M, p) Tensor
Mean vector at each of the M locations. mean_vec[i, :] should give the mean vector at location nr i.
- cov_mat: (M, p, p) Tensor
Covariance matrix at each of the M locations. cov_mat[i, :, :] should give the covariance matrix at location nr i.
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported. WARNING: wrong shapes can cause unexpected results.
- upper: (p) Tensor
List of upper threshold for each response. The excursion set is the set where responses are above the specified threshold. If not provided, defaults to + infinity.
- Returns:
- excursion_prob: (M) Tensor
Probability to be in excursion at each location.
meslas.inverse_random_fields module¶
meslas.means module¶
Mean functions for GRFs.
- class meslas.means.ConstantMean(means)¶
Bases:
object
Constant mean function.
- Parameters:
- means: (p) array-like.
Constant mean of each of the p-components.
Methods
__call__
(S, L)- Parameters:
- class meslas.means.LinearMean(beta0s, beta1s)¶
Bases:
object
Linear trend mean function. The mean at location x will be given by beta0 + beta1 x
- Parameters:
- betas0: (p) array-like.
Constant mean mean term for of each of the p-components.
- betas1: (p, d) array-like.
Linear trend matrix for each of the p-components.
Methods
__call__
(S, L)- Parameters:
meslas.plotting module¶
meslas.plotting_physical module¶
meslas.random_fields module¶
meslas.sensor module¶
TODO: Maybe add grid, grf, n_ouptuts to the sensor class.
- class meslas.sensor.DiscreteSensor(discrete_grf)¶
Bases:
Sensor
Sensor on a fixed discretization.
Methods
choose_next_point_myopic
(noise_std, lower[, ...])Choose the next observation location (given the current one) using the myopic strategy.
compute_exursion_prob
(lower[, upper])Compute the excursion probability on the whole grid, given the currently available data.
get_neighbors_isotopic_eibv
(noise_std, lower)For each neighbouring node of the current sensor location, compute the eibv if we were to measure every response (isotopic) at that node.
run_lookahead_stragegy
(n_steps, data_feed, ...)Run the myopic strategy for n_steps, starting from the current location.
run_myopic_stragegy
(n_steps, data_feed, ...)Run the myopic strategy for n_steps, starting from the current location.
update_design
(S_y_inds, L_y, y[, noise_std])Updates the full design grid by computing current conditional mean and covariance.
- choose_next_point_myopic(noise_std, lower, upper=None)¶
Choose the next observation location (given the current one) using the myopic strategy.
- Parameters:
- noise_std: float
Standar deviation of measurement noise.
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
If not provided, defaults to +infty (excursion set above threshold).
- Returns:
- next_point_ind: (1) Tensor
Grid index of next observation location chosen according to the myopic strategy.
- next_point_eibv: (1) Tensor
EIBV corresponding to the next chosen point.
- compute_exursion_prob(lower, upper=None)¶
Compute the excursion probability on the whole grid, given the currently available data.
- Parameters:
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
List of upper threshold for each response. The excursion set is the set where responses are above the specified threshold. If not provided, defaults to + infinity.
- Returns:
- excursion_proba: (self.grid.n_points) Tensor
Excursion probability at each point.
- get_neighbors_isotopic_eibv(noise_std, lower, upper=None)¶
For each neighbouring node of the current sensor location, compute the eibv if we were to measure every response (isotopic) at that node. Returns a list containing the EIBV for each neighbor.
- Parameters:
- noise_std: float
Standar deviation of measurement noise.
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
If not provided, defaults to +infty (excursion set above threshold).
- Returns:
- neighbors_eibv: (n_neighbors) Tensor
EIBV for each neighbouring cell.
- neighbors_inds: (n_neighbors) Tensor
Grid indices of the neighbouring cells.
- run_lookahead_stragegy(n_steps, data_feed, noise_std, lower, upper=None, n_prune=3)¶
Run the myopic strategy for n_steps, starting from the current location. That is, at each point, pick the neighbors with the smallest EIBV, move there, observe, update model, repeat.
- Parameters:
- n_steps: int
Number of steps (observations) to run the strategy for.
- data_feed: function(int)
Function that, given a node index, returns the measured data (isotopic) at that node.
- noise_std
- lower
- upper
- n_prune: int
Number of paths to consider at the first step. From the starting node, we will only consider the best n_prune nodes, ranked using the myopic strategy.
- run_myopic_stragegy(n_steps, data_feed, noise_std, lower, upper=None)¶
Run the myopic strategy for n_steps, starting from the current location. That is, at each point, pick the neighbors with the smallest EIBV, move there, observe, update model, repeat.
- Parameters:
- n_steps: int
Number of steps (observations) to run the strategy for.
- data_feed: function(int)
Function that, given a node index, returns the measured data (isotopic) at that node.
- update_design(S_y_inds, L_y, y, noise_std=None)¶
Updates the full design grid by computing current conditional mean and covariance. Note that this updates the internal of the discrete GRF.
- Returns:
- mu_cond_iso: (self.grid.n_points, self.grf.n_out)
Conditional mean.
- K_cond_iso: (self.grid.n_points, self.grid.n_points, self.grf.n_out, self.grf.n_out) Tensor
Conditional covariance matrix in isotopic ordered form. It means that the covariance matrix at cell i can be otained by subsetting K_cond_iso[i, i, :, :].
- class meslas.sensor.Sensor(grid, grf)¶
Bases:
object
Implements the data collection process. Will be responsible for querying the GP for mean and variances conditional on the already collected data.
- Attributes:
- S_y_tot: (N, d) Tensor
Spatial locations of the already collected data.
- L_y_tot: (N) Tensor
Corresponding response indices.
- location: (d) Tensor
Current position of the sensor.
- grid: IrregularGrid
A discretization of space that defines the locations the sensor can move to.
- grf: GRF
Gaussian Random Field used to model the unknown phenomenon of interest.
- current_node_ind: int
Index of the point in the grid that is closest to the sensor location.
- visited_nodes_inds: Tensor
Grid indices of the visited locations.
- noise_std: float
Standard deviation of the sensor noise. TODO: allow different noises for each component.
Methods
add_data
(S_y_inds, L_y, y)Add new data to the already collected one.
compute_exursion_prob
(points, lower[, upper])Compute the excursion probability at a set of points given the currently available data.
compute_neighbors_exursion_prob
(lower[, upper])Compute the excursion probability of the neighbors of the current location.
Get the neighbouring grid nodes of the current sensor location.
set_location
(location)Setter for the location.
- add_data(S_y_inds, L_y, y)¶
Add new data to the already collected one. Can also handle batches. This will just concatenate the new data vectors with the current ones.
- Parameters:
- S_y_inds: (n) Tensor
Grind index of spatial locations of the new measurements.
- L_y :(n) Tensor
Corresponding response indices.
- y :(n, p) Tensor
Measured data.
- compute_exursion_prob(points, lower, upper=None)¶
Compute the excursion probability at a set of points given the currently available data.
Note this is a helper function that take an index in the grid as input.
- Parameters:
- points: (N, d) Tensor
List of points (coordinates) at which to compute the excursion probability.
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
List of upper threshold for each response. The excursion set is the set where responses are above the specified threshold. If not provided, defaults to + infinity.
- Returns:
- excursion_proba: (N) Tensor
Excursion probability at each point.
- compute_neighbors_exursion_prob(lower, upper=None)¶
Compute the excursion probability of the neighbors of the current location.
- Parameters:
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
List of upper threshold for each response. The excursion set is the set where responses are above the specified threshold. If not provided, defaults to + infinity.
- get_current_neighbors()¶
Get the neighbouring grid nodes of the current sensor location.
This is done by first finding the node closes to the sensor location, and then returning its neighbors.
- Returns:
- neighbors_inds: (n_neighbors)
Grid indices of the neighbors.
- set_location(location)¶
Setter for the location.
- Parameters:
- location: (d) array_like
meslas.sensor_plotting module¶
REPORTING VERSION OF THE SENSOR MODULE.
The problem is that at stage n, we havent yet computed the ebiv of the neighbors and if we want a sensible plot, we have to provide the eibvs with the CURRENT status of the model. This doesn’t agree with the natural flow of the myopic search, so we choose to have a dedicated version of the module to produce the plots.
- class meslas.sensor_plotting.DiscreteSensor(discrete_grf)¶
Bases:
Sensor
Sensor on a fixed discretization.
Methods
choose_next_point_myopic
(noise_std, lower[, ...])Choose the next observation location (given the current one) using the myopic strategy.
compute_exursion_prob
(lower[, upper])Compute the excursion probability on the whole grid, given the currently available data.
get_neighbors_isotopic_eibv
(noise_std, lower)For each neighbouring node of the current sensor location, compute the eibv if we were to measure every response (isotopic) at that node.
run_myopic_stragegy
(n_steps, data_feed, ...)Run the myopic strategy for n_steps, starting from the current location.
update_design
(S_y_inds, L_y, y[, noise_std])Updates the full design grid by computing current conditional mean and covariance.
- choose_next_point_myopic(noise_std, lower, upper=None)¶
Choose the next observation location (given the current one) using the myopic strategy.
- Parameters:
- noise_std: float
Standar deviation of measurement noise.
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
If not provided, defaults to +infty (excursion set above threshold).
- Returns:
- next_point_ind: (1) Tensor
Grid index of next observation location chosen according to the myopic strategy.
- next_point_eibv: (1) Tensor
EIBV corresponding to the next chosen point.
- compute_exursion_prob(lower, upper=None)¶
Compute the excursion probability on the whole grid, given the currently available data.
- Parameters:
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
List of upper threshold for each response. The excursion set is the set where responses are above the specified threshold. If not provided, defaults to + infinity.
- Returns:
- excursion_proba: (self.grid.n_points) Tensor
Excursion probability at each point.
- get_neighbors_isotopic_eibv(noise_std, lower, upper=None)¶
For each neighbouring node of the current sensor location, compute the eibv if we were to measure every response (isotopic) at that node. Returns a list containing the EIBV for each neighbor.
- Parameters:
- noise_std: float
Standar deviation of measurement noise.
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
If not provided, defaults to +infty (excursion set above threshold).
- Returns:
- neighbors_eibv: (n_neighbors) Tensor
EIBV for each neighbouring cell.
- neighbors_inds: (n_neighbors) Tensor
Grid indices of the neighbouring cells.
- run_myopic_stragegy(n_steps, data_feed, noise_std, lower, upper=None)¶
Run the myopic strategy for n_steps, starting from the current location. That is, at each point, pick the neighbors with the smallest EIBV, move there, observe, update model, repeat.
- Parameters:
- n_steps: int
Number of steps (observations) to run the strategy for.
- data_feed: function(int)
Function that, given a node index, returns the measured data (isotopic) at that node.
- update_design(S_y_inds, L_y, y, noise_std=None)¶
Updates the full design grid by computing current conditional mean and covariance. Note that this updates the internal of the discrete GRF.
- Returns:
- mu_cond_iso: (self.grid.n_points, self.grf.n_out)
Conditional mean.
- K_cond_iso: (self.grid.n_points, self.grid.n_points, self.grf.n_out, self.grf.n_out) Tensor
Conditional covariance matrix in isotopic ordered form. It means that the covariance matrix at cell i can be otained by subsetting K_cond_iso[i, i, :, :].
- class meslas.sensor_plotting.Sensor(grid, grf)¶
Bases:
object
Implements the data collection process. Will be responsible for querying the GP for mean and variances conditional on the already collected data.
- Attributes:
- S_y_tot: (N, d) Tensor
Spatial locations of the already collected data.
- L_y_tot: (N) Tensor
Corresponding response indices.
- location: (d) Tensor
Current position of the sensor.
- grid: IrregularGrid
A discretization of space that defines the locations the sensor can move to.
- grf: GRF
Gaussian Random Field used to model the unknown phenomenon of interest.
- current_node_ind: int
Index of the point in the grid that is closest to the sensor location.
- visited_nodes_inds: Tensor
Grid indices of the visited locations.
- noise_std: float
Standard deviation of the sensor noise. TODO: allow different noises for each component.
Methods
add_data
(S_y_inds, L_y, y)Add new data to the already collected one.
compute_exursion_prob
(points, lower[, upper])Compute the excursion probability at a set of points given the currently available data.
compute_neighbors_exursion_prob
(lower[, upper])Compute the excursion probability of the neighbors of the current location.
Get the neighbouring grid nodes of the current sensor location.
set_location
(location)Setter for the location.
- add_data(S_y_inds, L_y, y)¶
Add new data to the already collected one. Can also handle batches. This will just concatenate the new data vectors with the current ones.
- Parameters:
- S_y_inds: (n) Tensor
Grind index of spatial locations of the new measurements.
- L_y :(n) Tensor
Corresponding response indices.
- y :(n, p) Tensor
Measured data.
- compute_exursion_prob(points, lower, upper=None)¶
Compute the excursion probability at a set of points given the currently available data.
Note this is a helper function that take an index in the grid as input.
- Parameters:
- points: (N, d) Tensor
List of points (coordinates) at which to compute the excursion probability.
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
List of upper threshold for each response. The excursion set is the set where responses are above the specified threshold. If not provided, defaults to + infinity.
- Returns:
- excursion_proba: (N) Tensor
Excursion probability at each point.
- compute_neighbors_exursion_prob(lower, upper=None)¶
Compute the excursion probability of the neighbors of the current location.
- Parameters:
- lower: (p) Tensor
List of lower threshold for each response. The excursion set is the set where responses are above the specified threshold. Note that np.inf is supported.
- upper: (p) Tensor
List of upper threshold for each response. The excursion set is the set where responses are above the specified threshold. If not provided, defaults to + infinity.
- get_current_neighbors()¶
Get the neighbouring grid nodes of the current sensor location.
This is done by first finding the node closes to the sensor location, and then returning its neighbors.
- Returns:
- neighbors_inds: (n_neighbors)
Grid indices of the neighbors.
- set_location(location)¶
Setter for the location.
- Parameters:
- location: (d) array_like
meslas.vectors module¶
Encapsulation of the reshaping between isotopic and non-isotopic form.
- class meslas.vectors.GeneralizedMatrix(vals, n_points1, n_out1, n_points2, n_out2)¶
Bases:
object
Same as GeneralizedVector, but for matrices.
- Attributes:
Methods
numpy
()Returns a numpy array containing the isotopic form of the matrix.
from_isotopic
from_list
set_vals
- classmethod from_isotopic(vals_iso)¶
- classmethod from_list(vals, n_points1, n_out1, n_points2, n_out2)¶
- property isotopic¶
Returns the 2D isotopic form of the generalized vector.
- Returns:
- vals_isotopic: (self.n_points, self.n_out) Tensor
- property list¶
Returns the 1D list form of the generalized vector.
- Returns:
- vals_list: (self.n_points * self.n_out) Tensor
- numpy()¶
Returns a numpy array containing the isotopic form of the matrix. Used for interfacing with others libraries and for saving.
- set_vals(vals)¶
- property shape¶
- class meslas.vectors.GeneralizedVector(vals, n_points, n_out)¶
Bases:
object
A generalized vector is used to implement the types of vectors that appear when working with multivariate random fields. Given n_points points in space, the value of a n_out dimensional random process at those points may be represented as a (n_points, n_out) vector. But for some operations (like sampling) it makes sense to expand this as a one dimensional vector of lenght (n_points, n_out). This is what this class is used for.
The two dimensional form is called the isotopic form, by analogy with the process of measuring all components of a random field, whereas the one-dimensional form is called the list form.
The underlying data structure is always a one-dimensional list of values. The class is indexable as GeneralizedVector[…], and the indexing will be performed on the isotopic from. What will be returned is a subset of the isotopic tensor.
- Attributes:
Methods
numpy
()Returns a numpy array containing the isotopic form of the vector.
from_isotopic
from_list
set_vals
- classmethod from_isotopic(vals_iso)¶
- classmethod from_list(vals, n_points, n_out)¶
- property isotopic¶
Returns the 2D isotopic form of the generalized vector.
- Returns:
- vals_isotopic: (self.n_points, self.n_out) Tensor
- property list¶
Returns the 1D list form of the generalized vector.
- Returns:
- vals_list: (self.n_points * self.n_out) Tensor
- numpy()¶
Returns a numpy array containing the isotopic form of the vector. Used for interfacing with others libraries and for saving.
- set_vals(vals)¶
- property shape¶