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