The MeanFunction Module

MeanFunction Module

The MeanFunction module contains classes used for constructing mean functions for GP emulators. A base MeanBase class is provided, which implements basic operations to combine fixed functions and fitting parameters. The basic operations f1 + f2, f1*f2, f1**f2 and f1(f2) are available, though not all possible combinations will make sense. Particular cases where combinations do not make sense often use classes that represent free fitting parameters, or if you attempt to raise a mean function to a power that is not independent of the inputs. These operations will create new derived classes MeanSum, MeanProduct, MeanPower, and MeanComposite, from which more complex regression functions can be formed. The derived sum, product, power, and composite mean classes call the necessary methods to compute the function and derivatives from the more basic classes and then combine them using sum, product, power, and chain rules for function evaluation and derivatives.

The basic building blocks are fixed mean functions, derived from FixedMean, and free parameters, represented by the Coefficient class. Incuded fixed functions include ConstantMean and LinearMean. Additional derived FixedMean functions can be created by initializing a new FixedMean instance where the user provides a fixed function and its derivative, and these can be combined to form arbitrarily complex mean functions. Future improvements will extend the number of pre-defined function options.

One implementation note: CompositeMean does not implement the Hessian, as computing this requires mixed partials involving inputs and parameters that are not normally implemented. If a composite mean is required with a Hessian Computation, the user must implement this.

Additionally, note that given mean function may have a number of parameters that depends on the shape of the input. Since the mean function does not store input, but rather provides a way to collate functions and derivatives together in a single object, the number of parameters can vary based on the inputs. This is particularly true for the provided PolynomialMean class, which fits a polynomial function of a fixed degree to each input parameter. Thus, the number of parameters depends on the input shape.

In addition to manually creating a mean function by composing fixed functions and fitting parameters, a MeanBase subclass can be created by using the MeanFunction function. MeanFunction is a functional interface for creating MeanBase subclasses from a string formula. The formula langauge supports the operations described above as expected (see below for some examples), with the option to first parse the formula using the Python library patsy before converting the terms to the respective subclasses of MeanBase. Formulas specify input variables using either x[i] or inputs[i] to represent the dependent variables, and can explicitly include a leading "y =" or "y ~" (which will be ignored). Optionally, named variables can be mapped to input dimensions by providing a dictionary mapping strings to integer indices. Any other variables in the formula will be assumed to be fitting coefficients. Note that the formula parser does not make any effort to simplify expressions (such as having identical terms or a term with redundant fitting parameters), so it is up to the user to get things correct. Converting a mean function instance to a string can be very helpful in determining if the parsing led to any problems, see below.

Example:

>>> from mogp_emulator.MeanFunction import Coefficient, LinearMean, MeanFunction
>>> mf1 = Coefficient() + Coefficient()*LinearMean()
>>> print(mf1)
c + c*x[0]
>>> mf2 = LinearMean(1)*LinearMean(2)
>>> print(mf2)
x[1]*x[2]
>>> mf3 = mf1(mf2)
>>> print(mf3)
c + c*x[1]*x[2]
>>> mf4 = Coefficient()*LinearMean()**2
>>> print(mf4)
c*x[0]^2
>>> mf5 = MeanFunction("x[0]")
>>> print(mf5)
c + c*x[0]
>>> mf6 = MeanFunction("y = a + b*x[0]", use_patsy=False)
>>> print(mf6)
c + c*x[0]
>>> mf7 = MeanFunction("a*b", {"a": 0, "b": 1})
>>> print(mf7)
c + c*x[0] + c*x[1] + c*x[0]*x[1]
mogp_emulator.MeanFunction.MeanFunction(formula, inputdict={}, use_patsy=True)

Create a mean function from a formula

This is the functional interface to creating a mean function from a string formula. This method takes a string as an input, an optional dictionary that map strings to integer indices in the input data, and an optional boolean flag that indicates if the user would like to have the formula parsed with patsy before being converted to a mean function.

The string formulas can be specified in several ways. The formula LHS is implicitly always "y = " or "y ~ ", though these can be explicitly provided as well. The RHS may contain a set of terms containing the add, multiply, power, and call operations much in the same way that the operations would be entered as regular python code. Parentheses are used to indicated prececence as well as the call operation, and square brackets indicate an indexing operation on the inputs. Inputs may be specified as either a string such as "x[0]", "inputs[0]", or a string that can be mapped to an integer index with the optional dictionary passed to the function. Any strings not representing operations or inputs as described above are interpreted as follows: if the string can be converted into a number, then it is interpreted as a ConstantMean fixed mean function object; otherwise it is assumed to represent a fitting coefficient. Note that this means many characters that do not represent operations within this mean function language but would not normally be considered as python variables will nonetheless be converted into fitting coefficients – it is up to the user to get this right.

Expressions that are repeated or redundant will not be simplified, so the user should take care that the provided expression is sensible as a mean function and will not cause problems when fitting.

Additional special cases to be aware of:

  • call cannot be used as a variable name, if this is parsed as a token an exception will be raised.
  • I is the identity operator, it simply returns the given value. It is useful if you wish to use patsy to evaluate a formula but protect a part of the string formula from being expanded based on the rules in patsy. If I is encountered in any other context, an exception will be raised.

Examples:

>>> from mogp_emulator.MeanFunction import MeanFunction
>>> mf1 = MeanFunction("x[0]")
>>> print(mf1)
c + c*x[0]
>>> mf2 = MeanFunction("y = a + b*x[0]", use_patsy=False)
>>> print(mf2)
c + c*x[0]
>>> mf3 = MeanFunction("a*b", {"a": 0, "b": 1})
>>> print(mf3)
c + c*x[0] + c*x[1] + c*x[0]*x[1]
Parameters:
  • formula (str) – string representing the desired mean function formula
  • inputdict (dict) – dictionary used to map variables to input indices. Maps strings to integer indices (must be non-negative). Optional, default is {}.
  • use_patsy (bool) – Boolean flag indicating if the string is to be parsed using patsy library. Optional, default is True. If patsy is not installed, the basic string parser will be used.
Returns:

New subclass of MeanBase implementing the given formula

Return type:

subclass of MeanBase (exact type will depend on the formula that is provided)

class mogp_emulator.MeanFunction.MeanBase

Base mean function class

The base class for the mean function implementation includes code for checking inputs and implements sum, product, power, and composition methods to allow more complicated functions to be built up from fixed functions and fitting coefficients. Subclasses need to implement the following methods:

  • get_n_params which returns the number of parameters for a given input size. This is usually a constant, but can be more complicated (such as the provided PolynomialMean class)
  • mean_f computes the mean function for the provided inputs and parameters
  • mean_deriv computes the derivative with respect to the parameters
  • mean_hessian computes the hessian with respect to the parameters
  • mean_inputderiv computes the derivate with respect to the inputs

The base class does not have any attributes, but subclasses will usually have some attributes that must be set and so are likely to need a __init__ method.

get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which possibly depends on x.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis).

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[0],) holding the value of the mean function for each input point.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_hessian(x, params)

Returns value of mean function Hessian wrt the parameters

Method to compute the value of the mean function Hessian with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, n_params, x.shape[0]) holding the value of the mean function second derivaties with respect to each parameter pair (first twp axes) for each input point (last axis).

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function Hessian with respect to the parameters evaluated at all input points, numpy array of shape (n_parmas, n_params, x.shape[0])

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis).

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray

class mogp_emulator.MeanFunction.MeanSum(f1, f2)

Class representing the sum of two mean functions

This derived class represents the sum of two mean functions, and does the necessary bookkeeping needed to compute the required function and derivatives. The code does not do any checks to confirm that it makes sense to add these particular mean functions – in particular, adding two Coefficient classes is the same as having a single one, but the code will not attempt to simplify this so it is up to the user to get it right.

Variables:
  • f1 – first MeanBase to be added
  • f2 – second MeanBase to be added
get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which possibly depends on x.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis).

For MeanSum, this method applies the sum rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[0],) holding the value of the mean function for each input point.

For MeanSum, this method applies the sum rule to the results of computing the mean for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_hessian(x, params)

Returns value of mean function Hessian wrt the parameters

Method to compute the value of the mean function Hessian with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, n_params, x.shape[0]) holding the value of the mean function second derivaties with respect to each parameter pair (first twp axes) for each input point (last axis).

For MeanSum, this method applies the sum rule to the results of computing the Hessian for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function Hessian with respect to the parameters evaluated at all input points, numpy array of shape (n_parmas, n_params, x.shape[0])

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis).

For MeanSum, this method applies the sum rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray

class mogp_emulator.MeanFunction.MeanProduct(f1, f2)

Class representing the product of two mean functions

This derived class represents the product of two mean functions, and does the necessary bookkeeping needed to compute the required function and derivatives. The code does not do any checks to confirm that it makes sense to multiply these particular mean functions – in particular, multiplying two Coefficient classes is the same as having a single one, but the code will not attempt to simplify this so it is up to the user to get it right.

Variables:
  • f1 – first MeanBase to be multiplied
  • f2 – second MeanBase to be multiplied
get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which possibly depends on x.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis).

For MeanProduct, this method applies the product rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[0],) holding the value of the mean function for each input point.

For MeanProduct, this method applies the product rule to the results of computing the mean for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_hessian(x, params)

Returns value of mean function Hessian wrt the parameters

Method to compute the value of the mean function Hessian with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, n_params, x.shape[0]) holding the value of the mean function second derivaties with respect to each parameter pair (first twp axes) for each input point (last axis).

For MeanProduct, this method applies the product rule to the results of computing the Hessian for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function Hessian with respect to the parameters evaluated at all input points, numpy array of shape (n_parmas, n_params, x.shape[0])

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis).

For MeanProduct, this method applies the product rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray

class mogp_emulator.MeanFunction.MeanPower(f1, f2)

Class representing a mean function raised to a power

This derived class represents a mean function raised to a power, and does the necessary bookkeeping needed to compute the required function and derivatives. The code requires that the exponent be either a Coefficient, ConstantMean, float, or int as the output of the exponent mean function must be independent of the inputs to make sense. If input is a float or int, a ConstantMean instance will be created.

Variables:
  • f1 – first MeanBase to be raised to the given exponent
  • f2 – second MeanBase indicating the exponent. Must be a Coefficient, ConstantMean, or float/int (from which a ConstantMean object will be created)
get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which possibly depends on x.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis).

For MeanPpwer, this method applies the power rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[0],) holding the value of the mean function for each input point.

For MeanProduct, this method applies the product rule to the results of computing the mean for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_hessian(x, params)

Returns value of mean function Hessian wrt the parameters

Method to compute the value of the mean function Hessian with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, n_params, x.shape[0]) holding the value of the mean function second derivaties with respect to each parameter pair (first twp axes) for each input point (last axis).

For MeanPower, this method applies the power rule to the results of computing the Hessian for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function Hessian with respect to the parameters evaluated at all input points, numpy array of shape (n_parmas, n_params, x.shape[0])

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis).

For MeanPower, this method applies the power rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray

class mogp_emulator.MeanFunction.MeanComposite(f1, f2)

Class representing the composition of two mean functions

This derived class represents the composition of two mean functions, and does the necessary bookkeeping needed to compute the required function and derivatives. The code does not do any checks to confirm that it makes sense to compose these particular mean functions – in particular, applying a Coefficient class to another function will simply wipe out the second function. This will not raise an error, but the code will not attempt to alert the user to this so it is up to the user to get it right.

Because the Hessian computation requires mixed partials that are not normally implemented in the MeanBase class, the Hessian computation is not currently implemented. If you require Hessian computation for a composite mean function, you must implement it yourself.

Note that since the outer function takes as its input the output of the second function, the outer function can only ever have an index of 0 due to the fixed output shape of a mean function. This will produce an error when attempting to evaluate the function or its derivatives, but will not cause an error when initializing a MeanComposite object.

Variables:
  • f1 – first MeanBase to be applied to the second
  • f2 – second MeanBase to be composed as the input to the first
get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which possibly depends on x.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis).

For MeanComposite, this method applies the chain rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[0],) holding the value of the mean function for each input point.

For MeanComposite, this method applies the output of the second function as input to the first function.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis).

For MeanComposite, this method applies the chain rule to the results of computing the derivative for the individual functions.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray

class mogp_emulator.MeanFunction.FixedMean(f, deriv=None)

Class representing a fixed mean function with no parameters

Class representing a mean function with a fixed function (and optional derivative) and no fitting parameters. The user must provide these functions when initializing the instance.

Variables:
  • f – fixed mean function, must be callable and take a single argument (the inputs)
  • deriv – fixed derivative function (optional if no derivatives are needed), must be callable and take a single argument (the inputs)
get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which possibly depends on x. For a FixedMean class, this is zero.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For FixedMean classes, there are no parameters so the params argument should be an array of length zero. Returns a numpy array of shape (n_params, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis). Since fixed means have no parameters, this will just be an array of zeros.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For FixedMean classes, there are no parameters so the params argument should be an array of length zero. Returns a numpy array of shape (x.shape[0],) holding the value of the mean function for each input point.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input (zero in this case)
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_hessian(x, params)

Returns value of mean function Hessian wrt the parameters

Method to compute the value of the mean function Hessian with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For FixedMean classes, there are no parameters so the params argument should be an array of length zero. Returns a numpy array of shape (n_params, n_params, x.shape[0]) holding the value of the mean function second derivaties with respect to each parameter pair (first twp axes) for each input point (last axis). Since fixed means have no parameters, this will just be an array of zeros.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function Hessian with respect to the parameters evaluated at all input points, numpy array of shape (n_parmas, n_params, x.shape[0])

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For FixedMean classes, there are no parameters so the params argument should be an array of length zero. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis).

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray

class mogp_emulator.MeanFunction.ConstantMean(val)

Class representing a constant fixed mean function

Subclass of FixedMean where the function is a constant, with the value provided when ConstantMean is initialized. Uses utility functions to bind the value to the fixed_f function and sets that as the f attribute.

Variables:
  • f – fixed mean function, must be callable and take a single argument (the inputs)
  • deriv – fixed derivative function (optional if no derivatives are needed), must be callable and take a single argument (the inputs)
class mogp_emulator.MeanFunction.LinearMean(index=0)

Class representing a linear fixed mean function

Subclass of FixedMean where the function is a linear function. By default the function is linear in the first input dimension, though any non-negative integer index can be provided to control which input is used in the linear function. Uses utility functions to bind the correct function to the fixed_f function and sets that as the f attribute and similar with the fixed_deriv utility function and the deriv attribute.

Variables:
  • f – fixed mean function, must be callable and take a single argument (the inputs)
  • deriv – fixed derivative function, must be callable and take a single argument (the inputs)
class mogp_emulator.MeanFunction.Coefficient

Class representing a single fitting parameter in a mean function

Class representing a mean function with single free fitting parameter. Does not require any internal state as the parameter value is stored/set externally through fitting routines.

get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which possibly depends on x. For a Coefficient class, this is always 1.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For Coefficient classes, the inputs are ignored and the derivative function returns one, broadcasting it appropriately given the shape of the inputs. Returns a numpy array of ones with shape (1, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis). Since coefficients are single parameters, this will just be an array of ones.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For Coefficient classes, the inputs are ignored and the function returns the value of the parameter broadcasting it appropriately given the shape of the inputs. Thus, the params argument should always be an array of length one. Returns a numpy array of shape (x.shape[0],) holding the value of the parameter for each input point.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input (one in this case)
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_hessian(x, params)

Returns value of mean function Hessian wrt the parameters

Method to compute the value of the mean function Hessian with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For Coefficient classes, there is only a single parameter so the params argument should be an array of length one. Returns a numpy array of shape (n_params, n_params, x.shape[0]) holding the value of the mean function second derivaties with respect to each parameter pair (first twp axes) for each input point (last axis). Since coefficients depend linearly on a single parameter, this will always be an array of zeros.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function Hessian with respect to the parameters evaluated at all input points, numpy array of shape (n_parmas, n_params, x.shape[0])

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. For Coefficient classes, there is a single parameters so the params argument should be an array of length one. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis). Since coefficients do not depend on the inputs, this is just an array of zeros.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray

class mogp_emulator.MeanFunction.PolynomialMean(degree)

Polynomial mean function class

A PolynomialMean is a mean function where every input dimension is fit to a fixed degree polynomial. The degree must be provided when creating the class instance. The number of parameters depends on the degree and the shape of the inputs, since a separate set of parameters are used for each input dimension.

Variables:degree – Polynomial degree, must be a positive integer
get_n_params(x)

Determine the number of parameters

Returns the number of parameters for the mean function, which depends on x.

Parameters:x (ndarray) – Input array
Returns:number of parameters
Return type:int
mean_deriv(x, params)

Returns value of mean function derivative wrt the parameters

Method to compute the value of the mean function derivative with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, x.shape[0]) holding the value of the mean function derivative with respect to each parameter (first axis) for each input point (second axis).

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the parameters evaluated at all input points, numpy array of shape (n_params, x.shape[0])

Return type:

ndarray

mean_f(x, params)

Returns value of mean function

Method to compute the value of the mean function for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[0],) holding the value of the mean function for each input point.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function evaluated at all input points, numpy array of shape (x.shape[0],)

Return type:

ndarray

mean_hessian(x, params)

Returns value of mean function Hessian wrt the parameters

Method to compute the value of the mean function Hessian with respect to the parameters for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (n_params, n_params, x.shape[0]) holding the value of the mean function second derivaties with respect to each parameter pair (first twp axes) for each input point (last axis). Since polynomial means depend linearly on all input parameters, this will always be an array of zeros.

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function Hessian with respect to the parameters evaluated at all input points, numpy array of shape (n_parmas, n_params, x.shape[0])

Return type:

ndarray

mean_inputderiv(x, params)

Returns value of mean function derivative wrt the inputs

Method to compute the value of the mean function derivative with respect to the inputs for the inputs and parameters provided. Shapes of x and params must be consistent based on the return value of the get_n_params method. Returns a numpy array of shape (x.shape[1], x.shape[0]) holding the value of the mean function derivative with respect to each input (first axis) for each input point (second axis).

Parameters:
  • x (ndarray) – Inputs, must be a 1D or 2D numpy array (if 1D a second dimension will be added)
  • params (ndarray) – Parameters, must be a 1D numpy array (of more than 1D will be flattened) and have the same length as the number of parameters required for the provided input
Returns:

Value of mean function derivative with respect to the inputs evaluated at all input points, numpy array of shape (x.shape[1], x.shape[0])

Return type:

ndarray