Changeset 1189 for trunk/yat/classifier/NCC.h
 Timestamp:
 Feb 29, 2008, 12:58:04 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/NCC.h
r1174 r1189 50 50 51 51 52 /// 53 /// @brief Class for Nearest Centroid Classification. 54 /// 55 /// The template argument Distance should be a class modelling 56 /// the concept \ref concept_distance. 57 /// 52 /** 53 \brief Nearest Centroid Classifier 54 55 A sample is predicted based on its distance to centroids for each 56 class. The centroids are generated using training data. NCC 57 supports using different measures, for example, Euclidean 58 distance, to define distance between samples and centroids. 59 60 The template argument Distance should be a class modelling 61 the concept \ref concept_distance. 62 */ 58 63 template <typename Distance> 59 64 class NCC : public SupervisedClassifier … … 61 66 62 67 public: 63 /// 64 /// @brief Constructor 65 /// 68 /** 69 \brief Constructor 70 71 Distance is initialized using its default constructor. 72 */ 66 73 NCC(void); 67 74 68 /// 69 /// @brief Constructor 70 /// 75 /** 76 \brief Constructor using an initialized distance measure 77 78 This constructor should be used if Distance has parameters and 79 the user wants to specify the parameters by initializing 80 Distance prior to constructing the NCC. 81 */ 71 82 NCC(const Distance&); 72 83 73 84 74 / //75 /// @briefDestructor76 ///85 /** 86 Destructor 87 */ 77 88 virtual ~NCC(void); 78 89 79 /// 80 /// @return the centroids for each class as columns in a matrix. 81 /// 90 /** 91 \brief Get the centroids for all classes. 92 93 \return The centroids for each class as columns in a matrix. 94 */ 82 95 const utility::Matrix& centroids(void) const; 83 96 84 97 NCC<Distance>* make_classifier(void) const; 85 86 /// 87 /// Train the classifier with a training data set and 88 /// targets. Centroids are calculated for each class. 89 /// 90 void train(const MatrixLookup&, const Target&); 91 92 93 /// 94 /// Train the classifier with a weighted training data set and 95 /// targets. Centroids are calculated for each class. 96 /// 97 void train(const MatrixLookupWeighted&, const Target&); 98 99 100 /// 101 /// Calculate the distance to each centroid for test samples 102 /// 103 void predict(const MatrixLookup&, utility::Matrix&) const; 104 105 /// 106 /// Calculate the distance to each centroid for weighted test samples 107 /// 108 void predict(const MatrixLookupWeighted&, utility::Matrix&) const; 98 99 /** 100 \brief Make predictions for unweighted test data. 101 102 Predictions are calculated and returned in \a results. For 103 each sample in \a data, \a results contains the distances to 104 the centroids for each class. If a class has no training 105 samples NaN's are returned for this class in \a 106 results. Weighted distance calculations, in which NaN's have 107 zero weights, are used if the centroids contain NaN's. 108 109 \note NCC returns distances to centroids as the 110 prediction. This means that the best class for a sample has the 111 smallest value in \a results. This is in contrast to, for 112 example, KNN for which the best class for a sample in \a 113 results has the largest number (the largest number of nearest 114 neighbors). 115 */ 116 void predict(const MatrixLookup& data, utility::Matrix& results) const; 117 118 /** 119 \brief Make predictions for weighted test data. 120 121 Predictions are calculated and returned in \a results. For 122 each sample in \a data, \a results contains the distances to 123 the centroids for each class as in predict(const MatrixLookup& 124 data, utility::Matrix& results). Weighted distance calculations 125 are used, and zero weights are used for NaN's in centroids. If 126 for a test sample and centroid pair, all variables have either 127 zero weight for the test sample or NaN for the centroid, the 128 centroid and the sample have no variables with values in 129 common. In this case the prediction for the sample is set to 130 NaN for the class in \a results. 131 132 \note NCC returns distances to centroids as the 133 prediction. This means that the best class for a sample has the 134 smallest value in \a results. This is in contrast to, for 135 example, KNN for which the best class for a sample in \a 136 results has the largest number (the largest number of nearest 137 neighbors). 138 */ 139 void predict(const MatrixLookupWeighted& data, utility::Matrix& results) const; 140 141 /** 142 \brief Train the NCC using unweighted training data with known 143 targets. 144 145 A centroid is calculated for each class. For each variable in 146 \a data, a centroid for a class contains the average value of 147 the variable across all training samples in the class. 148 */ 149 void train(const MatrixLookup& data, const Target& targets); 150 151 152 /** 153 \brief Train the NCC using weighted training data with known 154 targets. 155 156 A centroid is calculated for each class as in 157 train(const MatrixLookup&, const Target&). 158 The weights of the data are used when calculating the centroids 159 and the centroids should be interpreted as unweighted 160 (i.e. centroid values have unity weights). If a variable has 161 zero weights for all samples in a class, the centroid is set to 162 NaN for that variable. 163 */ 164 void train(const MatrixLookupWeighted& data, const Target& targets); 109 165 110 166 … … 117 173 bool centroids_nan_; 118 174 Distance distance_; 119 }; 120 121 /// 122 /// The output operator for the NCC class. 123 /// 124 // std::ostream& operator<< (std::ostream&, const NCC&); 125 175 }; 126 176 127 177 // templates
Note: See TracChangeset
for help on using the changeset viewer.