# Multivariate Expansion Worker#

template<class BasisEvaluatorType, typename MemorySpace = Kokkos::HostSpace>
class MultivariateExpansionWorker#

Defines a function in terms of the tensor product of unary basis functions.

• Cache memory managed elsewhere

$\begin{split} \text{cache} = \left[\begin{array}{c} \phi_1^0(x_1)\\ \phi_1^1(x_1)\\ \vdots \phi_1^{p_1}\\ \phi_2^0(x_2)\\ \vdots\\ \phi_2^{p_2}(x_2)\\ \vdots \\ \phi_d^{p_d}(x_d)\\ \frac{\partial}{\partial x_d}\phi_d^0(x_d)\\ \vdots\\ \frac{\partial}{\partial x_d}\phi_d^{p_d}(x_d)\\ \frac{\partial^2}{\partial x_d}\phi_d^0(x_d^2)\\ \vdots\\ \frac{\partial^2}{\partial x_d^2}\phi_d^{p_d}(x_d) \end{array} \right] \end{split}$

Template Parameters:

BasisEvaluatorType – The family of 1d basis functions to employ.

Public Types

using BasisType = BasisEvaluatorType#
using KokkosSpace = MemorySpace#

Public Functions

inline MultivariateExpansionWorker()#
inline MultivariateExpansionWorker(MultiIndexSet const &multiSet, BasisEvaluatorType const &basis1d = BasisEvaluatorType())#
inline MultivariateExpansionWorker(FixedMultiIndexSet<MemorySpace> const &multiSet, BasisEvaluatorType const &basis1d = BasisEvaluatorType())#
inline unsigned int CacheSize() const#

Returns the size of the cache needed to evaluate the expansion (in terms of number of doubles).

Returns:

unsigned int The length of the required cache vector.

inline unsigned int NumCoeffs() const#

Returns the number of coefficients in this expansion.

Returns:

unsigned int The number of terms in the multiindexset, which corresponds to the number of coefficients needed to define the expansion.

inline unsigned int InputSize() const#

Returns the dimension of inputs to this multivariate expansion.

Returns:

unsigned int The dimension of an input point.

template<typename PointType>
inline void FillCache1(double *polyCache, PointType const &pt, DerivativeFlags::DerivativeType derivType) const#

Precomputes parts of the cache using all but the last component of the point, i.e., using only $$x_1,x_2,\ldots,x_{d-1}$$, not $$x_d$$.

FillCache2

Template Parameters:

PointType – The vector type used to define the point. Can be anything allowing access to components with operator(). Examples are Kokkos::View<double*> or Eigen::VectorXd. Only the first d-1 components of the vector will be accessed in this function.

Parameters:
• polyCache – A pointer to the start of the cache. This memory must be allocated before calling this function.

• pt – The point (at least the first $$d-1$$ components) to use when filling in the cache.

• derivType

template<typename PointType>
inline void FillCache2(double *polyCache, PointType const&, double xd, DerivativeFlags::DerivativeType derivType) const#

Precomputes parts of the cache that depend on the $$d^{th}$$ component of the point $$x$$.

FillCache1

Template Parameters:

PointType – The vector type used to define the point. Can be anything allowing access to components with operator(). Examples are Kokkos::View<double*> or Eigen::VectorXd. Only the first d-1 components of the vector will be accessed in this function.

Parameters:
• polyCache – A pointer to the start of the cache. This memory must be allocated before calling this function.

• pt – The point to use when filling in the cache. Should contain $$[x_1,\ldots,x_{d-1}]$$. The vector itself can have more than $$d-1$$ components, but only the first $$d-1$$ will be accessed. The value of $$x_d$$ is passed through the xd argument.

• xd – The value of $$x_d$$. This is passed separate from $$[x_1,\ldots,x_{d-1}]$$ to make integrating over the last component more efficient. A copy of the point does not need to be created.

• derivType

template<typename CoeffVecType>
inline double Evaluate(const double *polyCache, CoeffVecType const &coeffs) const#
template<typename CoeffVecType>
inline double DiagonalDerivative(const double *polyCache, CoeffVecType const &coeffs, unsigned int derivOrder) const#

Evaluates the derivative of the expansion wrt x_{D-1}.

Template Parameters:

CoeffVecType

Parameters:
• polyCache

• coeffs

Returns:

double

Evaluates the expansion and also computes the gradient of the expansion output wrt the coefficients.

Using cached values in the “polyCache” argument and coefficients $$\theta$$ from the coeffs argument, this function returns the value of the expansion $$f(x;\theta)$$ and computes the gradient $$\nabla_\theta f$$ of the expansion output with respect to the coefficients $$\theta$$.

Template Parameters:
• CoeffVecType

Parameters:
• polyCache

• coeffs

• grad – A vector that will be updated with the scaled gradient. This is the vector $$g$$ in the expression above.

• gradScale – The scaling $$\alpha$$ used in the expression above.

Computes the gradient $$\nabla_x f(x_{1:d})$$ with respect to the input $$x$$.

Parameters:
• polyCache[in] – Cache vector that has been set up by calling both FillCache1 and FillCache2 with DerivativeFlags::Input

• coeffs[in] – Vector of coefficients. Must have parentheses access operator.

Returns:

The value of $f(x_{1:d})$.

Computes the gradient of the diagonal derivative $$\nabla_x \partial_d f(x_{1:d})$$ with respect to the input $$x$$.

Parameters:
• polyCache[in] – Cache vector that has been set up by calling both FillCache1 and FillCache2 with DerivativeFlags::MixedInput

• coeffs[in] – Vector of coefficients. Must have parentheses access operator.

Returns:

The value of $\partial_d f(x_{1:d})$.

inline double MixedCoeffDerivative(const double *cache, CoeffVecType const &coeffs, unsigned int derivOrder, GradVecType &grad) const#

Computes the gradient of the diagonal derivative $$\nabla_w \partial_d f(x_1:d; w)$$ with respect to the parameters.

Parameters:
• polyCache[in] – Cache vector that has been set up by calling both FillCache1 and FillCache2 with DerivativeFlags::Mixed

• coeffs[in] – Vector of coefficients. Must have parentheses access operator.

The value of $\partial_d f(x_{1:d})$.