Started Loss, done softmax, up to p.125
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.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "./utils/vector.h"
|
||||
#include "./utils/matrix.h"
|
||||
|
||||
|
||||
namespace numerics{
|
||||
|
||||
template <typename T>
|
||||
T exponential(const T a){
|
||||
return std::exp(a);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Vector<T> exponential(const utils::Vector<T>& a){
|
||||
utils::Vector<T> b = a;
|
||||
for (uint64_t i = 0; i < a.size(); ++i){
|
||||
b[i] = numerics::exponential(a[i]);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Matrix<T> exponential(const utils::Matrix<T>& A){
|
||||
utils::Matrix<T> B = A;
|
||||
for (uint64_t i = 0; i < A.rows(); ++i){
|
||||
for (uint64_t j = 0; j < A.cols(); ++j){
|
||||
B(i,j) = numerics::exponential(A(i,j));
|
||||
}
|
||||
}
|
||||
return B;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace numerics
|
||||
|
||||
Reference in New Issue
Block a user