Binomial_CrossEnthophy
fixed rowwise/colswise mean/sum and implemented binomial_corssentrhopy. Next up is regression.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/omp_config.h"
|
||||
#include "detail/binary_threshold_serial.h"
|
||||
|
||||
|
||||
namespace numerics{
|
||||
|
||||
// ---------------- Elementwise ----------------
|
||||
template <typename T>
|
||||
inline void inplace_greater_than(T& a, const T c) {
|
||||
detail::inplace_greater_than_serial(a, c);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T greater_than(const T a, const T c) {
|
||||
T out = a;
|
||||
inplace_greater_than(out, c);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void inplace_greater_than(utils::Vector<T>& v, const T c) {
|
||||
detail::inplace_greater_than_serial(v, c);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline utils::Vector<T> greater_than(const utils::Vector<T>& v, const T c) {
|
||||
utils::Vector<T> out = v;
|
||||
inplace_greater_than(out, c);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline void inplace_greater_than(utils::Matrix<T>& A, const T c) {
|
||||
detail::inplace_greater_than_serial(A, c);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline utils::Matrix<T> greater_than(const utils::Matrix<T>& A, const T c) {
|
||||
utils::Matrix<T> out = A;
|
||||
inplace_greater_than(out, c);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
+25
-2
@@ -11,7 +11,6 @@ namespace numerics{
|
||||
inline void inplace_div(utils::Matrix<T>& A, const T b) {
|
||||
detail::inplace_div_scalar_serial(A,b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline utils::Matrix<T> div(const utils::Matrix<T>& A, const T b) {
|
||||
utils::Matrix<T> out = A;
|
||||
@@ -19,17 +18,41 @@ namespace numerics{
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void inplace_div(const T b, utils::Matrix<T>& A) {
|
||||
detail::inplace_div_scalar_serial(b, A);
|
||||
}
|
||||
template <typename T>
|
||||
inline utils::Matrix<T> div(const T b, const utils::Matrix<T>& A) {
|
||||
utils::Matrix<T> out = A;
|
||||
inplace_div(b, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline void inplace_div(utils::Vector<T>& v, const T b) {
|
||||
detail::inplace_div_scalar_serial(v,b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline utils::Vector<T> div(const utils::Vector<T>& v, const T b) {
|
||||
utils::Vector<T> out = v;
|
||||
inplace_div(out, b);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void inplace_div(const T b, utils::Vector<T>& v) {
|
||||
detail::inplace_div_scalar_serial(b, v);
|
||||
}
|
||||
template <typename T>
|
||||
inline utils::Vector<T> div(const T b, const utils::Vector<T>& v) {
|
||||
utils::Vector<T> out = v;
|
||||
inplace_div(b, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// ---------------- Elementwise ----------------
|
||||
template <typename T>
|
||||
inline void inplace_div(utils::Matrix<T>& A, const utils::Matrix<T>& B) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "./numerics/add.h"
|
||||
#include "./numerics/argmax.h"
|
||||
#include "./numerics/argmin.h"
|
||||
#include "./numerics/binary_threshold.h"
|
||||
#include "./numerics/clip.h"
|
||||
#include "./numerics/div.h"
|
||||
#include "./numerics/dot.h"
|
||||
|
||||
@@ -11,6 +11,11 @@ namespace numerics{
|
||||
inline void inplace_sub(utils::Matrix<T>& A, const T b) {
|
||||
detail::inplace_sub_scalar_serial(A,b);
|
||||
}
|
||||
template <typename T>
|
||||
inline void inplace_sub(const T b, utils::Matrix<T>& A) {
|
||||
detail::inplace_sub_scalar_serial(b,A);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline utils::Matrix<T> sub(const utils::Matrix<T>& A, const T b) {
|
||||
@@ -18,11 +23,22 @@ namespace numerics{
|
||||
inplace_sub(out, b);
|
||||
return out;
|
||||
}
|
||||
template <typename T>
|
||||
inline utils::Matrix<T> sub(const T b, const utils::Matrix<T>& A) {
|
||||
utils::Matrix<T> out = A;
|
||||
inplace_sub(b, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline void inplace_sub(utils::Vector<T>& v, const T b) {
|
||||
detail::inplace_sub_scalar_serial(v,b);
|
||||
}
|
||||
template <typename T>
|
||||
inline void inplace_sub(const T b, utils::Vector<T>& v) {
|
||||
detail::inplace_sub_scalar_serial(b,v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline utils::Vector<T> sub(const utils::Vector<T>& v, const T b) {
|
||||
@@ -30,6 +46,14 @@ namespace numerics{
|
||||
inplace_sub(out, b);
|
||||
return out;
|
||||
}
|
||||
template <typename T>
|
||||
inline utils::Vector<T> sub(const T b, const utils::Vector<T>& v) {
|
||||
utils::Vector<T> out = v;
|
||||
inplace_sub(b, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// ---------------- Elementwise ----------------
|
||||
template <typename T>
|
||||
inline void inplace_sub(utils::Matrix<T>& A, const utils::Matrix<T>& B) {
|
||||
|
||||
Reference in New Issue
Block a user