Xmipp
v3.23.11-Nereus
xmipp
libraries
classification
knn_classifier.h
Go to the documentation of this file.
1
/***************************************************************************
2
*
3
* Authors: Vahid Abrishami (vabrishami@cnb.csic.es)
4
*
5
* Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6
*
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
* 02111-1307 USA
21
*
22
* All comments concerning this program package may be sent to the
23
* e-mail address 'xmipp@cnb.csic.es'
24
***************************************************************************/
25
26
#ifndef KNN_CLASSIFIER_HH
27
#define KNN_CLASSIFIER_HH
28
29
/* Includes-----------------------------------------------------------------*/
30
#include <
core/multidim_array.h
>
31
41
class
KNN
42
{
43
public
:
45
typedef
enum
{
EUCLIDEAN
= 0,
CITYBLOCK
= 1}
distType
;
46
51
KNN
(
int
k
);
52
57
void
train
(
MultidimArray<double>
&dataset,
MultidimArray<double>
&dataLabel,
58
MultidimArray<double>
&labelset);
59
64
int
predict
(
MultidimArray<double>
&sample,
double
&score);
65
67
void
KNearestNeighbors
(
MultidimArray<double>
&sample);
68
69
#ifdef UNUSED // detected as unused 29.6.2018
70
void
saveModel(
const
FileName
&fn);
72
74
void
loadModel(
const
FileName
&fn);
75
#endif
76
78
void
setK
(
int
k);
79
80
private
:
82
double
euclideanDistance(
MultidimArray<double>
&sample,
int
index
,
double
maximumDist);
83
84
#ifdef UNUSED // detected as unused 29.6.2018
85
double
cityBlockDistance(
MultidimArray<double>
&sample,
int
index,
double
maximumDist);
87
#endif
88
90
int
findMaxIndex(
MultidimArray<double>
&inputArray);
91
93
int
findMinIndex(
MultidimArray<double>
&inputArray);
94
95
private
:
97
int
K;
98
100
MultidimArray<double>
__dataset;
101
103
MultidimArray<double>
__dataLabel;
104
106
MultidimArray<double>
__labelSet;
107
109
MultidimArray<int>
neighborsIndex;
110
112
MultidimArray<double>
maxDist;
113
};
115
#endif
KNN
Definition:
knn_classifier.h:41
MultidimArray< double >
KNN::train
void train(MultidimArray< double > &dataset, MultidimArray< double > &dataLabel, MultidimArray< double > &labelset)
Definition:
knn_classifier.cpp:34
FileName
Definition:
xmipp_filename.h:65
k
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
KNN::CITYBLOCK
Definition:
knn_classifier.h:45
index
viol index
Definition:
numerical_recipes.cpp:5197
KNN::setK
void setK(int k)
Method for setting the K.
Definition:
knn_classifier.cpp:193
KNN::distType
distType
Type of distance.
Definition:
knn_classifier.h:45
KNN::KNearestNeighbors
void KNearestNeighbors(MultidimArray< double > &sample)
Compute the K nearest neighbors to the sample.
Definition:
knn_classifier.cpp:42
KNN::KNN
KNN(int k)
Definition:
knn_classifier.cpp:28
KNN::EUCLIDEAN
Definition:
knn_classifier.h:45
KNN::predict
int predict(MultidimArray< double > &sample, double &score)
Definition:
knn_classifier.cpp:70
multidim_array.h
Generated by
1.8.13