philsupertramp/game-math
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
NCC Class Reference

#include <NCC.h>

Inheritance diagram for NCC:
Classifier Predictor

Public Member Functions

 NCC (bool useIterative)
 
void fit (const Matrix< double > &X, const Matrix< double > &y) override
 
void fit_batch (const Matrix< double > &X, const Matrix< double > &y, const Matrix< double > &labels)
 
void fit_iterative (const Matrix< double > &X, const Matrix< double > &y, const Matrix< double > &labels)
 
Matrix< double > predict (const Matrix< double > &x) override
 
- Public Member Functions inherited from Classifier
 Classifier ()
 
void initialize_weights (size_t numRows, size_t numColumns=1)
 
void update_weights (const Matrix< double > &update, const Matrix< double > &delta)
 
Matrix< double > transform (const Matrix< double > &in) override
 
virtual void fit (const Matrix< double > &X, const Matrix< double > &y)=0
 
virtual Matrix< double > predict (const Matrix< double > &)=0
 
virtual Matrix< double > transform (const Matrix< double > &)=0
 

Private Attributes

bool use_iterative = true
 

Additional Inherited Members

- Public Attributes inherited from Classifier
Matrix< double > weights
 Vector holding weights. More...
 
Matrix< double > costs
 Vector holding classification error per epoch. More...
 
- Protected Attributes inherited from Classifier
bool w_initialized = false
 flag to initialize weights only once More...
 

Detailed Description

$: $N$ training sample lables Out: $\mu_k$: $K$ class centroids

Calculates centroids iteratively, holds $K$ centroids and 1 training sample in memory at-a-time.

Examples
ds/TestNCC.cpp.

Constructor & Destructor Documentation

◆ NCC()

NCC::NCC ( bool  useIterative)
inline

Member Function Documentation

◆ fit()

void NCC::fit ( const Matrix< double > &  X,
const Matrix< double > &  y 
)
inlineoverridevirtual

Implements training algorithm

Parameters
Xarray-like with the shape: [n_samples, n_features]
yarray-like with shape: [n_samples, 1]
Returns
this

Implements Predictor.

◆ fit_batch()

void NCC::fit_batch ( const Matrix< double > &  X,
const Matrix< double > &  y,
const Matrix< double > &  labels 
)
inline

Batch-wise implementation of nearest centroid classifier centroid calculation.

Note: Requires all input data in memory.

Complexity: O(K * 6N)

Parameters
Xgiven input data to calculate centroids from
ygiven labels for input data X
labelsunique labels inside y

◆ fit_iterative()

void NCC::fit_iterative ( const Matrix< double > &  X,
const Matrix< double > &  y,
const Matrix< double > &  labels 
)
inline

Iterative implementation of nearest centroid classifier centroid calculation

Note: Allows streaming of input data.

Complexity: O(N * 3D)

Parameters
Xinput data to calculate centroids from
ygiven labels for input data X
labelsunique labels inside y

◆ predict()

Matrix< double > NCC::predict ( const Matrix< double > &  x)
inlineoverridevirtual

Prediction: In: $x$: Data point to classify $\mu_k$: $k$ class centroids Out: $$ argmin(||\mu_k - x||_2) $$

Implements Predictor.

Member Data Documentation

◆ use_iterative

bool NCC::use_iterative = true
private

The documentation for this class was generated from the following file: