pymor.parameters.base¶
This module contains the implementation of pyMOR’s parameter handling facilities.
Use the ParametricObject base class to define immutable (mathematical) objects that
depend on some Parameters. Each Parameter in pyMOR has a name and a fixed dimension
(number of scalar components of the parameter vector). In particular, scalar parameters
are treated as parameter vectors of dimension 1. Mappings of Parameters to
parameter values are stored in pyMOR using dedicated Mu objects.
To sample parameter values within a given range, ParameterSpace objects can be used.
Module Contents¶
- class pymor.parameters.base.Mu(*args, **kwargs)[source]¶
Bases:
pymor.tools.frozendict.FrozenDictImmutable mapping of
Parameternames to parameter values.Parameters
Anything that dict accepts for the construction of a dictionary. Values are automatically converted to one-dimensional
NumPy arrays, except forFunctionswhich are interpreted as time-dependent parameter values. Unless the Python interpreter runs with the-Oflag, the arrays are made immutable.- parameters[source]¶
The
Parametersto which the mapping assigns values.
Methods
Compare dicts of
parameter valuesusingfloat_cmp_all.D.copy() -> a shallow copy of D
Return time-dependent
Functionfor given parameter.Check whether the values for a given parameter depend on time.
All parameter values as a NumPy array, ordered alphabetically.
- allclose(mu)[source]¶
Compare dicts of
parameter valuesusingfloat_cmp_all.Parameters
- mu
The
parameter valueswith which to compare.
Returns
Trueif bothparameter valuedicts contain values for the sameParametersand all components of the parameter values are almost equal, elseFalse.
- get_time_dependent_value(param)[source]¶
Return time-dependent
Functionfor given parameter.Parameters
- param
The parameter for which to return the time-dependent values.
Returns
If
paramdepends on time, this correspondingFunction(and not its evaluation at the current time) is returned. Ifparamis not given by aFunction, aConstantFunctionis returned.
- class pymor.parameters.base.ParameterSpace(parameters, *ranges)[source]¶
Bases:
ParametricObjectA set of
Parameterswith allowed ranges for their values.ParameterSpacesare mostly used to create sample set ofparameter valuesfor givenParameterswithin a specified range.Parameters
- parameters
The
Parameterswhich are part of the space.- ranges
Allowed ranges for the
parameter values. Either:two numbers specifying the lower and upper bound for all parameter value components,
a list/tuple of two numbers specifying these bounds,
or a dict of those tuples, specifying upper and lower bounds individually for each parameter of the space.
Methods
Clip (limit)
parameter valuesto the space's parameter ranges.Logarithmically scaled random sample
parameter valuesfrom the space.Logarithmically uniform sample
parameter valuesfrom the space.Randomly sample
parameter valuesfrom the space.Uniformly sample
parameter valuesfrom the space.- clip(mu, keep_additional=False)[source]¶
Clip (limit)
parameter valuesto the space’s parameter ranges.Parameters
- mu
Parameter valueto clip.- keep_additional
If
True, keep additional values in theMuinstance which are not contained in the parameters, e.g. time parameters.
Returns
The clipped
parameter values.
- sample_logarithmic_randomly(count=None)[source]¶
Logarithmically scaled random sample
parameter valuesfrom the space.Parameters
- count
If
None, a single dictmuofparameter valuesis returned. Otherwise, the number of logarithmically random samples to generate and return as a list ofparameter valuesdicts.
Returns
The sampled
parameter values.
- sample_logarithmic_uniformly(counts)[source]¶
Logarithmically uniform sample
parameter valuesfrom the space.Parameters
- counts
Number of samples to take per parameter and component of the parameter. Either a dict of counts per
Parameteror a single count that is taken for each parameter inParameters.
Returns
List of
parameter valuedicts.
- sample_randomly(count=None)[source]¶
Randomly sample
parameter valuesfrom the space.Parameters
- count
If
None, a single dictmuofparameter valuesis returned. Otherwise, the number of random samples to generate and return as a list ofparameter valuesdicts.
Returns
The sampled
parameter values.
- sample_uniformly(counts)[source]¶
Uniformly sample
parameter valuesfrom the space.Parameters
- counts
Number of samples to take per parameter and component of the parameter. Either a dict of counts per
Parameteror a single count that is taken for each parameter inParameters.
Returns
List of
parameter valuedicts.
- class pymor.parameters.base.Parameters(*args, **kwargs)[source]¶
Bases:
pymor.tools.frozendict.SortedFrozenDictImmutable dict mapping parameter names to parameter dimensions.
Each key of a
Parametersdict is a string specifying the name of a parameter. The corresponding value is a non-negativeintspecifying the dimension (number of scalar components) of the parameter.Methods
Assert that
parameter valuesare compatible with the givenParameters.Check if
parameter valuesare compatible with the givenParameters.Computes the total set of
Parametersa collection of objects depends on.Interpret
muas a set ofparameter valuesaccording to the givenParameters.Create a
ParameterSpacewith given ranges.- assert_compatible(mu)[source]¶
Assert that
parameter valuesare compatible with the givenParameters.Each of the parameter must be contained in
muand the dimensions have to match, i.e.mu[parameter].size == self[parameter]
Otherwise, an
AssertionErrorwill be raised.
- is_compatible(mu)[source]¶
Check if
parameter valuesare compatible with the givenParameters.Each of the parameter must be contained in
muand the dimensions have to match, i.e.mu[parameter].size == self[parameter]
- classmethod of(*args)[source]¶
Computes the total set of
Parametersa collection of objects depends on.If two objects depend on a parameter with the same name, both parameters must have the same dimension.
Parameters
- args
Each positional argument must either be
None, aParametricObjector lists, tuples, dicts orNumPy arraysof such objects. The latter will be traversed recursively.
- parse(mu)[source]¶
Interpret
muas a set ofparameter valuesaccording to the givenParameters.Depending on the
Parameters,mucan be given as a dict, list, tuple,NumPy arrayor scalar. In the latter cases, multiple parameters will be concatenated by alphabetical ordering. E.g.:Parameters(b=2, a=1).parse([1,2,3])
will assign to parameter
athe value[1]and to parameterbthe values[2, 3]. Further, each parameter value can be given as a vector-valuedFunctionwithdim_domain == 1to specify time-dependent values. Astris converted to an appropriateExpressionFunction.Parameters
- mu
The user input which shall be interpreted as
parameter values.
Returns
The resulting object of
parameter values.Raises
- ValueError
Is raised if
mucannot be interpreted asparameter valuesfor the givenParameters.
- space(*ranges)[source]¶
Create a
ParameterSpacewith given ranges.This is a shorthand for
ParameterSpace(self, *range)
See
ParameterSpacefor allowed range arguments.
- class pymor.parameters.base.ParametricObject[source]¶
Bases:
pymor.core.base.ImmutableObjectBase class for immutable mathematical entities depending on some
Parameters.Each
ParametricObjectlists theParametersit depends on in theparametersattribute. Usually, theseParametersare automatically derived as the union of allParametersof the object’s__init__arguments.Additional
Parametersintroduced by the object itself can be specified by setting theparameters_ownattribute in__init__. In case the object fixes someParametersit’s child objects depend on to concrete values, thoseParameterscan be removed from theparametersattribute by settingparameters_internal.Alternatively,
parameterscan be initialized manually in__init__.- parameters[source]¶
The
Parametersthe object depends on.
- parameters_own[source]¶
The
Parametersthe object depends on which are not inherited from a child object the object depends on. Each item ofparameters_ownis also an item ofparameters.
- parameters_inherited[source]¶
The
Parametersthe object depends on because some child object depends on them. Each item ofparameters_ownis also an item ofparameters.
- parameters_internal[source]¶
The
Parameterssome of the object’s child objects may depend on, but which are fixed to a concrete value by this object. All items ofparameters_internalare removed fromparametersandparameters_inherited. When initializingparameters_ownandparameters_internal, it has to be ensured that both dicts are disjoint.
- parametric[source]¶
Trueif the object really depends on a parameter, i.e.parametersis not empty.