mlmc.quantity¶
Subpackage provides methods to represent and handle a quantity of interest.
Submodules¶
mlmc.quantity.quantity module¶
-
class
mlmc.quantity.quantity.
Quantity
(quantity_type, operation, input_quantities=[])[source]¶ Bases:
object
-
static
create_quantity
(quantities, operation)[source]¶ Create new quantity (Quantity or QuantityConst) based on given quantities and operation. There are two scenarios: 1. At least one of quantities is Quantity instance then all quantities are considered to be input_quantities
of new Quantity2. All of quantities are QuantityConst instances then new QuantityConst is created :param quantities: List[Quantity] :param operation: function which is run with given quantities :return: Quantity
-
static
pick_samples
(chunk, subsample_params)[source]¶ Pick samples some samples from chunk in order to have ‘k’ samples from ‘n’ after all chunks are processed Inspired by https://dl.acm.org/doi/10.1145/23002.23003 method S
Parameters: - chunk – np.ndarray, shape M, N, 2, where N denotes number of samples in chunk
- subsample_params – instance of SubsampleParams class, it has two parameters: k: number of samples which we want to get from all chunks n: number of all samples among all chunks
Returns: np.ndarray
-
samples
(chunk_spec)[source]¶ Return list of sample chunks for individual levels. Possibly calls underlying quantities. :param chunk_spec: object containing chunk identifier level identifier and chunk_slice - slice() object :return: np.ndarray or None
-
select
(*args)[source]¶ Performs sample selection based on conditions :param args: Quantity :return: Quantity
-
set_selection_id
()[source]¶ Set selection id selection id is None by default,
but if we create new quantity from quantities that are result of selection we need to pass selection id
-
static
-
class
mlmc.quantity.quantity.
QuantityConst
(quantity_type, value)[source]¶
-
class
mlmc.quantity.quantity.
QuantityMean
(quantity_type, l_means, l_vars, n_samples, n_rm_samples)[source]¶ Bases:
object
-
l_means
¶
-
l_vars
¶
-
mean
¶
-
n_rm_samples
¶
-
n_samples
¶
-
var
¶
-
-
class
mlmc.quantity.quantity.
QuantityStorage
(storage, qtype)[source]¶
-
mlmc.quantity.quantity.
make_root_quantity
(storage: mlmc.sample_storage.SampleStorage, q_specs: List[mlmc.quantity.quantity_spec.QuantitySpec])[source]¶ Create a root quantity that has QuantityStorage as the input quantity, QuantityStorage is the only class that directly accesses the stored data. Quantity type is created based on the q_spec parameter :param storage: SampleStorage :param q_specs: same as result format in simulation class :return: QuantityStorage
mlmc.quantity.quantity_estimate module¶
-
mlmc.quantity.quantity_estimate.
covariance
(quantity, moments_fn, cov_at_bottom=True)[source]¶ Create quantity with operation that evaluates covariance matrix :param quantity: Quantity :param moments_fn: mlmc.moments.Moments child :param cov_at_bottom: bool, if True cov matrices are underneath,
a scalar is substituted with a matrix of moments of that scalarReturns: Quantity
-
mlmc.quantity.quantity_estimate.
estimate_mean
(quantity)[source]¶ MLMC mean estimator. The MLMC method is used to compute the mean estimate to the Quantity dependent on the collected samples. The squared error of the estimate (the estimator variance) is estimated using the central limit theorem. Data is processed by chunks, so that it also supports big data processing :param quantity: Quantity :return: QuantityMean which holds both mean and variance
-
mlmc.quantity.quantity_estimate.
mask_nan_samples
(chunk)[source]¶ Mask out samples that contain NaN in either fine or coarse part of the result :param chunk: np.ndarray [M, chunk_size, 2] :return: chunk: np.ndarray, number of masked samples: int
-
mlmc.quantity.quantity_estimate.
moment
(quantity, moments_fn, i=0)[source]¶ Create quantity with operation that evaluates particular moment :param quantity: Quantity instance :param moments_fn: mlmc.moments.Moments child :param i: index of moment :return: Quantity
-
mlmc.quantity.quantity_estimate.
moments
(quantity, moments_fn, mom_at_bottom=True)[source]¶ Create quantity with operation that evaluates moments_fn :param quantity: Quantity :param moments_fn: mlmc.moments.Moments child :param mom_at_bottom: bool, if True moments are underneath,
a scalar is substituted with an array of moments of that scalarReturns: Quantity
mlmc.quantity.quantity_spec module¶
mlmc.quantity.quantity_types module¶
-
class
mlmc.quantity.quantity_types.
ArrayType
(shape, qtype: mlmc.quantity.quantity_types.QType)[source]¶
-
class
mlmc.quantity.quantity_types.
DictType
(args: List[Tuple[str, mlmc.quantity.quantity_types.QType]])[source]¶
-
class
mlmc.quantity.quantity_types.
FieldType
(args: List[Tuple[str, mlmc.quantity.quantity_types.QType]])[source]¶
-
class
mlmc.quantity.quantity_types.
QType
(qtype)[source]¶ Bases:
object
-
static
keep_dims
(chunk)[source]¶ Always keep chunk shape to be [M, chunk size, 2]! For scalar quantities, the input block can have the shape (chunk size, 2) Sometimes we need to ‘flatten’ first few shape to have desired chunk shape :param chunk: list :return: list
-
static
-
class
mlmc.quantity.quantity_types.
ScalarType
(qtype=<class 'float'>)[source]¶
Module contents¶
Subpackage provides methods to represent and handle a quantity of interest.