kernel_set

Classes such as dcgp::expression, dcgp::symbolic_regression and others are constructed from an std::vector of dcgp::kernel. Assembling such a std::vector is an operation that is greatly facilitated by the class dcgp::kernel_set.

Intended use of the class is:

// (optional) - Say we have a custom kernel named f
kernel<double> f(my_sum<double>, print_my_sum, "my_sum");
// We can construct a kernel set (and fill it in with provided kernels)
kernel_set<double> kernels({"sum", "div", "mul","diff"});
// We can get a vector with these four basic kernels ...
auto kernel_vector = kernels();
// (optional) - ... or add our own custom kernel to the set ...
basic_set.push_back(f);
// (optional) - ... and get a vector with all five kernels
auto kernel_vector2 = kernels();

template<typename T>
class kernel_set

Function set.

This class is provided as an helper to construct the std::vector<kernel<T>> that is requested to form a dcgp::expression<T>. Once constructed, a call to its parenthesis operator will return the std::vector containing the requested kernels

Template Parameters

T – The type of the functions output (and inputs)

Public Functions

inline kernel_set()

Constructor.

Default constructor

inline kernel_set(const std::vector<std::string> &list)

Constructor.

Constructs a kernel set that can be used in a dCGP expression

Parameters

list[in] an std::vector of strings containing the function names (e.g., “sum”)

inline void push_back(std::string kernel_name)

Adds a kernel to the set.

Constructs a kernel<T> given a string containing the function name, and inserts it into the std::vector

Parameters

kernel_name[in] a string containing the function name

Throws

std::invalid_argument – if the function is not implemented

inline void push_back(const dcgp::kernel<T> &kernel)

Adds a kernel to the set.

Inserts the given kernel<T> into the std::vector

Parameters

kernel[in] the dcgp::kernel<T> to add

inline void clear()

Clears the kernel set.

Removes all the elements from the std::vector containing the kernels

inline std::vector<dcgp::kernel<T>> operator()() const

Overloaded function call operator.

Returns the std::vector containing the kernels

inline dcgp::kernel<T> operator[](const typename std::vector<dcgp::kernel<T>>::size_type idx) const

Returns the kernel at a specified index in the std::vector

Parameters

idx[in] index of the required kernel

Returns

the kernel at the specified index

template<typename Archive>
inline void serialize(Archive &ar, unsigned)

Object serialization.

This method will save/load this into the archive ar.

Parameters

ar – target archive.

Throws

unspecified – any exception thrown by the serialization of the expression and of primitive types.

Friends

inline friend std::ostream &operator<<(std::ostream &os, const kernel_set<T> &d)

Overloaded stream operator.

Will stream the function names

Parameters
  • os[inout] target stream

  • d[in] kernel_set argument

Returns

reference to os