Binomial_CrossEnthophy
fixed rowwise/colswise mean/sum and implemented binomial_corssentrhopy. Next up is regression.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint> //uint64_t
|
||||
#include <cmath> // std::abs
|
||||
|
||||
#include "utils/vector.h"
|
||||
#include "utils/matrix.h"
|
||||
|
||||
namespace numerics::detail{
|
||||
|
||||
|
||||
// ---------------- Elemenwise ----------------
|
||||
template <typename T>
|
||||
void inplace_greater_than_serial(T& a, const T c) {
|
||||
if (a > c){
|
||||
a = T{1};
|
||||
}
|
||||
else{
|
||||
a = T{0};
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void inplace_greater_than_serial(utils::Vector<T>& v, const T c) {
|
||||
for (uint64_t i = 0; i < v.size(); ++i){
|
||||
inplace_greater_than_serial(v[i], c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void inplace_greater_than_serial(utils::Matrix<T>& A, const T c) {
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
inplace_greater_than_serial(A(i,j), c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace numerics
|
||||
|
||||
@@ -20,12 +20,31 @@ namespace numerics::detail{
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void inplace_div_scalar_serial(const T c, utils::Matrix<T>& A) {
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
A(i,j) = c / A(i,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void inplace_div_scalar_serial(utils::Vector<T>& v, const T c) {
|
||||
for (uint64_t i = 0; i < v.size(); ++i){
|
||||
v[i] /= c;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void inplace_div_scalar_serial(const T c, utils::Vector<T>& v) {
|
||||
for (uint64_t i = 0; i < v.size(); ++i){
|
||||
v[i] = c / v[i];
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Elemenwise ----------------
|
||||
template <typename T>
|
||||
void inplace_div_elementwise_serial(utils::Matrix<T>& A, const utils::Matrix<T>& B) {
|
||||
|
||||
@@ -20,12 +20,33 @@ namespace numerics::detail{
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void inplace_sub_scalar_serial(const T c, utils::Matrix<T>& A) {
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
A(i,j) = c - A(i,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
void inplace_sub_scalar_serial(utils::Vector<T>& v, const T c) {
|
||||
for (uint64_t i = 0; i < v.size(); ++i){
|
||||
v[i] -= c;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void inplace_sub_scalar_serial(const T c, utils::Vector<T>& v) {
|
||||
for (uint64_t i = 0; i < v.size(); ++i){
|
||||
v[i] = c - v[i];
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Elemenwise ----------------
|
||||
template <typename T>
|
||||
void inplace_sub_elementwise_serial(utils::Matrix<T>& A, const utils::Matrix<T>& B) {
|
||||
|
||||
@@ -38,10 +38,10 @@ namespace numerics::detail{
|
||||
utils::Vector<T> sum_rowwise_serial(const utils::Matrix<T>& A) {
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
utils::Vector<T> sum(cols, T{0});
|
||||
utils::Vector<T> sum(rows, T{0});
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
sum[j] += A(i,j);
|
||||
sum[i] += A(i,j);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
@@ -51,10 +51,10 @@ namespace numerics::detail{
|
||||
utils::Vector<T> sum_colwise_serial(const utils::Matrix<T>& A) {
|
||||
const uint64_t rows = A.rows();
|
||||
const uint64_t cols = A.cols();
|
||||
utils::Vector<T> sum(rows, T{0});
|
||||
utils::Vector<T> sum(cols, T{0});
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
sum[i] += A(i,j);
|
||||
sum[j] += A(i,j);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
|
||||
Reference in New Issue
Block a user