# `pymor.analyticalproblems.functions`¶

## Module Contents¶

### Classes¶

 `Function` Interface for `Parameter` dependent analytical functions. `ConstantFunction` A constant `Function` `GenericFunction` Wrapper making an arbitrary Python function between `NumPy arrays` a proper `Function`. `ExpressionFunction` Turns a Python expression given as a string into a `Function`. `LincombFunction` A `Function` representing a linear combination of `Functions`. `ProductFunction` A `Function` representing a product of `Functions`. `BitmapFunction` Define a 2D `Function` via a grayscale image. `EmpiricalInterpolatedFunction` Empirically interpolated `Function`. `EmpiricalInterpolatedFunctionFunctional` Interface for `Parameter` functionals. `EmpiricalInterpolatedFunctionBasisFunction` Interface for `Parameter` dependent analytical functions.
class pymor.analyticalproblems.functions.Function[source]

Interface for `Parameter` dependent analytical functions.

Every `Function` is a map of the form

```f(μ): Ω ⊆ R^d -> R^(shape_range)
```

The returned values are `NumPy arrays` of arbitrary (but fixed) shape. Note that NumPy distinguishes between one-dimensional arrays of length 1 (with shape `(1,)`) and zero-dimensional scalar arrays (with shape `()`). In pyMOR, we usually expect scalar-valued functions to have `shape_range == ()`.

While the function might raise an error if it is evaluated for an argument not in the domain Ω, the exact behavior is left undefined.

Functions are vectorized in the sense, that if `x.ndim == k`, then

```f(x, μ)[i0, i1, ..., i(k-2)] == f(x[i0, i1, ..., i(k-2)], μ).
```

In particular, `f(x, μ).shape == x.shape[:-1] + shape_range`.

dim_domain[source]

The dimension d > 0.

shape_range[source]

The shape of the function values.

__rmul__[source]
abstract evaluate(self, x, mu=None)[source]

Evaluate the function for given argument `x` and `parameter values` `mu`.

__call__(self, x, mu=None)[source]

Shorthand for `evaluate`.

__sub__(self, other)[source]
__rsub__(self, other)[source]
__mul__(self, other)[source]
__neg__(self)[source]
class pymor.analyticalproblems.functions.ConstantFunction(value=np.array(1.0), dim_domain=1, name=None)[source]

Bases: `Function`

A constant `Function`

Defined as

```f: R^d -> R^shape(c), f(x) = c
```

Parameters

value

The constant c.

dim_domain

The dimension d.

name

The name of the function.

__str__(self)[source]

Return str(self).

evaluate(self, x, mu=None)[source]

Evaluate the function for given argument `x` and `parameter values` `mu`.

class pymor.analyticalproblems.functions.GenericFunction(mapping, dim_domain=1, shape_range=(), parameters={}, name=None)[source]

Bases: `Function`

Wrapper making an arbitrary Python function between `NumPy arrays` a proper `Function`.

Note that a `GenericFunction` can only be `pickled` if the function it is wrapping can be pickled (cf. `dumps_function`). For this reason, it is usually preferable to use `ExpressionFunction` instead of `GenericFunction`.

Parameters

mapping

The function to wrap. If `parameters` is `None`, the function is of the form `mapping(x)`. If `parameters` is not `None`, the function has to have the signature `mapping(x, mu)`. Moreover, the function is expected to be vectorized, i.e.:

```mapping(x).shape == x.shape[:-1] + shape_range.
```
dim_domain

The dimension of the domain.

shape_range

The shape of the values returned by the mapping.

parameters

The `Parameters` the mapping accepts.

name

The name of the function.

__str__(self)[source]

Return str(self).

evaluate(self, x, mu=None)[source]

Evaluate the function for given argument `x` and `parameter values` `mu`.

class pymor.analyticalproblems.functions.ExpressionFunction(expression, dim_domain=1, parameters={}, values={}, variable='x', name=None)[source]

Turns a Python expression given as a string into a `Function`.

Some `NumPy` arithmetic functions like ‘sin’, ‘log’, ‘min’ are supported. For a full list see the `functions` class attribute.

Warning

`eval` is used to evaluate the given expression. Using this class with expression strings from untrusted sources will cause mayhem and destruction!

Parameters

expression

A Python expression of one variable and the `parameters`, given as a `str`.

dim_domain

The dimension of the domain.

parameters

The `Parameters` the expression accepts.

values

Dictionary of additional constants that can be used in `expression` with their corresponding value.

variable

Name of the input variable in the given expression.

name

The name of the function.

__reduce__(self)[source]

Helper for pickle.

__str__(self)[source]

Return str(self).

class pymor.analyticalproblems.functions.LincombFunction(functions, coefficients, name=None)[source]

Bases: `Function`

A `Function` representing a linear combination of `Functions`.

The linear coefficients can be provided either as scalars or as `ParameterFunctionals`.

Parameters

functions

List of `Functions` whose linear combination is formed.

coefficients

A list of linear coefficients. A linear coefficient can either be a fixed number or a `ParameterFunctional`.

name

Name of the function.

functions[source]
coefficients[source]
evaluate_coefficients(self, mu)[source]

Compute the linear coefficients for given `parameter values` `mu`.

evaluate(self, x, mu=None)[source]

Evaluate the function for given argument `x` and `parameter values` `mu`.

class pymor.analyticalproblems.functions.ProductFunction(functions, name=None)[source]

Bases: `Function`

A `Function` representing a product of `Functions`.

Parameters

functions

List of `Functions` whose product is formed.

name

Name of the function.

functions[source]
evaluate(self, x, mu=None)[source]

Evaluate the function for given argument `x` and `parameter values` `mu`.

class pymor.analyticalproblems.functions.BitmapFunction(filename, bounding_box=None, range=None)[source]

Bases: `Function`

Define a 2D `Function` via a grayscale image.

Parameters

filename

Path of the image representing the function.

bounding_box

Lower left and upper right coordinates of the domain of the function.

range

A pixel of value p is mapped to `(p / 255.) * range + range`.

dim_domain = 2[source]
shape_range = [][source]
evaluate(self, x, mu=None)[source]

Evaluate the function for given argument `x` and `parameter values` `mu`.

class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunction(function, interpolation_points, interpolation_matrix, triangular, snapshot_mus, snapshot_coefficients, evaluation_points=None, basis_evaluations=None, name=None)[source]

Empirically interpolated `Function`.

Instantiated by `interpolate_function`.

Parameters

function

The `Function` to interpolate.

interpolation_points

`NumPy array` containing the coordinates at which the function is interpolated. Typically `X[dofs]` where `X` is the array of evaluation points used for snapshot data generation and `dofs` is returned by `ei_greedy`.

interpolation_matrix

The interpolation matrix corresponding to the selected interpolation basis vectors and `interpolation_points` as returned by `pymor.algorithms.ei.ei_greedy`.

triangular

Whether or not `interpolation_matrix` is lower triangular with unit diagonal.

snapshot_mus

List of `parameter values` for which the snapshot data for `pymor.algorithms.ei.ei_greedy` has been computed.

snapshot_coefficients

Matrix of linear coefficients s.t. the i-th interpolation basis vector is given by a linear combination of the functions corresponding to `snapshot_mus` with the i-th row of `snapshot_coefficients` as coefficients. Returned by `ei_greedy` as `data['coefficients']`.

evaluation_points

Optional `NumPy array` of coordinates at which the function has been evaluated to obtain the snapshot data. If the same evaluation points are used to evaluate `EmpiricalInterpolatedFunction`, then re-evaluation of the snapshot data at the evaluation points can be avoided, when this argument is specified together with `basis_evaluations`.

basis_evaluations

Optional `NumPy array` of evaluations of the interpolation basis at `evaluation_points`. Corresponds to the `basis` return value of `ei_greedy`.

_update_coefficients(self, mu)[source]
_update_evaluation_points(self, x)[source]
class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionFunctional(interpolated_function, index)[source]

Interface for `Parameter` functionals.

A parameter functional is simply a function mapping `Parameters` to a number.

evaluate(self, mu=None)[source]

Evaluate the functional for given `parameter values` `mu`.

class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionBasisFunction(interpolated_function, index)[source]

Bases: `Function`

Interface for `Parameter` dependent analytical functions.

Every `Function` is a map of the form

```f(μ): Ω ⊆ R^d -> R^(shape_range)
```

The returned values are `NumPy arrays` of arbitrary (but fixed) shape. Note that NumPy distinguishes between one-dimensional arrays of length 1 (with shape `(1,)`) and zero-dimensional scalar arrays (with shape `()`). In pyMOR, we usually expect scalar-valued functions to have `shape_range == ()`.

While the function might raise an error if it is evaluated for an argument not in the domain Ω, the exact behavior is left undefined.

Functions are vectorized in the sense, that if `x.ndim == k`, then

```f(x, μ)[i0, i1, ..., i(k-2)] == f(x[i0, i1, ..., i(k-2)], μ).
```

In particular, `f(x, μ).shape == x.shape[:-1] + shape_range`.

dim_domain[source]

The dimension d > 0.

shape_range[source]

The shape of the function values.

evaluate(self, x, mu=None)[source]

Evaluate the function for given argument `x` and `parameter values` `mu`.