# Linear kernel¶

The linear kernel is the simplest kernel function for pattern analysis.

 Operation Computational methods Programming Interface dense dense compute(…) compute_input compute_result

## Mathematical formulation¶

### Computing¶

Given a set $$X$$ of $$n$$ feature vectors $$x_1 = (x_{11}, \ldots, x_{1p}), \ldots, x_n = (x_{n1}, \ldots, x_{np})$$ of dimension $$p$$ and a set $$Y$$ of $$m$$ feature vectors $$y_1 = (y_{11}, \ldots, y_{1p}), \ldots, y_m = (y_{m1}, \ldots, x_{mp})$$, the problem is to compute the linear kernel function $$K(x_i,, y_i)$$ for any pair of input vectors: $$K(x_i, y_i) = k {X_i}^T y_i + b$$.

## Programming Interface¶

All types and functions in this section are declared in the oneapi::dal::linear_kernel namespace and are available via inclusion of the oneapi/dal/algo/linear_kernel.hpp header file.

### Descriptor¶

template<typename Task = task::by_default>
class descriptor_base

Constructors

descriptor_base()

Properties

double scale = 1.0

The coefficient $$k$$ of the linear kernel.

Getter & Setter
double get_scale() const
double shift = 0.0

The coefficient $$b$$ of the linear kernel.

Getter & Setter
double get_shift() const
template<typename Float = detail::descriptor_base<>::float_t, typename Method = detail::descriptor_base<>::method_t, typename Task = detail::descriptor_base<>::task_t>
class descriptor
Template Parameters
• Float – The floating-point type that the algorithm uses for intermediate computations. Can be float or double.

• Method – Tag-type that specifies an implementation of algorithm. Can be method::v1::dense.

• Task – Tag-type that specifies the type of the problem to solve. Can be task::v1::compute.

Public Methods

auto &set_scale(double value)
auto &set_shift(double value)

#### Method tags¶

struct dense
using by_default = dense

Alias tag-type for the dense method.

struct compute

Tag-type that parameterizes entities that are used to compute statistics, distance, and so on.

using by_default = compute

Alias tag-type for the compute task.

### Training compute(...)¶

#### Input¶

template<typename Task = task::by_default>
class compute_input
Template Parameters

Task – Tag-type that specifies the type of the problem to solve. Can be task::v1::compute.

Constructors

compute_input(const table &x, const table &y)

Creates a new instance of the class with the given x and y.

Properties

const table &x = table{}

An $$n1 \times p$$ table with the data x, where each row stores one feature vector.

Getter & Setter
const table & get_x() const
auto & set_x(const table &data)
const table &y = table{}

An $$n2 \times p$$ table with the data y, where each row stores one feature vector.

Getter & Setter
const table & get_y() const
auto & set_y(const table &data)

#### Result¶

template<typename Task = task::by_default>
class compute_result
Template Parameters

Task – Tag-type that specifies the type of the problem to solve. Can be task::v1::compute.

Constructors

compute_result()

Creates a new instance of the class with the default property values.

Properties

const table &values = table{}

A $$n1 \times n2$$ table with the result kernel functions.

Getter & Setter
const table & get_values() const
auto & set_values(const table &value)

#### Operation¶

template<typename Descriptor>
linear_kernel::compute_result compute(const Descriptor &desc, const linear_kernel::compute_input &input)
Template Parameters

Descriptor – Linear Kernel algorithm descriptor linear_kernel::desc.

Preconditions
input.data.is_empty == false