37#include "../matrix_utils.h"
38#include "../numerics/utils.h"
53 NCC(
bool useIterative)
86 for(
size_t i = 0; i < labels.
rows(); ++i) {
87 std::function<bool(
double)> condition = [i](
double x) {
return bool(x == i); };
89 auto yis =
where(condition, y, { { 1 } }, { { 0 } });
91 auto Nk = yis.sumElements();
114 for(
size_t i = 0; i < X.
rows(); ++i) {
117 auto current_counter = counters(k, 0);
122 weights.
GetSlice(k, k) * (current_counter /
double(current_counter + 1))
124 + xi * (1. /
double(current_counter + 1)));
143 for(
size_t i = 0; i < x.
rows(); ++i) {
146 predictions(i, 0) =
argmin(distances);
Definition: Classifier.h:22
Matrix< double > weights
Vector holding weights.
Definition: Classifier.h:29
void SetSlice(const size_t &row_start, const size_t &row_end, const size_t &col_start, const size_t &col_end, const Matrix< T > &slice)
Definition: Matrix.h:641
size_t rows() const
Definition: Matrix.h:193
size_t columns() const
Definition: Matrix.h:198
Matrix GetSlice(size_t rowStart) const
Definition: Matrix.h:609
Matrix< T > GetSlicesByIndex(const Matrix< size_t > &indices) const
Definition: Matrix.h:679
Matrix< double > predict(const Matrix< double > &x) override
Definition: NCC.h:141
void fit_iterative(const Matrix< double > &X, const Matrix< double > &y, const Matrix< double > &labels)
Definition: NCC.h:111
NCC(bool useIterative)
Definition: NCC.h:53
void fit(const Matrix< double > &X, const Matrix< double > &y) override
Definition: NCC.h:60
void fit_batch(const Matrix< double > &X, const Matrix< double > &y, const Matrix< double > &labels)
Definition: NCC.h:82
bool use_iterative
Definition: NCC.h:50
Matrix< size_t > where_true(const Matrix< T > &in)
Definition: matrix_utils.h:246
size_t argmin(const Matrix< T > &mat)
Definition: matrix_utils.h:167
Matrix< T > unique(const Matrix< T > &in, int axis=0)
Definition: matrix_utils.h:466
Matrix< T > where(const std::function< bool(T)> &condition, const Matrix< T > &in, const Matrix< T > &valIfTrue, const Matrix< T > &valIfFalse)
Definition: matrix_utils.h:194
double norm(const Matrix< double > &in)
Matrix< double > zerosV(size_t rows)
Matrix< double > zeros(size_t rows, size_t columns, size_t elements=1)