Class KernelWrapper

Inheritance Relationships

Base Type

Class Documentation

class KernelWrapper : public Kernel

A simple wrapper, which wraps a std::function into the kernel object. This allows us to use lambdas / std::functions instead of writing a new class for a new Kernel. For example: KernelWrapper kernel([](const std::vector<data_t>& x1, const std::vector<data_t>& x2) { data_t distance = 0; if (x1 != x2) { for (unsigned int i = 0; i < x1.size(); ++i) { distance += (x1[i]-x2[i])*(x1[i]-x2[i]); } distance /= 1.0; } return 1.0 * std::exp(-distance); })

Public Functions

inline KernelWrapper(std::function<data_t(std::vector<data_t> const&, std::vector<data_t> const&)> f)

Creates a new KernelWrapper object.

Note

The supplied std::function is moved into this wrapper. There is no copy involved.

Parameters

f – The std::function to be wrapped.

inline virtual data_t operator()(const std::vector<data_t> &x1, const std::vector<data_t> &x2) const override

Evaluates the wrapped kernel on the given parameters.

Parameters
  • x1 – First parameter for evaluation.

  • x2 – Second parameter for evaluation.

inline virtual std::shared_ptr<Kernel> clone() const override

Clones this objet.

Note

This is not a deep copy. The internal std::function is moved into the new object

Protected Attributes

std::function<data_t(std::vector<data_t> const&, std::vector<data_t> const&)> f

The wrapped function.

Parameters
  • & – First parameter for evaluation.

  • & – Second parameter for evaluation.