Add an utility function to compute l2 loss in ml
This commit is contained in:
parent
6d40e4dd98
commit
d410c970e6
1 changed files with 19 additions and 0 deletions
19
libs/ml/include/psemek/ml/neural_net/loss.hpp
Normal file
19
libs/ml/include/psemek/ml/neural_net/loss.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <psemek/geom/math.hpp>
|
||||
|
||||
namespace psemek::ml
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
T l2_loss(std::vector<T> const & x1, std::vector<T> const & x2)
|
||||
{
|
||||
T value = T{0};
|
||||
for (std::size_t i = 0; i < x1.size(); ++i)
|
||||
value += geom::sqr(x1[i] - x2[i]) / T{2};
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue