ea359f3b09
I've implemented alot of support functions that needs to be refactored, optimised and tested; mean.h, exponential.h, matdiv.h matsum.h matsubtract.h. Maybe we need to have a look at if matdiv/matmul should be in the same. Same with matadd/matsubtract and if some of it should be in matvec.h.
34 lines
643 B
C++
34 lines
643 B
C++
#pragma once
|
|
|
|
#include "./core/omp_config.h"
|
|
|
|
#include "./utils/vector.h"
|
|
#include "./utils/matrix.h"
|
|
|
|
|
|
namespace neural_networks{
|
|
|
|
template <typename Td, typename Ti>
|
|
struct Loss{
|
|
|
|
utils::Matrix<Td> sample_losses;
|
|
Td data_losses;
|
|
|
|
virtual utils::Vector<Td> forward(const utils::Matrix<Td>& output, const utils::Matrix<Ti>& y) = 0;
|
|
|
|
Td calculate(const utils::Matrix<Td>& output, const utils::Matrix<Ti>& y){
|
|
// Calculate sample losses
|
|
sample_losses = forward(output, y);
|
|
|
|
// Calculate mean loss
|
|
data_losses = numerics::mean(sample_losses);
|
|
return data_losses;
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace neural_networks
|