Started on regulaization in Loss.h. I need to refactor the matsum.h since I need a total sum over the matrix. Also matmul needs a elementwise matmul function, which is the next this in the ragulaization
This commit is contained in:
+10
-13
@@ -1,5 +1,4 @@
|
||||
#ifndef _mean_n_
|
||||
#define _mean_n_
|
||||
#pragma once
|
||||
|
||||
#include "./utils/vector.h"
|
||||
#include "./utils/matrix.h"
|
||||
@@ -8,7 +7,7 @@
|
||||
namespace numerics{
|
||||
|
||||
template <typename T>
|
||||
T matmean(utils::Matrix<T>& A) {
|
||||
T matmean(const utils::Matrix<T>& A) {
|
||||
|
||||
T mean(T{0});
|
||||
|
||||
@@ -27,7 +26,7 @@ namespace numerics{
|
||||
|
||||
|
||||
template <typename T>
|
||||
void inplace_matmean_row(utils::Matrix<T>& A, utils::Vector<T>& b) {
|
||||
void inplace_matmean_row(const utils::Matrix<T>& A, utils::Vector<T>& b) {
|
||||
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
@@ -40,12 +39,12 @@ namespace numerics{
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
b[j] += A(i, j);
|
||||
}
|
||||
b[j] =/ static_cast<T>(rows);
|
||||
b[j] /= static_cast<T>(rows);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void inplace_matmean_cols(utils::Matrix<T>& A) {
|
||||
void inplace_matmean_cols(const utils::Matrix<T>& A, utils::Vector<T>& b) {
|
||||
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
@@ -58,15 +57,15 @@ namespace numerics{
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
b[i] += A(i, j);
|
||||
}
|
||||
b[j] =/ static_cast<T>(cols);
|
||||
b[i] /= static_cast<T>(cols);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
utils::Vector<T> matmean_row(utils::Matrix<T>& A) {
|
||||
utils::Vector<T> matmean_row(const utils::Matrix<T>& A) {
|
||||
|
||||
utils:Vector<T> b(A.rows(), T{0});
|
||||
utils::Vector<T> b(A.rows(), T{0});
|
||||
|
||||
inplace_matmean_row(A, b);
|
||||
|
||||
@@ -74,9 +73,9 @@ namespace numerics{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Vector<T> matmean_col(utils::Matrix<T>& A) {
|
||||
utils::Vector<T> matmean_col(const utils::Matrix<T>& A) {
|
||||
|
||||
utils:Vector<T> b(A.cols(), T{0});
|
||||
utils::Vector<T> b(A.cols(), T{0});
|
||||
|
||||
inplace_matmean_cols(A, b);
|
||||
|
||||
@@ -84,5 +83,3 @@ namespace numerics{
|
||||
}
|
||||
|
||||
} // namespace numerics
|
||||
|
||||
#endif // _mean_n_
|
||||
Reference in New Issue
Block a user