Expression Templates Library (ETL)
Functions
ml_expression_builder.hpp File Reference

Contains some special helpers for machine learning. More...

#include "etl/impl/cce.hpp"
#include "etl/impl/bce.hpp"
#include "etl/impl/mse.hpp"
Include dependency graph for ml_expression_builder.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<size_t S1 = 1, size_t S2 = 1, size_t P1 = 0, size_t P2 = 0, etl_expr A, etl_expr B>
conv_4d_valid_expr< detail::build_type< A >, detail::build_type< B >, S1, S2, P1, P2, true > etl::ml::convolution_forward (A &&a, B &&b)
 Forward convolution for a batch of images with a set of kernels. More...
 
template<etl_expr A, etl_expr B>
dyn_conv_4d_valid_expr< detail::build_type< A >, detail::build_type< B >, true > etl::ml::convolution_forward (A &&a, B &&b, size_t s1, size_t s2, size_t p1=0, size_t p2=0)
 Forward convolution for a batch of images with a set of kernels. More...
 
template<size_t S1 = 1, size_t S2 = 1, size_t P1 = 0, size_t P2 = 0, etl_expr A, etl_expr B>
conv_4d_backward_expr< detail::build_type< A >, detail::build_type< B >, S1, S2, P1, P2, true > etl::ml::convolution_backward (A &&a, B &&b)
 Backward convolution for a batch of images with a set of kernels. More...
 
template<etl_expr A, etl_expr B>
dyn_conv_4d_backward_expr< detail::build_type< A >, detail::build_type< B >, true > etl::ml::convolution_backward (A &&a, B &&b, size_t s1, size_t s2, size_t p1=0, size_t p2=0)
 Backward convolution for a batch of images with a set of kernels. More...
 
template<size_t S1 = 1, size_t S2 = 1, size_t P1 = 0, size_t P2 = 0, etl_expr A, etl_expr B>
conv_4d_backward_filter_expr< detail::build_type< A >, detail::build_type< B >, S1, S2, P1, P2, true > etl::ml::convolution_backward_filter (A &&a, B &&b)
 Backward convolution for a batch of images with a set of kernels. More...
 
template<etl_expr A, etl_expr B>
dyn_conv_4d_backward_filter_expr< detail::build_type< A >, detail::build_type< B >, true > etl::ml::convolution_backward_filter (A &&a, B &&b, size_t s1, size_t s2, size_t p1=0, size_t p2=0)
 Backward convolution for a batch of images with a set of kernels. More...
 
template<size_t C1, size_t C2, size_t S1 = C1, size_t S2 = C2, size_t P1 = 0, size_t P2 = 0, typename E >
auto etl::ml::max_pool_forward (E &&value)
 Forward 2D Max Pooling of the given matrix expression. More...
 
template<typename E >
auto etl::ml::max_pool_forward (E &&value, size_t c1, size_t c2)
 Forward 2D Max Pooling of the given matrix expression. More...
 
template<typename E >
auto etl::ml::max_pool_forward (E &&value, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1=0, size_t p2=0)
 Forward 2D Max Pooling of the given matrix expression. More...
 
template<size_t C1, size_t C2, size_t C3, typename E >
auto etl::ml::max_pool_3d_forward (E &&value)
 Forward 3D Max Pooling of the given matrix expression. More...
 
template<typename E >
auto etl::ml::max_pool_3d_forward (E &&value, size_t c1, size_t c2, size_t c3)
 Forward 3D Max Pooling of the given matrix expression. More...
 
template<size_t C1, size_t C2, size_t S1 = C1, size_t S2 = C2, size_t P1 = 0, size_t P2 = 0, typename E >
auto etl::ml::avg_pool_forward (E &&value)
 Forward Average Pooling of the given matrix expression. More...
 
template<typename E >
auto etl::ml::avg_pool_forward (E &&value, size_t c1, size_t c2)
 2D Average Pooling of the given matrix expression More...
 
template<typename E >
auto etl::ml::avg_pool_forward (E &&value, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1=0, size_t p2=0)
 2D Average Pooling of the given matrix expression More...
 
template<size_t C1, size_t C2, size_t C3, typename E >
auto etl::ml::avg_pool_3d_forward (E &&value)
 Forward 3D Average Pooling of the given matrix expression. More...
 
template<typename E >
auto etl::ml::avg_pool_3d_forward (E &&value, size_t c1, size_t c2, size_t c3)
 Forward 3D Average Pooling of the given matrix expression. More...
 
template<size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_expr A, etl_expr B, typename C >
pool_upsample_2d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, C1, C2, S1, S2, P1, P2, true > etl::ml::max_pool_backward (A &&input, B &&output, C &&errors)
 Derivative of the 2D Max Pooling of the given matrix expression and upsampling. More...
 
template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, true > etl::ml::max_pool_backward (A &&input, B &&output, C &&errors, size_t c1, size_t c2)
 Derivative of the 2D Max Pooling of the given matrix expression and upsampling. More...
 
template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, true > etl::ml::max_pool_backward (A &&input, B &&output, C &&errors, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1=0, size_t p2=0)
 Derivative of the 2D Max Pooling of the given matrix expression and upsampling. More...
 
template<size_t C1, size_t C2, size_t C3, etl_expr A, etl_expr B, typename C >
pool_upsample_3d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, C1, C2, C3, true > etl::ml::max_pool_3d_backward (A &&input, B &&output, C &&errors)
 Derivative of the 3D Max Pooling of the given matrix expression and upsampling. More...
 
template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_3d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, true > etl::ml::max_pool_3d_backward (A &&input, B &&output, C &&errors, size_t c1, size_t c2, size_t c3)
 Derivative of the 3D Max Pooling of the given matrix expression and upsampling. More...
 
template<size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_expr A, etl_expr B, typename C >
pool_upsample_2d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, C1, C2, S1, S2, P1, P2, false > etl::ml::avg_pool_backward (A &&input, B &&output, C &&errors)
 Derivative of the 2D Avg Pooling of the given matrix expression and upsampling. More...
 
template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, false > etl::ml::avg_pool_backward (A &&input, B &&output, C &&errors, size_t c1, size_t c2)
 Derivative of the 2D Average Pooling of the given matrix expression and upsampling. More...
 
template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, false > etl::ml::avg_pool_backward (A &&input, B &&output, C &&errors, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1=0, size_t p2=0)
 Derivative of the 2D Average Pooling of the given matrix expression and upsampling. More...
 
template<size_t C1, size_t C2, size_t C3, etl_expr A, etl_expr B, typename C >
pool_upsample_3d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, C1, C2, C3, false > etl::ml::avg_pool_3d_backward (A &&input, B &&output, C &&errors)
 Derivative of the 2D Avg Pooling of the given matrix expression and upsampling. More...
 
template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_3d_expr< detail::build_type< A >, detail::build_type< B >, detail::build_type< C >, false > etl::ml::avg_pool_3d_backward (A &&input, B &&output, C &&errors, size_t c1, size_t c2, size_t c3)
 Derivative of the 2D Average Pooling of the given matrix expression and upsampling. More...
 
template<typename E >
auto etl::ml::identity_derivative_out ([[maybe_unused]] E &&value)
 Return the derivative of the identiy function for the given output value. More...
 
template<etl_expr E>
auto etl::ml::sigmoid_derivative_out (E &&value) -> decltype(value >>(1.0 - value))
 Return the derivative of the logistic sigmoid of the given ETL expression, with respect to the output value. More...
 
template<typename E >
auto etl::ml::softmax_derivative_out ([[maybe_unused]] E &&e)
 Return the derivative of the softmax function of the given ETL expression, with respect to output values. More...
 
template<etl_expr E>
auto etl::ml::tanh_derivative_out (E &&value) -> decltype(1.0 -(value >> value))
 Return the derivative of the tanh function of the given ETL expression, with respect to the output values. More...
 
template<etl_expr E>
auto etl::ml::relu_derivative_out (const E &value) -> detail::unary_helper< E, relu_derivative_op >
 Return the derivative of the relu function of the given ETL expression, with respect for the output values. More...
 
template<typename O , typename E >
decltype(auto) etl::ml::identity_backward ([[maybe_unused]] O &&output, E &&errors)
 Return the backward activation of the identity function. More...
 
template<typename O , typename E >
auto etl::ml::sigmoid_backward (O &&output, E &&errors) -> detail::left_binary_helper< O, E, sigmoid_derivative_binary_op >
 Return the backward activation of the sigmoid function. More...
 
template<typename O , typename E >
auto etl::ml::relu_backward (O &&output, E &&errors) -> detail::left_binary_helper< O, E, relu_derivative_binary_op >
 Return the backward activation of the RELU function. More...
 
template<typename O , typename E >
decltype(auto) etl::ml::softmax_backward ([[maybe_unused]] O &&output, E &&errors)
 Return the backward activation of the softmax function. More...
 
template<typename O , etl_expr E>
auto etl::ml::tanh_backward (O &&output, E &&errors)
 Return the backward activation of the tanh function. More...
 
template<etl_expr O, etl_expr L>
value_t< O > etl::ml::cce_loss (O &&output, L &&labels, value_t< O > scale)
 Returns the Categorical Cross Entropy Loss. More...
 
template<etl_expr O, etl_expr L>
value_t< O > etl::ml::cce_error (O &&output, L &&labels, value_t< O > scale)
 Returns the Categorical Cross Entropy Error. More...
 
template<etl_expr O, etl_expr L>
value_t< O > etl::ml::bce_loss (O &&output, L &&labels, value_t< O > scale)
 Returns the Binary Cross Entropy Loss. More...
 
template<etl_expr O, etl_expr L>
value_t< O > etl::ml::bce_error (O &&output, L &&labels, value_t< O > scale)
 Returns the Binary Cross Entropy Error. More...
 
template<etl_expr O, etl_expr L>
std::pair< value_t< O >, value_t< O > > etl::ml::bce (O &&output, L &&labels, value_t< O > alpha, value_t< O > beta)
 Returns the Binary Cross Entropy Loss and Error. More...
 
template<etl_expr O, etl_expr L>
std::pair< value_t< O >, value_t< O > > etl::ml::cce (O &&output, L &&labels, value_t< O > alpha, value_t< O > beta)
 Returns the Categorical Cross Entropy Loss and Error. More...
 
template<etl_expr O, etl_expr L>
value_t< O > etl::ml::mse_loss (O &&output, L &&labels, value_t< O > scale)
 Returns the Binary Cross Entropy Loss. More...
 
template<etl_expr O, etl_expr L>
value_t< O > etl::ml::mse_error (O &&output, L &&labels, value_t< O > scale)
 Returns the Binary Cross Entropy Error. More...
 
template<etl_expr O, etl_expr L>
std::pair< value_t< O >, value_t< O > > etl::ml::mse (O &&output, L &&labels, value_t< O > alpha, value_t< O > beta)
 Returns the Binary Cross Entropy Loss and Error. More...
 

Detailed Description

Contains some special helpers for machine learning.

This is mostly a simpler set of names and functions to achieve machine learning features.

Function Documentation

◆ avg_pool_3d_backward() [1/2]

template<size_t C1, size_t C2, size_t C3, etl_expr A, etl_expr B, typename C >
pool_upsample_3d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, C1, C2, C3, false> etl::ml::avg_pool_3d_backward ( A &&  input,
B &&  output,
C &&  errors 
)

Derivative of the 2D Avg Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
Returns
A expression representing the Derivative of 3D Max Pooling of the input expression.

◆ avg_pool_3d_backward() [2/2]

template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_3d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, false> etl::ml::avg_pool_3d_backward ( A &&  input,
B &&  output,
C &&  errors,
size_t  c1,
size_t  c2,
size_t  c3 
)

Derivative of the 2D Average Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the Derivative of 3D Average Pooling of the input expression.

◆ avg_pool_3d_forward() [1/2]

template<size_t C1, size_t C2, size_t C3, typename E >
auto etl::ml::avg_pool_3d_forward ( E &&  value)

Forward 3D Average Pooling of the given matrix expression.

Parameters
valueThe matrix expression
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
C3The third pooling ratio
Returns
A expression representing the 2D Forward Average Pooling of the input expression.

◆ avg_pool_3d_forward() [2/2]

template<typename E >
auto etl::ml::avg_pool_3d_forward ( E &&  value,
size_t  c1,
size_t  c2,
size_t  c3 
)

Forward 3D Average Pooling of the given matrix expression.

Parameters
valueThe matrix expression
c1The first pooling ratio
c2The second pooling ratio
c3The third pooling ratio
Returns
A expression representing the 2D Average Pooling of the input expression.

◆ avg_pool_backward() [1/3]

template<size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_expr A, etl_expr B, typename C >
pool_upsample_2d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, C1, C2, S1, S2, P1, P2, false> etl::ml::avg_pool_backward ( A &&  input,
B &&  output,
C &&  errors 
)

Derivative of the 2D Avg Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
Returns
A expression representing the Derivative of 3D Max Pooling of the input expression.

◆ avg_pool_backward() [2/3]

template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, false> etl::ml::avg_pool_backward ( A &&  input,
B &&  output,
C &&  errors,
size_t  c1,
size_t  c2 
)

Derivative of the 2D Average Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the Derivative of 3D Average Pooling of the input expression.

◆ avg_pool_backward() [3/3]

template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, false> etl::ml::avg_pool_backward ( A &&  input,
B &&  output,
C &&  errors,
size_t  c1,
size_t  c2,
size_t  s1,
size_t  s2,
size_t  p1 = 0,
size_t  p2 = 0 
)

Derivative of the 2D Average Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the Derivative of 3D Average Pooling of the input expression.

◆ avg_pool_forward() [1/3]

template<size_t C1, size_t C2, size_t S1 = C1, size_t S2 = C2, size_t P1 = 0, size_t P2 = 0, typename E >
auto etl::ml::avg_pool_forward ( E &&  value)

Forward Average Pooling of the given matrix expression.

Parameters
valueThe matrix expression
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
Returns
A expression representing the 2D Forward Average Pooling of the input expression.

◆ avg_pool_forward() [2/3]

template<typename E >
auto etl::ml::avg_pool_forward ( E &&  value,
size_t  c1,
size_t  c2 
)

2D Average Pooling of the given matrix expression

Parameters
valueThe matrix expression
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the 2D Average Pooling of the input expression.

◆ avg_pool_forward() [3/3]

template<typename E >
auto etl::ml::avg_pool_forward ( E &&  value,
size_t  c1,
size_t  c2,
size_t  s1,
size_t  s2,
size_t  p1 = 0,
size_t  p2 = 0 
)

2D Average Pooling of the given matrix expression

Parameters
valueThe matrix expression
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the 2D Average Pooling of the input expression.

◆ bce()

template<etl_expr O, etl_expr L>
std::pair<value_t<O>, value_t<O> > etl::ml::bce ( O &&  output,
L &&  labels,
value_t< O >  alpha,
value_t< O >  beta 
)

Returns the Binary Cross Entropy Loss and Error.

Parameters
outputThe outputs
labelsThe labels
Returns
The BCE Loss and Error of the output and labels

◆ bce_error()

template<etl_expr O, etl_expr L>
value_t<O> etl::ml::bce_error ( O &&  output,
L &&  labels,
value_t< O >  scale 
)

Returns the Binary Cross Entropy Error.

Parameters
outputThe outputs
labelsThe labels
Returns
The BCE Error of the output and labels

◆ bce_loss()

template<etl_expr O, etl_expr L>
value_t<O> etl::ml::bce_loss ( O &&  output,
L &&  labels,
value_t< O >  scale 
)

Returns the Binary Cross Entropy Loss.

Parameters
outputThe outputs
labelsThe labels
Returns
The BCE Loss of the output and labels

◆ cce()

template<etl_expr O, etl_expr L>
std::pair<value_t<O>, value_t<O> > etl::ml::cce ( O &&  output,
L &&  labels,
value_t< O >  alpha,
value_t< O >  beta 
)

Returns the Categorical Cross Entropy Loss and Error.

Parameters
outputThe outputs
labelsThe labels
Returns
The BCE Loss and Error of the output and labels

◆ cce_error()

template<etl_expr O, etl_expr L>
value_t<O> etl::ml::cce_error ( O &&  output,
L &&  labels,
value_t< O >  scale 
)

Returns the Categorical Cross Entropy Error.

Parameters
outputThe outputs
labelsThe labels
Returns
The CCE Error of the output and labels

◆ cce_loss()

template<etl_expr O, etl_expr L>
value_t<O> etl::ml::cce_loss ( O &&  output,
L &&  labels,
value_t< O >  scale 
)

Returns the Categorical Cross Entropy Loss.

Parameters
outputThe outputs
labelsThe labels
Returns
The CCE Loss of the output and labels

◆ convolution_backward() [1/2]

template<size_t S1 = 1, size_t S2 = 1, size_t P1 = 0, size_t P2 = 0, etl_expr A, etl_expr B>
conv_4d_backward_expr<detail::build_type<A>, detail::build_type<B>, S1, S2, P1, P2, true> etl::ml::convolution_backward ( A &&  a,
B &&  b 
)

Backward convolution for a batch of images with a set of kernels.

This will compute the 2D backward convolutions of each image with each given kernels. The results accross channels will be accumulated together.

The 4D matrix a is assumed to be of [N, K, Hi, Wi] dimensions. The 4D matrix b is assumed to be of [K, C, Hj, Wj] dimensions. The 4D matrix c is assumed to be of [N, C, (Hi - Hj + 2 * P1) / S1 + 1, (Wi - Hj + 2 * P2) / S2 + 1] dimensions.

Parameters
aAn expression containing the batch of images
bAn expression containing the set of kernels
Template Parameters
S1The stride in the first dimension
S2The stride in the second dimension
P1The padding of the first dimension
P2The padding of the second dimension
Returns
an expression representing the result of the forward convolution

◆ convolution_backward() [2/2]

template<etl_expr A, etl_expr B>
dyn_conv_4d_backward_expr<detail::build_type<A>, detail::build_type<B>, true> etl::ml::convolution_backward ( A &&  a,
B &&  b,
size_t  s1,
size_t  s2,
size_t  p1 = 0,
size_t  p2 = 0 
)

Backward convolution for a batch of images with a set of kernels.

This will compute the 2D convolutions of each image with each given kernels. The results accross channels will be accumulated together.

The 4D matrix a is assumed to be of [N, K, Hi, Wi] dimensions. The 4D matrix b is assumed to be of [K, C, Hj, Wj] dimensions. The 4D matrix c is assumed to be of [N, C, (Hi - Hj + 2 * P1) / S1 + 1, (Wi - Hj + 2 * P2) / S2 + 1] dimensions.

Parameters
aAn expression containing the batch of images
bAn expression containing the set of kernels
s1The stride in the first dimension
s2The stride in the second dimension
p1The padding of the first dimension
p2The padding of the second dimension
Returns
an expression representing the result of the forward convolution

◆ convolution_backward_filter() [1/2]

template<size_t S1 = 1, size_t S2 = 1, size_t P1 = 0, size_t P2 = 0, etl_expr A, etl_expr B>
conv_4d_backward_filter_expr<detail::build_type<A>, detail::build_type<B>, S1, S2, P1, P2, true> etl::ml::convolution_backward_filter ( A &&  a,
B &&  b 
)

Backward convolution for a batch of images with a set of kernels.

This will compute the 2D backward convolutions of each image with each given kernels. The results accross channels will be accumulated together.

The 4D matrix a is assumed to be of [N, K, Hi, Wi] dimensions. The 4D matrix b is assumed to be of [K, C, Hj, Wj] dimensions. The 4D matrix c is assumed to be of [N, C, (Hi - Hj + 2 * P1) / S1 + 1, (Wi - Hj + 2 * P2) / S2 + 1] dimensions.

Parameters
aAn expression containing the batch of images
bAn expression containing the set of kernels
Template Parameters
S1The stride in the first dimension
S2The stride in the second dimension
P1The padding of the first dimension
P2The padding of the second dimension
Returns
an expression representing the result of the forward convolution

◆ convolution_backward_filter() [2/2]

template<etl_expr A, etl_expr B>
dyn_conv_4d_backward_filter_expr<detail::build_type<A>, detail::build_type<B>, true> etl::ml::convolution_backward_filter ( A &&  a,
B &&  b,
size_t  s1,
size_t  s2,
size_t  p1 = 0,
size_t  p2 = 0 
)

Backward convolution for a batch of images with a set of kernels.

This will compute the 2D convolutions of each image with each given kernels. The results accross channels will be accumulated together.

The 4D matrix a is assumed to be of [N, K, Hi, Wi] dimensions. The 4D matrix b is assumed to be of [K, C, Hj, Wj] dimensions. The 4D matrix c is assumed to be of [N, C, (Hi - Hj + 2 * P1) / S1 + 1, (Wi - Hj + 2 * P2) / S2 + 1] dimensions.

Parameters
aAn expression containing the batch of images
bAn expression containing the set of kernels
s1The stride in the first dimension
s2The stride in the second dimension
p1The padding of the first dimension
p2The padding of the second dimension
Returns
an expression representing the result of the forward convolution

◆ convolution_forward() [1/2]

template<size_t S1 = 1, size_t S2 = 1, size_t P1 = 0, size_t P2 = 0, etl_expr A, etl_expr B>
conv_4d_valid_expr<detail::build_type<A>, detail::build_type<B>, S1, S2, P1, P2, true> etl::ml::convolution_forward ( A &&  a,
B &&  b 
)

Forward convolution for a batch of images with a set of kernels.

This will compute the 2D convolutions of each image with each given kernels. The results accross channels will be accumulated together.

The 4D matrix a is assumed to be of [N, C, Hi, Wi] dimensions. The 4D matrix b is assumed to be of [K, C, Hj, Wj] dimensions. The 4D matrix c is assumed to be of [N, K, (Hi - Hj + 2 * P1) / S1 + 1, (Wi - Hj + 2 * P2) / S2 + 1] dimensions.

Parameters
aAn expression containing the batch of images
bAn expression containing the set of kernels
Template Parameters
S1The stride in the first dimension
S2The stride in the second dimension
P1The padding of the first dimension
P2The padding of the second dimension
Returns
an expression representing the result of the forward convolution

◆ convolution_forward() [2/2]

template<etl_expr A, etl_expr B>
dyn_conv_4d_valid_expr<detail::build_type<A>, detail::build_type<B>, true> etl::ml::convolution_forward ( A &&  a,
B &&  b,
size_t  s1,
size_t  s2,
size_t  p1 = 0,
size_t  p2 = 0 
)

Forward convolution for a batch of images with a set of kernels.

This will compute the 2D convolutions of each image with each given kernels. The results accross channels will be accumulated together.

The 4D matrix a is assumed to be of [N, C, Hi, Wi] dimensions. The 4D matrix b is assumed to be of [K, C, Hj, Wj] dimensions. The 4D matrix c is assumed to be of [N, K, (Hi - Hj + 2 * P1) / S1 + 1, (Wi - Hj + 2 * P2) / S2 + 1] dimensions.

Parameters
aAn expression containing the batch of images
bAn expression containing the set of kernels
s1The stride in the first dimension
s2The stride in the second dimension
p1The padding of the first dimension
p2The padding of the second dimension
Returns
an expression representing the result of the forward convolution

◆ identity_backward()

template<typename O , typename E >
decltype(auto) etl::ml::identity_backward ( [[maybe_unused] ] O &&  output,
E &&  errors 
)

Return the backward activation of the identity function.

Parameters
outputThe output of the forward activation function
errorsThe errors at output of this activation function
Returns
the backward activation of the activation function

◆ identity_derivative_out()

template<typename E >
auto etl::ml::identity_derivative_out ( [[maybe_unused] ] E &&  value)

Return the derivative of the identiy function for the given output value.

Parameters
valueThe ETL expression
Returns
1.0

◆ max_pool_3d_backward() [1/2]

template<size_t C1, size_t C2, size_t C3, etl_expr A, etl_expr B, typename C >
pool_upsample_3d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, C1, C2, C3, true> etl::ml::max_pool_3d_backward ( A &&  input,
B &&  output,
C &&  errors 
)

Derivative of the 3D Max Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
Returns
A expression representing the Derivative of 3D Max Pooling of the input expression.

◆ max_pool_3d_backward() [2/2]

template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_3d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, true> etl::ml::max_pool_3d_backward ( A &&  input,
B &&  output,
C &&  errors,
size_t  c1,
size_t  c2,
size_t  c3 
)

Derivative of the 3D Max Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the Derivative of 3D Max Pooling of the input expression.

◆ max_pool_3d_forward() [1/2]

template<size_t C1, size_t C2, size_t C3, typename E >
auto etl::ml::max_pool_3d_forward ( E &&  value)

Forward 3D Max Pooling of the given matrix expression.

Parameters
valueThe matrix expression
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
C3The third pooling ratio
Returns
A expression representing the 2D Forward Max Pooling of the input expression.

◆ max_pool_3d_forward() [2/2]

template<typename E >
auto etl::ml::max_pool_3d_forward ( E &&  value,
size_t  c1,
size_t  c2,
size_t  c3 
)

Forward 3D Max Pooling of the given matrix expression.

Parameters
valueThe matrix expression
c1The first pooling ratio
c2The second pooling ratio
c3The second pooling ratio
Returns
A expression representing the 2D Max Pooling of the input expression.

◆ max_pool_backward() [1/3]

template<size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_expr A, etl_expr B, typename C >
pool_upsample_2d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, C1, C2, S1, S2, P1, P2, true> etl::ml::max_pool_backward ( A &&  input,
B &&  output,
C &&  errors 
)

Derivative of the 2D Max Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
Returns
A expression representing the Derivative of 3D Max Pooling of the input expression.

◆ max_pool_backward() [2/3]

template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, true> etl::ml::max_pool_backward ( A &&  input,
B &&  output,
C &&  errors,
size_t  c1,
size_t  c2 
)

Derivative of the 2D Max Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the Derivative of 3D Max Pooling of the input expression.

◆ max_pool_backward() [3/3]

template<etl_expr A, etl_expr B, typename C >
dyn_pool_upsample_2d_expr<detail::build_type<A>, detail::build_type<B>, detail::build_type<C>, true> etl::ml::max_pool_backward ( A &&  input,
B &&  output,
C &&  errors,
size_t  c1,
size_t  c2,
size_t  s1,
size_t  s2,
size_t  p1 = 0,
size_t  p2 = 0 
)

Derivative of the 2D Max Pooling of the given matrix expression and upsampling.

Parameters
inputThe input
outputThe output
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the Derivative of 3D Max Pooling of the input expression.

◆ max_pool_forward() [1/3]

template<size_t C1, size_t C2, size_t S1 = C1, size_t S2 = C2, size_t P1 = 0, size_t P2 = 0, typename E >
auto etl::ml::max_pool_forward ( E &&  value)

Forward 2D Max Pooling of the given matrix expression.

Parameters
valueThe matrix expression
Template Parameters
C1The first pooling ratio
C2The second pooling ratio
Returns
A expression representing the 2D Forward Max Pooling of the input expression.

◆ max_pool_forward() [2/3]

template<typename E >
auto etl::ml::max_pool_forward ( E &&  value,
size_t  c1,
size_t  c2 
)

Forward 2D Max Pooling of the given matrix expression.

Parameters
valueThe matrix expression
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the 2D Max Pooling of the input expression.

◆ max_pool_forward() [3/3]

template<typename E >
auto etl::ml::max_pool_forward ( E &&  value,
size_t  c1,
size_t  c2,
size_t  s1,
size_t  s2,
size_t  p1 = 0,
size_t  p2 = 0 
)

Forward 2D Max Pooling of the given matrix expression.

Parameters
valueThe matrix expression
c1The first pooling ratio
c2The second pooling ratio
Returns
A expression representing the 2D Max Pooling of the input expression.

◆ mse()

template<etl_expr O, etl_expr L>
std::pair<value_t<O>, value_t<O> > etl::ml::mse ( O &&  output,
L &&  labels,
value_t< O >  alpha,
value_t< O >  beta 
)

Returns the Binary Cross Entropy Loss and Error.

Parameters
outputThe outputs
labelsThe labels
Returns
The MSE Loss and Error of the output and labels

◆ mse_error()

template<etl_expr O, etl_expr L>
value_t<O> etl::ml::mse_error ( O &&  output,
L &&  labels,
value_t< O >  scale 
)

Returns the Binary Cross Entropy Error.

Parameters
outputThe outputs
labelsThe labels
Returns
The MSE Error of the output and labels

◆ mse_loss()

template<etl_expr O, etl_expr L>
value_t<O> etl::ml::mse_loss ( O &&  output,
L &&  labels,
value_t< O >  scale 
)

Returns the Binary Cross Entropy Loss.

Parameters
outputThe outputs
labelsThe labels
Returns
The MSE Loss of the output and labels

◆ relu_backward()

template<typename O , typename E >
auto etl::ml::relu_backward ( O &&  output,
E &&  errors 
) -> detail::left_binary_helper<O, E, relu_derivative_binary_op>

Return the backward activation of the RELU function.

Parameters
outputThe output of the forward activation function
errorsThe errors at output of this activation function
Returns
the backward activation of the activation function

◆ relu_derivative_out()

template<etl_expr E>
auto etl::ml::relu_derivative_out ( const E &  value) -> detail::unary_helper<E, relu_derivative_op>

Return the derivative of the relu function of the given ETL expression, with respect for the output values.

Parameters
valueThe ETL expression
Returns
An ETL expression representing the derivative of the relu function of the input.

◆ sigmoid_backward()

template<typename O , typename E >
auto etl::ml::sigmoid_backward ( O &&  output,
E &&  errors 
) -> detail::left_binary_helper<O, E, sigmoid_derivative_binary_op>

Return the backward activation of the sigmoid function.

Parameters
outputThe output of the forward activation function
errorsThe errors at output of this activation function
Returns
the backward activation of the activation function

◆ sigmoid_derivative_out()

template<etl_expr E>
auto etl::ml::sigmoid_derivative_out ( E &&  value) -> decltype(value >> (1.0 - value))

Return the derivative of the logistic sigmoid of the given ETL expression, with respect to the output value.

Parameters
valueThe ETL expression
Returns
An ETL expression representing the derivative of the logistic sigmoid of the input.

◆ softmax_backward()

template<typename O , typename E >
decltype(auto) etl::ml::softmax_backward ( [[maybe_unused] ] O &&  output,
E &&  errors 
)

Return the backward activation of the softmax function.

Parameters
outputThe output of the forward activation function
errorsThe errors at output of this activation function
Returns
the backward activation of the activation function

◆ softmax_derivative_out()

template<typename E >
auto etl::ml::softmax_derivative_out ( [[maybe_unused] ] E &&  e)

Return the derivative of the softmax function of the given ETL expression, with respect to output values.

Parameters
eThe ETL expression
Returns
An ETL expression representing the derivative of the softmax function of the input.

◆ tanh_backward()

template<typename O , etl_expr E>
auto etl::ml::tanh_backward ( O &&  output,
E &&  errors 
)

Return the backward activation of the tanh function.

Parameters
outputThe output of the forward activation function
errorsThe errors at output of this activation function
Returns
the backward activation of the activation function

◆ tanh_derivative_out()

template<etl_expr E>
auto etl::ml::tanh_derivative_out ( E &&  value) -> decltype(1.0 - (value >> value))

Return the derivative of the tanh function of the given ETL expression, with respect to the output values.

Parameters
valueThe ETL expression
Returns
An ETL expression representing the derivative of the tanh function of the input.