bet package¶
Subpackages¶
Submodules¶
bet.Comm module¶
This module provides a workaround for people without mpi4py installed to run BET.
- class bet.Comm.MPI_for_no_mpi4py¶
Bases:
object
Provides a fake MPI implementation so that the user need not install mpi4py.
- BOOL¶
bool type
- DOUBLE¶
float type
- INT¶
int type
- SUM¶
fake sum
- class bet.Comm.comm_for_no_mpi4py¶
Bases:
object
Provides a fake MPI.COMM_WORLD implementation so that the user need not install mpi4py.
- Allgather(val, val2=None)¶
- Allreduce(val1, val2=None, op=None)¶
- Barrier()¶
Does nothing in serial.
- Bcast(val, root=0)¶
- Scatter(val1, val2, root=0)¶
- allreduce(val1, op=None)¶
- barrier()¶
Does nothing in serial.
- bcast(val, root=0)¶
- gather(val1, root=0)¶
- rank¶
rank, 0
- scatter(val1, root=0)¶
- size¶
size, 1
bet.sample module¶
This module contains the main data structures and exceptions for BET. Notably:
sample_set_base
provides the basic data structure for input and output setssample_set
is the default sample set.voronoi_sample_set
is a sample set based on a Voronoi discretization (same as default).rectangle_sample_set
is a sample set based on a hyper-rectangle.ball_sample_set
is a sample set based on balls in R^ncartesian_sample_set
is a sample set based on a Cartesian grid.discretization
provides the basic data structure for and input to output stochastic map.length_not_matching
is an Exception class.dim_not_matching
is an Exception class.evaluate_pdf()
evaluates probability density functions.evaluate_pdf_marginal()
evaluates marginal probability density functions.
- class bet.sample.ball_sample_set(dim)¶
Bases:
bet.sample.sample_set_base
A data structure containing arrays specific to a set of samples defining discretization containing a number of balls. Only returns the neighbors for which \(x_i \in A_k\).
A series of n balls \(A_i \subset \Lambda\) with \(A_i \cap A_j = \emptyset\) for \(i \neq j\). The last entry represents the remainder \(\Lambda \setminus ( \cup_{i-1}^n A_i)\).
- append_error_estimates(new_error_estimates)¶
Does nothing for this type of sample set.
Note
Remember to update the other member attribute arrays so that
check_num()
does not fail.- Parameters
new_error_estimates (
numpy.ndarray
of shape (num,)) – New error_estimates to append.
- append_jacobians(new_jacobians)¶
Does nothing for this type of sample set.
Note
Remember to update the other member attribute arrays so that
check_num()
does not fail.- Parameters
new_jacobians (
numpy.ndarray
of shape (num, other_dim, dim)) – New jacobians to append.
- append_values(values)¶
Does nothing for this type of sample_set.
See also
numpy.concatenate()
- Parameters
values (
numpy.ndarray
of shape (some_num, dim)) – values to append
- append_values_local(values_local)¶
Does nothing for this type of sample_set.
See also
numpy.concatenate()
- Parameters
values_local (
numpy.ndarray
of shape (some_num, dim)) – values to append
- exact_volume()¶
Calculate the exact volume fraction given the given p-norm.
- query(x, k=1)¶
Identify which value points x are associated with for discretization. The distance is set to 0 if it is in the rectangle and infinity if it is not. It is only considered in or out.
See also
scipy.spatial.KDTree.query()
- Parameters
x (
numpy.ndarray
of shape(*, dim)
) – points for queryk (int) – number of nearest neighbors to return
- Return type
tuple
- Returns
(dist, ptr)
- setup(centers, radii)¶
Initialize.
- Parameters
centers (iterable of shape (num-1, dim)) – centers of balls
radii (iterable of length num-1) – radii of balls
- update_bounds(num=None)¶
Does nothing for this type of sample set.
- update_bounds_local(num_local=None)¶
Does nothing for this type of sample set.
- class bet.sample.cartesian_sample_set(dim)¶
Bases:
bet.sample.rectangle_sample_set
Defines a hyperrectangle discretization based on a Cartesian grid.
See also
- setup(xi)¶
Initialize.
- Parameters
xi (array_like) – x1, x2,…, xn, 1-D arrays representing the coordinates of a grid
See also
numpy.meshgrid()
- exception bet.sample.dim_not_matching¶
Bases:
Exception
Exception for when the dimension of the array is inconsistent.
- class bet.sample.discretization(input_sample_set, output_sample_set, output_probability_set=None, emulated_input_sample_set=None, emulated_output_sample_set=None, output_observed_set=None)¶
Bases:
object
A data structure to store all of the
sample_set_base
objects and associated pointers to solve an stochastic inverse problem.- check_nums()¶
Checks that
self._input_sample_set
andself._output_sample_set
both have the same number of samples.- Return type
- Returns
Number of samples
- choose_inputs_outputs(inputs=None, outputs=None)¶
Slices the inputs and outputs of the discretization.
- Parameters
inputs (list) – list of indices of input sample set to include
outputs (list) – list of indices of output sample set to include
- Return type
- Returns
sliced discretization
- clip(cnum)¶
Creates and returns a discretization with the the first cnum entries of the input and output sample sets.
- Parameters
cnum (int) – number of values of sample set to return
- Return type
- Returns
clipped discretization
- copy()¶
Makes a copy using
numpy.copy()
.- Return type
- Returns
Copy of this
discretization
- estimate_input_volume_emulated()¶
Calculate the volume faction of cells approximately using Monte Carlo integration.
Note
This could be re-written to just use
emulated_ii_ptr
instead of_emulated_input_sample_set
.
- estimate_output_volume_emulated()¶
Calculate the volume faction of cells approximately using Monte Carlo integration.
Note
This could be re-written to just use
emulated_oo_ptr
instead of_emulated_output_sample_set
.
- get_emulated_ii_ptr()¶
Returns the pointer from
self._emulated_input_sample_set
toself._input_sample_set
See also
scipy.spatial.KDTree.query`()
- Return type
numpy.ndarray
of int of shape (self._output_sample_set._values.shape[0],)- Returns
self._emulated_ii_ptr
- get_emulated_input_sample_set()¶
Returns a reference to the emulated_input sample set for this discretization.
- Return type
- Returns
emulated_input sample set
- get_emulated_oo_ptr()¶
Returns the pointer from
self._emulated_output_sample_set
toself._output_probability_set
See also
scipy.spatial.KDTree.query`()
- Return type
numpy.ndarray
of int of shape (self._output_sample_set._values.shape[0],)- Returns
self._emulated_ii_ptr
- get_emulated_output_sample_set()¶
Returns a reference to the emulated_output sample set for this discretization.
- Return type
- Returns
emulated_output sample set
- get_input_sample_set()¶
Returns a reference to the input sample set for this discretization.
- Return type
- Returns
input sample set
- get_io_ptr()¶
Returns the pointer from
self._output_sample_set
toself._output_probability_set
See also
scipy.spatial.KDTree.query`()
- Return type
numpy.ndarray
of int of shape (self._output_sample_set._values.shape[0],)- Returns
self._io_ptr
- get_output_observed_set()¶
Returns a reference to the output observed sample set for this discretization.
- Return type
- Returns
output sample set
- get_output_probability_set()¶
Returns a reference to the output probability sample set for this discretization.
- Return type
- Returns
output probability sample set
- get_output_sample_set()¶
Returns a reference to the output sample set for this discretization.
- Return type
- Returns
output sample set
- global_to_local()¶
Call global_to_local for
input_sample_set
andoutput_sample_set
.
- globalize_ptrs()¶
Globalizes discretization pointers.
- local_to_global()¶
Call local_to_global for
input_sample_set
andoutput_sample_set
.
- merge(disc)¶
Merges a given discretization with this one by merging the input and output sample sets.
- Parameters
disc (
bet.sample.discretization
) – Discretization object to merge with.- Return type
- Returns
Merged discretization
- sample_set_names = ['_input_sample_set', '_output_sample_set', '_emulated_input_sample_set', '_emulated_output_sample_set', '_output_probability_set', '_output_observed_set']¶
List of attribute names for attributes that are
sample.sample_set_base
- save(filename, globalize=True)¶
Save the discretization using pickle.
- Returns
- set_emulated_ii_ptr(globalize=True)¶
Creates the pointer from
self._emulated_input_sample_set
toself._input_sample_set
See also
scipy.spatial.KDTree.query`()
- set_emulated_input_sample_set(emulated_input_sample_set)¶
Sets the emulated_input sample set for this discretization.
- Parameters
emulated_input_sample_set (
sample_set_base
) – emupated input sample set.
- set_emulated_oo_ptr(globalize=True)¶
Creates the pointer from
self._emulated_output_sample_set
toself._output_probability_set
See also
scipy.spatial.KDTree.query`()
- set_emulated_output_sample_set(emulated_output_sample_set)¶
Sets the emulated_output sample set for this discretization.
- Parameters
emulated_output_sample_set (
sample_set_base
) – emupated output sample set.
- set_input_sample_set(input_sample_set)¶
Sets the input sample set for this discretization.
- Parameters
input_sample_set (
sample_set_base
) – input sample set.
- set_io_ptr(globalize=True)¶
Creates the pointer from
self._output_sample_set
toself._output_probability_set
- Parameters
globalize (bool) – flag whether or not to globalize
self._output_sample_set
- set_output_observed_set(output_sample_set)¶
Sets the output observed sample set for this discretization.
- Parameters
output_sample_set (
sample_set_base
) – output observed sample set.
- set_output_probability_set(output_probability_set)¶
Sets the output probability sample set for this discretization.
- Parameters
output_probability_set (
sample_set_base
) – output probability sample set.
- set_output_sample_set(output_sample_set)¶
Sets the output sample set for this discretization.
- Parameters
output_sample_set (
sample_set_base
) – output sample set.
- vector_names = ['_io_ptr', '_io_ptr_local', '_emulated_ii_ptr', '_emulated_ii_ptr_local', '_emulated_oo_ptr', '_emulated_oo_ptr_local']¶
List of attribute names for attributes which are vectors or 1D
numpy.ndarray
- exception bet.sample.domain_not_matching¶
Bases:
Exception
Exception for when the domain does not match.
- bet.sample.evaluate_pdf(prob_type, prob_parameters, vals)¶
Evaluate the probability density function defined by prob_type and prob_parameters at points defined by vals.
- Parameters
prob_type (str) – Type of probability description. Options are ‘kde’ (weighted kernel density estimate), ‘rv’ (random variable), ‘gmm’ (Gaussian mixture model), and ‘voronoi’.
prob_parameters – Parameters that define the probability measure of type prob_type
vals (
numpy.ndarray
) – Values at which to evaluate the PDF.
- Returns
probability density evaluated at vals
:rtype numpy.ndarray
- bet.sample.evaluate_pdf_marginal(prob_type, prob_parameters, vals, i)¶
Evaluate the marginal probability density function of index i defined by prob_type and prob_parameters at points defined by vals.
- Parameters
prob_type (str) – Type of probability description. Options are ‘kde’ (weighted kernel density estimate), ‘rv’ (random variable), ‘gmm’ (Gaussian mixture model), and ‘voronoi’.
prob_parameters – Parameters that define the probability measure of type prob_type
vals (
numpy.ndarray
) – Values at which to evaluate the PDF.i (int) – index of marginal
- Returns
marginal probability density evaluated at vals
:rtype numpy.ndarray
- exception bet.sample.length_not_matching¶
Bases:
Exception
Exception for when the length of the array is inconsistent.
- class bet.sample.rectangle_sample_set(dim)¶
Bases:
bet.sample.sample_set_base
A data structure containing arrays specific to a set of samples defining a hyperrectangle discretization.
A series of n hyperrectangles \(A_i \subset \Lambda\) with \(A_i \cap A_j = \emptyset\) for \(i \neq j\). The last entry represents the remainder \(\Lambda \setminus ( \cup_{i-1}^n A_i)\).
- append_error_estimates(new_error_estimates)¶
Does nothing for this type of sample set.
Note
Remember to update the other member attribute arrays so that
check_num()
does not fail.- Parameters
new_error_estimates (
numpy.ndarray
of shape (num,)) – New error_estimates to append.
- append_jacobians(new_jacobians)¶
Does nothing for this type of sample set.
Note
Remember to update the other member attribute arrays so that
check_num()
does not fail.- Parameters
new_jacobians (
numpy.ndarray
of shape (num, other_dim, dim)) – New jacobians to append.
- append_values(values)¶
Does nothing for this type of sample_set.
See also
numpy.concatenate()
- Parameters
values (
numpy.ndarray
of shape (some_num, dim)) – values to append
- append_values_local(values_local)¶
Does nothing for this type of sample_set.
See also
numpy.concatenate()
- Parameters
values_local (
numpy.ndarray
of shape (some_num, dim)) – values to append
- exact_volume_lebesgue()¶
Exactly calculates the Lebesgue volume fraction of the cells.
- query(x, k=1)¶
Identify which value points x are associated with for discretization. Only returns the neighbors for which \(x_i \in A_k\). The distance is set to 0 if it is in the rectangle and infinity if it is not. It is only considered in or out.
See also
scipy.spatial.KDTree.query()
- Parameters
x (
numpy.ndarray
of shape(*, dim)
) – points for queryk (int) – number of nearest neighbors to return
- Return type
tuple
- Returns
(dist, ptr)
- setup(maxes, mins)¶
Initialization
- Parameters
maxes (iterable with components of length dim) – array or list of maxes for hyperrectangles
mins (iterable with components of length dim) – array or list of mins for hyperrectangles
- update_bounds(num=None)¶
Does nothing for this type of sample set.
- update_bounds_local(num_local=None)¶
Does nothing for this type of sample set.
- class bet.sample.sample_set(dim)¶
Bases:
bet.sample.voronoi_sample_set
Set Voronoi cells as the default for now.
- class bet.sample.sample_set_base(dim)¶
Bases:
object
A data structure containing values that define a set of samples.
- append_error_estimates(new_error_estimates)¶
Appends the
new_error_estimates
toself._error_estimates
.Note
Remember to update the other member attribute arrays so that
check_num()
does not fail.- Parameters
new_error_estimates (
numpy.ndarray
of shape (num,)) – New error_estimates to append.
- append_jacobians(new_jacobians)¶
Appends the
new_jacobians
toself._jacobians
.Note
Remember to update the other member attribute arrays so that
check_num()
does not fail.- Parameters
new_jacobians (
numpy.ndarray
of shape (num, other_dim, dim)) – New jacobians to append.
- append_values(values)¶
Appends the values in
_values
toself._values
.See also
numpy.concatenate()
- Parameters
values (
numpy.ndarray
of shape (some_num, dim)) – values to append
- append_values_local(values_local)¶
Appends the values in
_values_local
toself._values
.See also
numpy.concatenate()
- Parameters
values_local (
numpy.ndarray
of shape (some_num, dim)) – values to append
- array_names = ['_values', '_volumes', '_probabilities', '_densities', '_jacobians', '_error_estimates', '_right', '_left', '_width', '_kdtree_values', '_radii', '_normalized_radii', '_region', '_error_id']¶
List of global attribute names for attributes that are
numpy.ndarray
- calculate_volumes()¶
Calculate the volumes of cells. Depends on sample set type.
- check_num()¶
Checks that the number of entries in
self._values
,self._volumes
,self._probabilities
,self._jacobians
, andself._error_estimates
all match (assuming the named array exists).- Return type
- Returns
num
- check_num_local()¶
Checks that the number of entries in
self._values_local
,self._volumes_local
,self._probabilities_local
,self._jacobians_local
, andself._error_estimates_local
all match (assuming the named array exists).- Return type
- Returns
num
- clip(cnum)¶
Creates and returns a sample set with the the first cnum entries of the sample set.
- Parameters
cnum (int) – number of values of sample set to return
- Return type
- Returns
the clipped sample set
- copy()¶
Makes a copy using
numpy.copy()
.- Return type
- Returns
Copy of this
sample_set_base
- estimate_volume(n_mc_points=10000)¶
Calculate the volume faction of cells approximately using Monte Carlo integration.
- Parameters
n_mc_points (int) – If estimate is True, number of MC points to use
- estimate_volume_emulated(emulated_sample_set)¶
Calculate the volume faction of cells approximately using Monte Carlo integration.
Note
This could be re-written to just use an
emulated_ii_ptr
instead of anemulated_sample_set
.- Parameters
emulated_sample_set (
bet.sample.sample_set_base
) – The set of samples used to approximate the volume measure.
- estimate_volume_mc(globalize=True)¶
Give all cells the same volume fraction based on the Monte Carlo assumption.
- get_bounding_box()¶
Get the bounding box of the values.
- get_cluster_maps()¶
Returns cluster maps.
- get_densities()¶
Returns sample densities.
- Return type
numpy.ndarray
of shape (num,)- Returns
sample densities
- get_densities_local()¶
Returns sample local densities.
- Return type
- Returns
sample local densities
- get_dim()¶
Return the dimension of the sample space.
- Return type
- Returns
Dimension of the sample space.
- get_domain()¶
Returns the sample domain,
- Return type
numpy.ndarray
of shape (dim, 2)- Returns
Sample domain
- get_error_estimates()¶
Returns sample error_estimates.
- Return type
numpy.ndarray
of shape (num,)- Returns
sample error_estimates
- get_error_estimates_local()¶
Returns sample error_estimates_local.
- Return type
numpy.ndarray
of shape (num,)- Returns
sample error_estimates_local
- get_error_id()¶
Returns error identifiers.
- get_error_id_local()¶
Returns local error identifier.
- get_jacobians()¶
Returns sample jacobians.
- Return type
numpy.ndarray
of shape (num, other_dim, dim)- Returns
sample jacobians
- get_jacobians_local()¶
Returns local sample jacobians.
- Return type
numpy.ndarray
of shape (num, other_dim, dim)- Returns
local sample jacobians
- get_kdtree()¶
Returns a
scipy.spatial.KDTree
for this set of samples.- Return type
scipy.spatial.KDTree
- Returns
scipy.spatial.KDTree
for this set of samples.
- get_label()¶
Returns label for set.
- get_labels()¶
Returns labels for each dimension of set.
- get_p_norm()¶
Returns p-norm for sample set
- get_prob_parameters()¶
Returns the updated probability measure parameters.
- get_prob_parameters_init()¶
Returns initial probability measure parameters.
- get_prob_type()¶
Returns the type of updated probability measure.
- get_prob_type_init()¶
Returns the type of initial probability measure.
- get_probabilities()¶
Returns sample probabilities.
- Return type
numpy.ndarray
of shape (num,)- Returns
sample probabilities
- get_probabilities_local()¶
Returns sample local probabilities.
- Return type
- Returns
sample local probabilities
- get_reference_value()¶
Returns the reference value of a sample set.
- get_region()¶
Returns region.
- get_region_local()¶
Returns local region.
- get_values()¶
Returns sample values.
- Return type
- Returns
sample values
- get_values_local()¶
Returns sample local values.
- Return type
- Returns
sample local values
- get_volumes()¶
Returns sample cell volumes.
- Return type
numpy.ndarray
of shape (num,)- Returns
sample cell volumes
- get_volumes_local()¶
Returns sample local volumes.
- Return type
- Returns
sample local volumes
- get_weights()¶
Returns weights of samples.
- get_weights_init()¶
Returns initial weights of samples
- global_to_local()¶
Makes local arrays from available global ones.
- local_to_global()¶
Makes global arrays from available local ones.
- marginal_pdf(vals, i)¶
Evaluate the marginal (with index i) probability density function of the updated probability measure at values.
- Parameters
vals (
numpy.ndarray
of shape (num_vals, dim) or (num_vals, )) – Values at which to evaluated the PDF.i (int) – index defining marginal
:return probability densities :rtype
numpy.ndarray
of shape (num_vals, )
- marginal_pdf_init(vals, i)¶
Evaluate the marginal (with index i) probability density function of the initial probability measure at values.
- Parameters
vals (
numpy.ndarray
of shape (num_vals, dim) or (num_vals, )) – Values at which to evaluated the PDF.i (int) – index defining marginal
:return probability densities :rtype
numpy.ndarray
of shape (num_vals, )
- meta_fields = ['_bounding_box', '_densities', '_densities_local', '_dim', '_domain', '_domain_original', '_error_estimates', '_error_estimates_local', '_error_id', '_error_id_local', '_jacobians', '_jacobians_local', '_kdtree_values', '_kdtree_values_local', '_left', '_left_local', '_local_index', '_normalized_radii', '_normalized_radii_local', '_p_norm', '_probabilities', '_probabilities_local', '_radii', '_radii_local', '_reference_value', '_region', '_region_local', '_right', '_right_local', '_values', '_values_local', '_volumes', '_volumes_local', '_width', '_width_local', '_prob_type', '_prob_type_init', '_prob_parameters', '_prob_parameters_init', '_label', '_labels', '_cluster_maps', '_weights', '_weights_init']¶
- normalize_domain()¶
Normalize the domain and attributes to a unit hyperbox.
- pdf(vals)¶
Evaluate the probability density function of the updated probability measure at values. :param vals: Values at which to evaluated the PDF. :type vals:
numpy.ndarray
of shape (num_vals, dim) :return probability densities :rtypenumpy.ndarray
of shape (num_vals, )
- pdf_init(vals)¶
Evaluate the probability density function of the initial probability measure at values. :param vals: Values at which to evaluated the PDF. :type vals:
numpy.ndarray
of shape (num_vals, dim) :return probability densities :rtypenumpy.ndarray
of shape (num_vals, )
- query(x, k=1)¶
Identify which value points x are associated with for discretization.
- Parameters
x (
numpy.ndarray
of shape(*, dim)
) – points for queryk (int) – number of nearest neighbors to return
- save(filename, globalize=True)¶
Save the set using pickle.
- set_bounding_box()¶
Set the bounding box of the values.
- set_cluster_maps(cluster_maps)¶
Sets cluster maps (generally coming from LUQ).
- Parameters
cluster_maps (list) – List of arrays containing values in each cluster.
- set_densities(densities=None)¶
Set sample densities.
- Parameters
densities (
numpy.ndarray
of shape (num,)) – sample densities
- set_densities_local(densities_local=None)¶
Set sample local densities.
- Parameters
densities_local (
numpy.ndarray
of shape (num,)) – local sample densities
- set_domain(domain)¶
Sets the domain.
- Parameters
domain (
numpy.ndarray
of shape (dim, 2)) – Sample domain
- set_error_estimates(error_estimates)¶
Returns sample error estimates.
- Parameters
error_estimates (
numpy.ndarray
of shape (num,)) – sample error estimates
- set_error_estimates_local(error_estimates_local)¶
Returns local sample error estimates.
- Parameters
error_estimates_local (
numpy.ndarray
of shape (num,)) – local sample error estimates
- set_error_id(error_id)¶
Sets error_id for sample set.
- Parameters
error_id (
numpy.ndarray
of shape (some_num, dim)) – array of error identifiers
- set_error_id_local(error_id)¶
Sets local error id for sample set.
- Parameters
error_id (
numpy.ndarray
of shape (some_num, dim)) – array of error identifiers
- set_jacobians(jacobians)¶
Returns sample jacobians.
- Parameters
jacobians (
numpy.ndarray
of shape (num, other_dim, dim)) – sample jacobians
- set_jacobians_local(jacobians_local)¶
Returns local sample jacobians.
- Parameters
jacobians_local (
numpy.ndarray
of shape (num, other_dim, dim)) – local sample jacobians
- set_kdtree()¶
Creates a
scipy.spatial.KDTree
for this set of samples.
- set_label(label)¶
Sets label for set. :param label: Label for set. :type label: str
- set_labels(labels)¶
Sets labels for each dimension of set. :param labels: list or tuple containing strings which label parameters in each dimension. :type labels: list or tuple of length dim :return:
- set_prob_parameters(prob_parameters)¶
Set updated probability measure parameters. :param prob_parameters: Updated probability measure parameters.
- set_prob_parameters_init(prob_parameters_init)¶
Set initial probability measure parameters. :param prob_parameters_init: Initial probability measure parameters.
- set_prob_type(prob_type)¶
Set the type of updated probability measure. :param prob_type: Type of updated probability measure (‘kde’, ‘gmm’, ‘voronoi’, ‘rv’) :type prob_type: str
- set_prob_type_init(prob_type_init)¶
Set the type of initial probability measure. :param prob_type_init: Type of initial probability measure (‘kde’, ‘gmm’, ‘voronoi’, ‘rv’) :type prob_type_init: str
- set_probabilities(probabilities)¶
Set sample probabilities.
- Parameters
probabilities (
numpy.ndarray
of shape (num,)) – sample probabilities
- set_probabilities_local(probabilities_local)¶
Set sample local probabilities.
- Parameters
probabilities_local (
numpy.ndarray
of shape (num,)) – local sample probabilities
- set_reference_value(ref_val)¶
Sets reference value for sample set.
- Parameters
ref_val (
numpy.ndarray
of shape (dim,)) – reference value
- set_region(region)¶
Sets region for sample set.
- Parameters
region – array of regions
- set_region_local(region)¶
Sets local region for sample set.
- Parameters
region – array of regions
- set_values(values)¶
Sets the sample values.
- Parameters
values (
numpy.ndarray
of shape (num, dim)) – sample values
- set_values_local(values_local)¶
Sets the local sample values.
- Parameters
values_local (
numpy.ndarray
of shape (local_num, dim)) – sample local values
- set_volumes(volumes)¶
Sets sample cell volumes.
- Parameters
volumes (
numpy.ndarray
of shape (num,)) – sample cell volumes
- set_volumes_local(volumes_local)¶
Sets local sample cell volumes.
- Parameters
volumes_local (
numpy.ndarray
of shape (num,)) – local sample cell volumes
- set_weights(weights)¶
Set weights for samples :type weights:
numpy.ndarray
of shape (num,) :param weights: weights of samples
- set_weights_init(weights)¶
Set initial weights for samples :type weights:
numpy.ndarray
of shape (num,) :param weights: initial weights of samples
- shape()¶
Returns the shape of
self._values
- Return type
tuple
- Returns
(num, dim)
- shape_local()¶
Returns the shape of
self._values_local
- Return type
tuple
- Returns
(local_num, dim)
- undo_normalize_domain()¶
Undoes normalization of the domain and attributes if they have been normalized.
- class bet.sample.voronoi_sample_set(dim)¶
Bases:
bet.sample.sample_set_base
A data structure containing arrays specific to a set of samples defining a Voronoi tesselation.
- estimate_local_volume(num_emulate_local=500, max_num_emulate=10000)¶
Estimates the volume fraction of the Voronoi cells associated with
samples
. Specifically we are calculating \(\mu_\Lambda(\mathcal(V)_{i,N} \cap A)/\mu_\Lambda(\Lambda)\). Here all of the samples are drawn from the generalized Lp uniform distribution.Note
If this
voronoi_sample_set
has exact/estimated radii of the Voronoi cell associated with each sample for a domain normalized to the unit hypercube (_normalized_radii
). Note that these are not centroidal Voronoi tesselations meaning that the centroid is NOT the generator of the Voronoi cell. What we desire for the radius is actually \(sup_{\lambda \in \mathcal{V}_{i, N}} d_v(\lambda, \lambda^{(i)})\).Todo
When we move away from domains defined on hypercubes this will need to be updated to use whatever
_in_domain
method exists.Volume of the L-p ball is obtained from Wang, X.. (2005). Volumes of Generalized Unit Balls. Mathematics Magazine, 78(5), 390-395. DOI 10.2307/30044198
- estimate_radii(n_mc_points=10000, normalize=True)¶
Calculate the radii of cells approximately using Monte Carlo integration.
Todo
This currently presumes a uniform Lesbegue measure on the
domain
. Currently the way this is writtenemulated_input_sample_set
is NOT used to calculate the volume. This should at least be an option.
- estimate_radii_and_volume(n_mc_points=10000, normalize=True)¶
Calculate the radii and volume faction of cells approximately using Monte Carlo integration.
Todo
This currently presumes a uniform Lesbegue measure on the
domain
. Currently the way this is writtenemulated_input_sample_set
is NOT used to calculate the volume. This should at least be an option.
- exact_volume_1D()¶
Exactly calculates the volume fraction of the Voronoi cells. Specifically we are calculating \(\mu_\Lambda(\mathcal(V)_{i,N} \cap A)/\mu_\Lambda(\Lambda)\).
- exact_volume_2D(side_ratio=0.25)¶
Exactly calculates the volume fraction of the Voronoi cells. Specifically we are calculating \(\mu_\Lambda(\mathcal(V)_{i,N} \cap A)/\mu_\Lambda(\Lambda)\).
- Parameters
side_ratio (float) – ratio of width to reflect across boundary
- merge(sset)¶
Merges a given sample set with this one by merging the values.
- Parameters
sset (
bet.sample.voronoi_sample_set
) – Sample set object to merge with.- Return type
- Returns
Merged discretization
- query(x, k=1)¶
Identify which value points x are associated with for discretization.
- Parameters
x (
numpy.ndarray
of shape(*, dim)
) – points for queryk (int) – number of nearest neighbors to return
- Return type
tuple
- Returns
(dist, ptr)
- exception bet.sample.wrong_input¶
Bases:
Exception
Exception for when the input is of the wrong type.
- exception bet.sample.wrong_p_norm¶
Bases:
Exception
Exception for when the dimension of the array is inconsistent.
bet.surrogates module¶
This module provides methods for generating and using surrogate models.
- class bet.surrogates.piecewise_polynomial_surrogate(input_disc)¶
Bases:
object
This class provides methods for generating a piecewise polynomial surrogate.
- calculate_prob_for_sample_set_region(s_set, regions, update_input=True)¶
Solves stochastic inverse problem based on surrogate points and the MC assumption. Calculates the probability of a regions of input space and error estimates for those probabilities.
- Param
s_set: sample set for which to calculate error
- Parameters
region (list) – list of regions of s_set for which to calculate error
update_input (bool) – whether or not to update probabilities and errror identifiers for input discretization
- Return type
tuple
- Returns
(probabilities,
error_estimates
), the probability and error estimates for the region
- generate_for_input_set(input_sample_set, order=0)¶
Generates a surrogate discretization based on the input discretization, for a user-defined input sample set. The output sample set values and error estimates are piecewise polynomially defined over input sample set cells from the input discretization. For order 0, both are piecewise constant. For order 1, values are piecewise linear (assuming Jacobians exist), and error estimates are piecewise constant.
- Parameters
input_sample_set – input sample set for surrogate discretization
order (int) – Polynomial order
- Return type
- Returns
discretization defining the surrogate model
bet.util module¶
This module contains general tools for BET including saving and loading objects, and reshaping objects. The most important methods are:
get_global_values
concatenates local arrays into global arrays.save_object
saves all types of objects.load_object
loads all types of saved objects.load_object_parallel
loads all types of saved parallel objects.
- bet.util.clean_data(data)¶
Clean data so that NaN->0, inf-> maxfloat, -inf-> -maxfloat
- Parameters
data (
numpy.ndarray
) – numerical object- Return type
- Returns
array of shape (data.shape)
- bet.util.fix_dimensions_data(data, dim=None)¶
Fix the dimensions of an input so that it is a
numpy.ndarray
of shape (N, dim).If
dim
is non-specified: Ifdata
is a non-iterable number assumes thatdim==1
. Ifdata
is a numpy array with len(shape) == 1 assumes thatdim==1
. Ifdata
is a numpy array with len(shape) == 2 assumes thatdim==shape[1]
.- Parameters
data – numerical object
dim (int) – The dimension of the “data” space.
- Return type
- Returns
array of shape (N, dim)
- bet.util.fix_dimensions_domain(domain)¶
Fix the dimensions of an input so that it is a
numpy.ndarray
of shape (dim, 2).- Parameters
vector (
collections.abc.Iterable
) – numerical object of at least length 2- Return type
- Retuns
array of shape (dim, 2)
- bet.util.fix_dimensions_vector(vector)¶
Fix the dimensions of an input so that it is a
numpy.ndarray
of shape (N,). :param vector: numerical object :rtype:numpy.ndarray
:returns: array of shape (N,)
- bet.util.fix_dimensions_vector_2darray(vector)¶
Fix the dimensions of an input so that it is a
numpy.ndarray
of shape (N,1).- Parameters
vector – numerical object
- Return type
- Returns
array of shape (N,1)
- bet.util.get_global_values(array, shape=None)¶
Concatenates local arrays into global array using
np.vstack()
.- Parameters
array – Array.
- Return type
- Returns
array
- bet.util.load_object(file_name, localize=False)¶
Load saved objects.
- bet.util.load_object_parallel(file_name)¶
Load saved paralell objects.
- Parameters
file_name (str) – Filename of object.
- Returns
The saved object
- bet.util.meshgrid_ndim(X)¶
Return coordinate matrix from two or more coordinate vectors. Handles a maximum of 10 vectors.
Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays (x1, x2,…, xn).
- Parameters
X (tuple) – A tuple containing the 1d coordinate arrays
- Return type
ndarray
of shape (num_grid_points,n)- Returns
X_new
Module contents¶
Butler, Estep, Tavener Method
This package provides tools for solving stochastic inverse problems using a
measure-theoretic. It is named for the developers of the key algorithm in
bet.calculateP.calculateP
.
Comm
provides a work around for users who do not which to install :program:mpi4py
.util
provides some general use methods for creating grids, checking/fixing dimensions, and globalizing arrays.calculateP
provides tools to approximate probabilities.sampling
provides various sampling algorithms.sensitivity
provides tools for approximating derivatives and optimally choosing quantities of interest.postProcess
provides plotting tools and tools to sort samples by probabilities.sample
provides data structures to store sets of samples and their associated arrays.surrogates
provides methods for generating and usingsurrogate models.