10#ifndef VECTOR_OPS_FOR_NN
11#define VECTOR_OPS_FOR_NN
36 for (
const auto &a : A) {
37 for (
const auto &x : a) {
56 std::cout <<
"(" << A.first <<
", " << A.second <<
")";
70 for (
const auto &a : A) {
87 B.resize(A.size() + 1);
88 for (
size_t i = 0; i < A.size(); i++) {
91 B[B.size() - 1] = ele;
104 B.resize(A.size() - 1);
105 for (
size_t i = 1; i < A.size();
121 B.resize(A.size() - 1);
122 for (
size_t i = 0; i < A.size() - 1;
139 if (A.size() != B.size()) {
140 std::cerr <<
"ERROR (" << __func__ <<
") : ";
142 <<
"Can not equally shuffle two vectors with different sizes: ";
146 for (
size_t i = 0; i < A.size(); i++) {
149 size_t random_index =
std::rand() % A.size();
168 const T &low,
const T &high) {
174 for (
size_t i = 0; i < shape.first; i++) {
177 row.resize(shape.second);
178 for (
auto &r : row) {
179 r = distribution(generator);
196 for (
size_t i = 0; i < shape.first; i++) {
199 row.resize(shape.second);
216 for (
size_t i = 0; i < shape.first; i++) {
219 row.resize(shape.second);
234 for (
const auto &a : A) {
248 const size_t sub_size = (*A.begin()).size();
249 for (
const auto &a : A) {
251 if (a.size() != sub_size) {
252 std::cerr <<
"ERROR (" << __func__ <<
") : ";
277 if (shape.first != 1) {
278 std::cerr <<
"ERROR (" << __func__ <<
") : ";
280 <<
"Supplied vector is not supported for minmax scaling, shape: ";
284 for (
size_t i = 0; i < shape.second; i++) {
285 T min = B[0][0][i], max = B[0][0][i];
286 for (
size_t j = 0; j < B.
size(); j++) {
291 for (
size_t j = 0; j < B.
size(); j++) {
294 ((B[j][0][i] - min) / (max - min)) * (high - low) + low;
311 if (shape.first != 1) {
312 std::cerr <<
"ERROR (" << __func__ <<
") : ";
387 for (
size_t j = 0; j < shape.second; j++) {
389 row.resize(shape.first);
390 for (
size_t i = 0; i < shape.first; i++) {
412 if (shape_a.first != shape_b.first || shape_a.second != shape_b.second) {
413 std::cerr <<
"ERROR (" << __func__ <<
") : ";
414 std::cerr <<
"Supplied vectors have different shapes ";
419 for (
size_t i = 0; i < A.size(); i++) {
439 if (shape_a.first != shape_b.first || shape_a.second != shape_b.second) {
440 std::cerr <<
"ERROR (" << __func__ <<
") : ";
441 std::cerr <<
"Supplied vectors have different shapes ";
446 for (
size_t i = 0; i < A.size(); i++) {
465 if (shape_a.second != shape_b.first) {
466 std::cerr <<
"ERROR (" << __func__ <<
") : ";
467 std::cerr <<
"Vectors are not eligible for multiplication ";
473 for (
size_t i = 0; i < shape_a.first; i++) {
475 row.resize(shape_b.second);
476 for (
size_t j = 0; j < shape_b.second; j++) {
477 for (
size_t k = 0; k < shape_a.second; k++) {
478 row[j] += A[i][k] * B[k][j];
500 if (shape_a.first != shape_b.first || shape_a.second != shape_b.second) {
501 std::cerr <<
"ERROR (" << __func__ <<
") : ";
502 std::cerr <<
"Vectors have different shapes ";
507 for (
size_t i = 0; i < A.size(); i++) {
std::vector< std::valarray< T > > operator-(const std::vector< std::valarray< T > > &A, const std::vector< std::valarray< T > > &B)
Definition vector_ops.hpp:433
std::vector< std::valarray< T > > operator*(const std::vector< std::valarray< T > > &A, const T &val)
Definition vector_ops.hpp:347
std::vector< std::valarray< T > > operator+(const std::vector< std::valarray< T > > &A, const std::vector< std::valarray< T > > &B)
Definition vector_ops.hpp:406
std::valarray< T > insert_element(const std::valarray< T > &A, const T &ele)
Definition vector_ops.hpp:85
size_t argmax(const std::vector< std::valarray< T > > &A)
Definition vector_ops.hpp:307
std::vector< std::valarray< T > > multiply(const std::vector< std::valarray< T > > &A, const std::vector< std::valarray< T > > &B)
Definition vector_ops.hpp:460
T sum(const std::vector< std::valarray< T > > &A)
Definition vector_ops.hpp:232
std::ostream & operator<<(std::ostream &out, std::vector< std::valarray< T > > const &A)
Definition vector_ops.hpp:32
std::vector< std::valarray< T > > transpose(const std::vector< std::valarray< T > > &A)
Definition vector_ops.hpp:382
void unit_matrix_initialization(std::vector< std::valarray< T > > &A, const std::pair< size_t, size_t > &shape)
Definition vector_ops.hpp:193
std::valarray< T > pop_front(const std::valarray< T > &A)
Definition vector_ops.hpp:102
std::pair< size_t, size_t > get_shape(const std::vector< std::valarray< T > > &A)
Definition vector_ops.hpp:247
void uniform_random_initialization(std::vector< std::valarray< T > > &A, const std::pair< size_t, size_t > &shape, const T &low, const T &high)
Definition vector_ops.hpp:166
void zeroes_initialization(std::vector< std::valarray< T > > &A, const std::pair< size_t, size_t > &shape)
Definition vector_ops.hpp:213
std::vector< std::vector< std::valarray< T > > > minmax_scaler(const std::vector< std::vector< std::valarray< T > > > &A, const T &low, const T &high)
Definition vector_ops.hpp:269
std::vector< std::valarray< T > > hadamard_product(const std::vector< std::valarray< T > > &A, const std::vector< std::valarray< T > > &B)
Definition vector_ops.hpp:494
std::vector< std::valarray< T > > apply_function(const std::vector< std::valarray< T > > &A, T(*func)(const T &))
Definition vector_ops.hpp:329
std::valarray< T > pop_back(const std::valarray< T > &A)
Definition vector_ops.hpp:119
std::vector< std::valarray< T > > operator/(const std::vector< std::valarray< T > > &A, const T &val)
Definition vector_ops.hpp:365
void equal_shuffle(std::vector< std::vector< std::valarray< T > > > &A, std::vector< std::vector< std::valarray< T > > > &B)
Definition vector_ops.hpp:136