shark::KernelBasisDistance Class Reference

Computes the squared distance between the optimal point in a basis to the point represented by a KernelExpansion. More...

#include <shark/ObjectiveFunctions/KernelBasisDistance.h>

+ Inheritance diagram for shark::KernelBasisDistance:

Public Member Functions

SHARK_EXPORT_SYMBOL KernelBasisDistance (KernelExpansion< RealVector > *kernelExpansion, std::size_t numApproximatingVectors=1)
 Constructs the objective function. More...
 
std::string name () const
 Returns the name of the class. More...
 
std::size_t numApproximatingVectors () const
 Returns the number of vectors the uses to approximate the point - the basis size. More...
 
std::size_t & numApproximatingVectors ()
 Returns a reference the number of vectors the uses to approximate the point - the basis size. More...
 
SHARK_EXPORT_SYMBOL SearchPointType proposeStartingPoint () const
 Returns a starting point of the algorithm. More...
 
SHARK_EXPORT_SYMBOL std::size_t numberOfVariables () const
 Returns the number of variables of the function. More...
 
SHARK_EXPORT_SYMBOL RealMatrix findOptimalBeta (RealVector const &input) const
 Given an input basis, returns the point with the minimum error. More...
 
SHARK_EXPORT_SYMBOL double eval (RealVector const &input) const
 Evaluate the (sum of) squared distance(s) between the closes point in the basis to the point(s) represented by the kernel expansion. More...
 
SHARK_EXPORT_SYMBOL ResultType evalDerivative (const SearchPointType &input, FirstOrderDerivative &derivative) const
 computes the derivative of the function with respect to the supplied basis. More...
 
- Public Member Functions inherited from shark::AbstractObjectiveFunction< RealVector, double >
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasValue () const
 returns whether this function can calculate it's function value More...
 
bool hasFirstDerivative () const
 returns whether this function can calculate the first derivative More...
 
bool hasSecondDerivative () const
 returns whether this function can calculate the second derivative More...
 
bool canProposeStartingPoint () const
 returns whether this function can propose a starting point. More...
 
bool isConstrained () const
 returns whether this function can return More...
 
bool hasConstraintHandler () const
 returns whether this function can return More...
 
bool canProvideClosestFeasible () const
 Returns whether this function can calculate thee closest feasible to an infeasible point. More...
 
bool isThreadSafe () const
 Returns true, when the function can be usd in parallel threads. More...
 
bool isNoisy () const
 Returns true, when the function can be usd in parallel threads. More...
 
 AbstractObjectiveFunction ()
 Default ctor. More...
 
virtual ~AbstractObjectiveFunction ()
 Virtual destructor. More...
 
virtual void init ()
 
virtual bool hasScalableDimensionality () const
 
virtual void setNumberOfVariables (std::size_t numberOfVariables)
 Adjusts the number of variables if the function is scalable. More...
 
virtual std::size_t numberOfObjectives () const
 
virtual bool hasScalableObjectives () const
 
virtual void setNumberOfObjectives (std::size_t numberOfObjectives)
 Adjusts the number of objectives if the function is scalable. More...
 
std::size_t evaluationCounter () const
 Accesses the evaluation counter of the function. More...
 
AbstractConstraintHandler< SearchPointType > const & getConstraintHandler () const
 Returns the constraint handler of the function if it has one. More...
 
virtual bool isFeasible (const SearchPointType &input) const
 Tests whether a point in SearchSpace is feasible, e.g., whether the constraints are fulfilled. More...
 
virtual void closestFeasible (SearchPointType &input) const
 If supported, the supplied point is repaired such that it satisfies all of the function's constraints. More...
 
ResultType operator() (SearchPointType const &input) const
 Evaluates the function. Useful together with STL-Algorithms like std::transform. More...
 
virtual ResultType evalDerivative (SearchPointType const &input, SecondOrderDerivative &derivative) const
 Evaluates the objective function and calculates its gradient. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 

Additional Inherited Members

- Public Types inherited from shark::AbstractObjectiveFunction< RealVector, double >
enum  Feature
 List of features that are supported by an implementation. More...
 
typedef RealVector SearchPointType
 
typedef double ResultType
 
typedef boost::mpl::if_< std::is_arithmetic< double >, SearchPointType, RealMatrix >::type FirstOrderDerivative
 
typedef TypedFlags< FeatureFeatures
 This statement declares the member m_features. See Core/Flags.h for details. More...
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Protected Member Functions inherited from shark::AbstractObjectiveFunction< RealVector, double >
void announceConstraintHandler (AbstractConstraintHandler< SearchPointType > const *handler)
 helper function which is called to announce the presence of an constraint handler. More...
 
- Protected Attributes inherited from shark::AbstractObjectiveFunction< RealVector, double >
Features m_features
 
std::size_t m_evaluationCounter
 Evaluation counter, default value: 0. More...
 
AbstractConstraintHandler< SearchPointType > const * m_constraintHandler
 

Detailed Description

Computes the squared distance between the optimal point in a basis to the point represented by a KernelExpansion.

Assume we are given a kernel expansion \( w = \sum_i \alpha_i k(x_i, \cdot) \). The KernelBasisDistance takes a new set of basis vectors \( z_i \) and finds the linear combination in that space which is closest to \( w \) . More formally the function measures the squared distance in the kernel-induced feature space:

\[ f(z) = \min_{\beta} \frac 1 2 \| \sum_j \beta_j k(z_j, \cdot) - w \|^2 . \]

In vector notation with \( (K_x)_{i,j} = k(x_i,x_j) \), \( (K_z)_{i,j} = k(z_i,z_j) \) and \( (K_{zx})_{i,j} = k(z_i,x_j) \) it computes:

\[ f(z) = \min_{\beta} \frac 1 2 \beta^T K_z \beta - \beta^T K_{zx} \alpha + \frac 1 2 \alpha^TK_x \alpha . \]

The last term is independent of \( z_i \). Thus it is omitted in the actual computation. That is, the value is offset by a constant and the minimum is not 0. The input of the function consists of a vector which is the concatenation \( v=[z_1, z_2,\dots,z_k] \) of all basis vectors.

The target point \( w \) is set as a KernelExpansion in the constructor. If the kernel is differentiable with respect to the input point then this objective function is differentiable as well.

The kernel expansion can represent more than one single point, in this case the error is the sum of approximation errors.

Definition at line 53 of file KernelBasisDistance.h.

Constructor & Destructor Documentation

◆ KernelBasisDistance()

SHARK_EXPORT_SYMBOL shark::KernelBasisDistance::KernelBasisDistance ( KernelExpansion< RealVector > *  kernelExpansion,
std::size_t  numApproximatingVectors = 1 
)

Constructs the objective function.

This functions calls sparsify on the kernel expansion to save computation time in the case of sparse bases.

Parameters
kernelExpansiona pointer to the kernel expansion to approximate
numApproximatingVectorsthe number of vectors used to approximate the point - the basis size

Member Function Documentation

◆ eval()

SHARK_EXPORT_SYMBOL double shark::KernelBasisDistance::eval ( RealVector const &  input) const
virtual

Evaluate the (sum of) squared distance(s) between the closes point in the basis to the point(s) represented by the kernel expansion.

See the class description for more details on this computation.

Reimplemented from shark::AbstractObjectiveFunction< RealVector, double >.

Referenced by numApproximatingVectors().

◆ evalDerivative()

SHARK_EXPORT_SYMBOL ResultType shark::KernelBasisDistance::evalDerivative ( const SearchPointType input,
FirstOrderDerivative derivative 
) const
virtual

computes the derivative of the function with respect to the supplied basis.

Assume \( \beta \) to be the optimal value. Then the derivative with respect to the basis vectors is:

\[ \frac{ \partial f}{\partial z_l} = \beta_l \sum_i \beta_i \frac{ \partial f}{\partial z_l} k(z_l,z_i) - \beta_l \sum_i \alpha_i \frac{ \partial f}{\partial z_l} k(z_l, x_i) \]

Reimplemented from shark::AbstractObjectiveFunction< RealVector, double >.

Referenced by numApproximatingVectors().

◆ findOptimalBeta()

SHARK_EXPORT_SYMBOL RealMatrix shark::KernelBasisDistance::findOptimalBeta ( RealVector const &  input) const

Given an input basis, returns the point with the minimum error.

Referenced by numApproximatingVectors().

◆ name()

std::string shark::KernelBasisDistance::name ( ) const
inlinevirtual

Returns the name of the class.

Reimplemented from shark::INameable.

Definition at line 65 of file KernelBasisDistance.h.

◆ numApproximatingVectors() [1/2]

std::size_t shark::KernelBasisDistance::numApproximatingVectors ( ) const
inline

Returns the number of vectors the uses to approximate the point - the basis size.

Definition at line 69 of file KernelBasisDistance.h.

◆ numApproximatingVectors() [2/2]

std::size_t& shark::KernelBasisDistance::numApproximatingVectors ( )
inline

Returns a reference the number of vectors the uses to approximate the point - the basis size.

Definition at line 74 of file KernelBasisDistance.h.

References beta, eval(), evalDerivative(), findOptimalBeta(), numberOfVariables(), proposeStartingPoint(), and SHARK_EXPORT_SYMBOL.

◆ numberOfVariables()

SHARK_EXPORT_SYMBOL std::size_t shark::KernelBasisDistance::numberOfVariables ( ) const
virtual

Returns the number of variables of the function.

Implements shark::AbstractObjectiveFunction< RealVector, double >.

Referenced by numApproximatingVectors().

◆ proposeStartingPoint()

SHARK_EXPORT_SYMBOL SearchPointType shark::KernelBasisDistance::proposeStartingPoint ( ) const
virtual

Returns a starting point of the algorithm.

Returns a random subset of the basis of the kernel expansion

Reimplemented from shark::AbstractObjectiveFunction< RealVector, double >.

Referenced by numApproximatingVectors().


The documentation for this class was generated from the following file: