|
| | NNC () |
| |
| | NNC (const size_t &k) |
| |
| | NNC (const arma::Mat< T > &inputs, const arma::Row< size_t > &labels, const size_t &num_class, const size_t &k) |
| |
| | NNC (const arma::Mat< T > &inputs, const arma::Row< size_t > &labels, const size_t &num_class) |
| |
| void | Train (const arma::Mat< T > &inputs, const arma::Row< size_t > &labels) |
| |
| void | Train (const arma::Mat< T > &inputs, const arma::Row< size_t > &labels, const size_t num_class) |
| |
| void | Classify (const arma::Mat< T > &inputs, arma::Row< size_t > &labels) const |
| |
| void | Classify (const arma::Mat< T > &inputs, arma::Row< size_t > &labels, arma::Mat< T > &probs) const |
| |
| T | ComputeError (const arma::Mat< T > &points, const arma::Row< size_t > &responses) const |
| |
| T | ComputeAccuracy (const arma::Mat< T > &points, const arma::Row< size_t > &responses) const |
| |
| template<typename Archive > |
| void | serialize (Archive &ar, const unsigned int) |
| |
template<class T = DTYPE>
class algo::classification::NNC< T >
Definition at line 19 of file nonparamclass.h.
◆ NNC() [1/4]
template<class T = DTYPE>
◆ NNC() [2/4]
template<class T = DTYPE>
◆ NNC() [3/4]
template<class T >
| algo::classification::NNC< T >::NNC |
( |
const arma::Mat< T > & |
inputs, |
|
|
const arma::Row< size_t > & |
labels, |
|
|
const size_t & |
num_class, |
|
|
const size_t & |
k |
|
) |
| |
◆ NNC() [4/4]
◆ Classify() [1/2]
- Parameters
-
Definition at line 63 of file nonparamclass_impl.h.
void Classify(const arma::Mat< T > &inputs, arma::Row< size_t > &labels) const
◆ Classify() [2/2]
template<class T >
| void algo::classification::NNC< T >::Classify |
( |
const arma::Mat< T > & |
inputs, |
|
|
arma::Row< size_t > & |
labels, |
|
|
arma::Mat< T > & |
probs |
|
) |
| const |
- Parameters
-
| inputs | : X* |
| labels | : y* |
| probs | : probabilties per class |
Definition at line 71 of file nonparamclass_impl.h.
75 const size_t N = inputs.n_cols;
76 probs.resize(nclass_,N);
80 labels.fill(unique_(0));
81 probs.row(unique_(0)).fill(1);
87 mlpack::KNN knn(inputs_);
89 arma::Mat<size_t> neig;
90 arma::Mat<size_t> select;
93 knn.Search(inputs, k_, neig, dist);
94 arma::Col<size_t> unq;
98 for (
size_t j=0; j<N; j++ )
101 select = labels_(arma::conv_to<arma::uvec>::from(neig.col(j)));
103 auto count = arma::hist(select,unique_);
105 arma::conv_to<arma::Col<T>>::from(count);
106 probs.col(j) = ps / arma::accu(ps);
108 labels(j) = unique_(count.index_max());
◆ ComputeAccuracy()
template<class T >
| T algo::classification::NNC< T >::ComputeAccuracy |
( |
const arma::Mat< T > & |
points, |
|
|
const arma::Row< size_t > & |
responses |
|
) |
| const |
Calculate the Accuracy
- Parameters
-
Definition at line 126 of file nonparamclass_impl.h.
T ComputeError(const arma::Mat< T > &points, const arma::Row< size_t > &responses) const
◆ ComputeError()
template<class T >
| T algo::classification::NNC< T >::ComputeError |
( |
const arma::Mat< T > & |
points, |
|
|
const arma::Row< size_t > & |
responses |
|
) |
| const |
Calculate the Error Rate
- Parameters
-
Definition at line 114 of file nonparamclass_impl.h.
117 arma::Row<size_t> predictions;
119 arma::Row<size_t> temp = predictions - responses;
120 double total = responses.n_cols;
122 return (arma::accu(temp != 0))/total;
◆ serialize()
template<class T = DTYPE>
template<typename Archive >
Serialize the model.
Definition at line 105 of file nonparamclass.h.
108 ar ( cereal::make_nvp(
"dim",dim_),
109 cereal::make_nvp(
"nuclass",nuclass_),
110 cereal::make_nvp(
"nclass",nclass_),
111 cereal::make_nvp(
"size",size_),
112 cereal::make_nvp(
"unique",unique_),
113 cereal::make_nvp(
"k",k_),
114 cereal::make_nvp(
"inputs",inputs_),
115 cereal::make_nvp(
"labels",labels_) );
◆ Train() [1/2]
- Parameters
-
Definition at line 36 of file nonparamclass_impl.h.
40 nuclass_ = arma::unique(labels).eval().n_elem;
42 unique_ = arma::unique(labels);
44 unique_ = arma::regspace<arma::Row<size_t>>(0,nclass_-1);
46 size_ = inputs.n_cols;
49 if ( k_ > inputs.n_cols )
Referenced by algo::classification::NNC< T >::NNC().
◆ Train() [2/2]
template<class T >
| void algo::classification::NNC< T >::Train |
( |
const arma::Mat< T > & |
inputs, |
|
|
const arma::Row< size_t > & |
labels, |
|
|
const size_t |
num_class |
|
) |
| |
- Parameters
-
| inputs | : X |
| labels | : y |
| num_class | : number of classes |
Definition at line 54 of file nonparamclass_impl.h.
58 this ->nuclass_ = num_class;
59 this ->
Train(inputs,labels);
The documentation for this class was generated from the following files: