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:
+27
-3
@@ -39,13 +39,37 @@ namespace numerics{
|
||||
utils::Matrix<T> max(const utils::Matrix<T>& A, const T b){
|
||||
|
||||
utils::Matrix<T> B = A;
|
||||
|
||||
inplace_max(B, b);
|
||||
|
||||
|
||||
return B;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Vector<T> max(const utils::Matrix<T>& A, std::string method){
|
||||
|
||||
utils::Vector<T> b;
|
||||
|
||||
if (method == "cols"){
|
||||
b.resize(A.cols(), T{0});
|
||||
for (uint64_t i = 0; i < A.cols(); ++i){
|
||||
for (uint64_t j = 0; j < A.rows(); ++j){
|
||||
b[i] = max(A(j, i), b[i]);
|
||||
}
|
||||
}
|
||||
}else if (method == "rows"){
|
||||
b.resize(A.rows(), T{0});
|
||||
for (uint64_t i = 0; i < A.rows(); ++i){
|
||||
for (uint64_t j = 0; j < A.cols(); ++j){
|
||||
//std::cout << i << ":" << j << std::endl;
|
||||
b[i] = max(A(i, j), b[i]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
throw std::runtime_error("max: choose 'rows or 'cols'");
|
||||
}
|
||||
return b;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace numerics
|
||||
|
||||
Reference in New Issue
Block a user