Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
classifier_normal_bayes.hpp
Go to the documentation of this file.
1#ifndef FSTCLASSIFIERNORMALBAYES_H
2#define FSTCLASSIFIERNORMALBAYES_H
3 /*
27=========================================================================
28Copyright and license:
29 * FST4 software (with the exception of any bundled or externally linked
30 third-party components) is Copyright (C) 2000-present Institute of
31 Information Theory and Automation of the Czech Academy of Sciences (UTIA).
32 * FST4 is free software: you can redistribute it and/or modify it under
33 the terms of the GNU Affero General Public License as published by the
34 Free Software Foundation, version 3. The full text of the license is in
35 the file LICENSE in the distribution root and at
36 https://www.gnu.org/licenses/agpl-3.0.html.
37 * FST4 is distributed in the hope that it will be useful, but WITHOUT ANY
38 WARRANTY; without even the implied warranty of MERCHANTABILITY or
39 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
40 License for more details.
41 * Closed-source use without the AGPL's copyleft obligations requires a
42 commercial license from UTIA; in case of interest write to
43 utia@utia.cas.cz. LICENSING.md in the distribution root explains both
44 options, the contributor license agreement that every contribution
45 requires, and the contacts (technical questions and pull requests:
46 somol@utia.cas.cz, with "FST" in the subject line).
47========================================================================== */
48
49#include <memory>
50#include <cassert>
51#include <iostream>
52#include <sstream>
53#include <cmath>
54#ifndef M_PI
55#define M_PI 3.14159265358979323846
56#endif
57#include <cstring> // memcpy
58#include "error.hpp"
59#include "global.hpp"
60#include "classifier.hpp"
61#include "model_normal.hpp"
62#include "indexed_matrix.hpp"
63
64/*============== Template parameter type naming conventions ==============
65--------- Numeric types: -------------------------------------------------
66DATATYPE - data sample values - usually real numbers (but may be integers
67 in text processing etc.)
68REALTYPE - must be real numbers - for representing intermediate results of
69 calculations like mean, covariance etc.
70IDXTYPE - index values for enumeration of data samples - (nonnegative) integers,
71 extent depends on numbers of samples in data
72DIMTYPE - index values for enumeration of features (dimensions), or classes (not
73 class sizes) - (nonnegative) integers, usually lower extent than IDXTYPE,
74 but be aware of expressions like _classes*_features*_features !
75 in linearized representations of feature matrices for all classes
76BINTYPE - feature selection marker type - represents ca. <10 different feature
77 states (selected, deselected, sel./desel. temporarily 1st nested loop, 2nd...)
78RETURNTYPE - criterion value: real value, but may be extended in future to support
79 multiple values
80--------- Class types: ---------------------------------------------------
81SUBSET - class of class type Subset
82CLASSIFIER - class implementing interface defined in abstract class Classifier
83EVALUATOR - class implementing interface defined in abstract class Sequential_Step
84DISTANCE - class implementing interface defined in abstract class Distance
85DATAACCESSOR - class implementing interface defined in abstract class Data_Accessor
86INTERVALCONTAINER - class of class type Data_Intervaller
87CONTAINER - STL container of class type Data_Interval
88========================================================================== */
89
90namespace FST {
91
115template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
116class Classifier_Normal_Bayes : public Clonable_Impl<Classifier_Normal_Bayes<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>,Classifier<RETURNTYPE,DIMTYPE,SUBSET,DATAACCESSOR> > {
117public:
119 typedef std::shared_ptr<DATAACCESSOR> PDataAccessor;
120 typedef std::shared_ptr<SUBSET> const PSubset;
121 typedef typename DATAACCESSOR::PPattern PPattern;
122 Classifier_Normal_Bayes();
123 virtual ~Classifier_Normal_Bayes() {notify("Classifier_Normal_Bayes destructor.");}
124
130 void enable_prelearn_mode(const PDataAccessor da);
132 bool get_prelearn_mode() const {return _prelearn_mode;}
133
140 void initialize(const PDataAccessor da);
141
142 virtual bool classify(DIMTYPE &cls, const PPattern &pattern) override; // classifies pattern, returns the respective class index
143 virtual bool classify_scores(std::vector<RETURNTYPE> &scores, const PPattern &pattern) override
144 { // per-class posteriors P(class|x) for ranking metrics (AUC); classify() fills _Pwx on both its paths
145 DIMTYPE cls;
146 if(!classify(cls,pattern)) return false;
147 scores.resize(_classes);
148 for(DIMTYPE c=0;c<_classes;c++) scores[c]=(RETURNTYPE)_Pwx[c];
149 return true;
150 }
151 virtual bool train(const PDataAccessor da, const PSubset sub) override; // learns from designated training part of data
152 virtual bool test(RETURNTYPE &result, const PDataAccessor da) override; // estimates accuracy using designated test data
153
154 DIMTYPE get_n() const {assert(_model); return _model->get_n();}
155 DIMTYPE get_d() const {assert(_model); return _model->get_d();}
156
157
158
159 virtual std::ostream& print(std::ostream& os) const override {os << "Classifier_Normal_Bayes()"; return os;}
160private:
161 friend parent_impl;
164 Classifier_Normal_Bayes(const Classifier_Normal_Bayes& cnb); // copy-constructor
165protected:
166 std::unique_ptr<Model_Normal<DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR> > _model;
167
168 DIMTYPE _classes;
169 DIMTYPE _features;
170 std::unique_ptr<Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET> > _LUtemp;
171 std::unique_ptr<Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET>[]> _inverse;
172 std::unique_ptr<REALTYPE[]> _det;
173 std::unique_ptr<REALTYPE[]> _constant;
174 std::unique_ptr<REALTYPE[]> _pxw;
175 std::unique_ptr<REALTYPE[]> _Pwx;
176 std::unique_ptr<REALTYPE[]> _log_constant;
177 std::unique_ptr<REALTYPE[]> _ecoef;
178
179private:
181 std::unique_ptr<DIMTYPE[]> _index;
182 DIMTYPE _subfeatures;
183};
184
185template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
186Classifier_Normal_Bayes<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>::Classifier_Normal_Bayes(const Classifier_Normal_Bayes& cnb) :
187 _classes(cnb._classes),
188 _features(cnb._features),
191{
192 notify("Classifier_Normal_Bayes copy-constructor.");
195 if(_classes>0)
196 {
198 for(DIMTYPE c=0;c<_classes;c++) _inverse[c]=cnb._inverse[c];
199 _det.reset(new REALTYPE[_classes]); memcpy((void *)_det.get(),(void *)(cnb._det).get(),sizeof(REALTYPE)*_classes);
200 _constant.reset(new REALTYPE[_classes]); memcpy((void *)_constant.get(),(void *)(cnb._constant).get(),sizeof(REALTYPE)*_classes);
201 _pxw.reset(new REALTYPE[_classes]); memcpy((void *)_pxw.get(),(void *)(cnb._pxw).get(),sizeof(REALTYPE)*_classes);
202 _Pwx.reset(new REALTYPE[_classes]); memcpy((void *)_Pwx.get(),(void *)(cnb._Pwx).get(),sizeof(REALTYPE)*_classes);
203 if(cnb._log_constant) {_log_constant.reset(new REALTYPE[_classes]); memcpy((void *)_log_constant.get(),(void *)(cnb._log_constant).get(),sizeof(REALTYPE)*_classes);}
204 if(cnb._ecoef) {_ecoef.reset(new REALTYPE[_classes]); memcpy((void *)_ecoef.get(),(void *)(cnb._ecoef).get(),sizeof(REALTYPE)*_classes);}
205 }
206 _index.reset(new DIMTYPE[_features]); memcpy((void *)_index.get(),(void *)(cnb._index).get(),sizeof(DIMTYPE)*_features);
207}
208
209
210
211template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
212Classifier_Normal_Bayes<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>::Classifier_Normal_Bayes()
213{
214 notify("Classifier_Normal_Bayes constructor.");
216 _classes=0;
217 _features=0;
218 _subfeatures=0;
219 _prelearn_mode=false;
220}
221
222template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
224{
225 notify("Classifier_Normal_Bayes::init_prelearn_mode().");
226 assert(_model);
227 assert(da);
228 assert(da->getNoOfFeatures()>0);
229 assert(da->getNoOfClasses()>0);
230 _model->learn(da);
231 _prelearn_mode=true;
232}
233
234template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
236{
237 notify("Classifier_Normal_Bayes::initialize().");
238 assert(da);
239 assert(da->getNoOfFeatures()>0);
240 assert(da->getNoOfClasses()>0);
241
242 // (re)allocate buffers
243 if(!_LUtemp) _LUtemp.reset(new Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET>(da->getNoOfFeatures(),true));
244 if(da->getNoOfFeatures()>_LUtemp->get_n_max()) _LUtemp->reset(da->getNoOfFeatures(),true);
245 if(!_inverse || _classes!=da->getNoOfClasses()) _inverse.reset(new Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET>[da->getNoOfClasses()]);
246 for(DIMTYPE c=0;c<da->getNoOfClasses();c++) if(da->getNoOfFeatures()>_inverse[c].get_n_max()) _inverse[c].reset(da->getNoOfFeatures());
247 if(!_det || _classes!=da->getNoOfClasses()) _det.reset(new REALTYPE[da->getNoOfClasses()]);
248 if(!_constant || _classes!=da->getNoOfClasses()) _constant.reset(new REALTYPE[da->getNoOfClasses()]);
249 if(!_pxw || _classes!=da->getNoOfClasses()) _pxw.reset(new REALTYPE[da->getNoOfClasses()]);
250 if(!_Pwx || _classes!=da->getNoOfClasses()) _Pwx.reset(new REALTYPE[da->getNoOfClasses()]);
251 if(!_log_constant || _classes!=da->getNoOfClasses()) _log_constant.reset(new REALTYPE[da->getNoOfClasses()]);
252 if(!_ecoef || _classes!=da->getNoOfClasses()) _ecoef.reset(new REALTYPE[da->getNoOfClasses()]);
253 _classes=da->getNoOfClasses();
254
255 if(!_index || _features!=da->getNoOfFeatures()) _index.reset(new DIMTYPE[da->getNoOfFeatures()]);
256 _features=da->getNoOfFeatures();
257}
258
259template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
261{
262 // NOTE: initialize() must have been called for the current data shape (it allocates the
263 // per-class buffers this method fills). The model's mean/covariance are learned HERE,
264 // from the accessor's currently designated TRAIN part - which is why train() must be
265 // re-issued after every split change. When driven by Criterion_Wrapper, _prelearn_mode
266 // must therefore stay false (the default).
267
268 notify("Classifier_Normal_Bayes::train().");
269 assert(_model);
270 assert(da);
271 if(_prelearn_mode) assert(get_n()>0);
272 assert(da->getNoOfFeatures()>0);
273 assert(sub);
274 assert(sub->get_frozen_mode()==false);
275 if(_prelearn_mode) assert(sub->get_n_raw()==get_n());
276 assert(sub->get_n_raw()==da->getNoOfFeatures());
277
278 if(_prelearn_mode) _model->narrow_to(sub);
279 else {_model->learn(da,sub); _model->denarrow();}
280
281 // pre-compute matrix inverse, determinants depending on current subset
282 REALTYPE tmpval=2.0*M_PI; for(DIMTYPE f=1;f<sub->get_d_raw();f++) tmpval*=2.0*M_PI; // tmpval = (2*pi)^d; overflows to inf for large d, which is what _log_constant exists for
283 _LUtemp->redim(sub->get_d_raw());
284 for(DIMTYPE c=0; c<_model->get_classes(); c++)
285 {
286 _inverse[c].redim(get_d());
287 _model->get_cov()[c].LUdecompose(*_LUtemp);
288 _model->get_cov()[c].invert(_inverse[c],*_LUtemp);
289 _det[c]=_model->get_cov()[c].determinant(*_LUtemp);
290 _constant[c]=sqrt(tmpval*_det[c]);
291 // ln(_constant[c]) for the log-domain fallback in classify(), formed without ever
292 // building the overflowing product: ln sqrt((2pi)^d * det) = 0.5*(d*ln(2pi) + ln det)
293 _log_constant[c]=0.5*((REALTYPE)sub->get_d_raw()*std::log(2.0*M_PI)+_model->get_cov()[c].log_determinant(*_LUtemp));
294 }
295
296 // prepare feature subset index buffering
297 DIMTYPE f;
298 _subfeatures=0;
299 for(DIMTYPE fsel : sub->selected_features()) {assert(_subfeatures<get_n()); _index[_subfeatures++]=fsel;}
300
301#ifdef DEBUG
302 {
303 std::ostringstream sos; sos << "index: "; for(f=0;f<_subfeatures;f++) sos << _index[f] << " "; sos << std::endl;
304 syncout::print(std::cout,sos);
305 }
306#endif
307 assert(_subfeatures==sub->get_d_raw());
308 return true;
309}
310
311template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
313{
314 // NOTE: train() must have been called - it learns (or narrows) the model and fills
315 // _inverse[], _det[], _constant[], _log_constant[] and the _index map this method
316 // reads. \p pattern must point at a full, raw feature vector: it is indexed through
317 // _index, not pre-narrowed by the caller.
318 notify("Classifier_Normal_Bayes::classify().");
319 assert(_model);
320 assert(get_n()>0);
321 assert(_model->get_classes()>1);
322 assert(_classes==_model->get_classes());
323 assert(_index);
324 assert(_subfeatures==_model->get_d());
325 assert(_subfeatures>0);
326
327 DIMTYPE f1, f2;
328 DIMTYPE c_cand;
329 REALTYPE ecoef, px, tmpval;
330
331 // compute p(x|w) and p(x)
332 // NOTE on the three index conventions in the inner loop: the pattern is raw and mapped
333 // through _index; the model's mean is read with at(), i.e. through the model's own
334 // narrowing map; the inverse covariance is read with at_raw(), because invert()
335 // writes its result raw (unindexed) in subset order. All three therefore address the
336 // same subset position - do not "unify" them.
337 px=0.0;
338 for(c_cand=0;c_cand<_classes;c_cand++)
339 {
340 ecoef=0.0; // the Mahalanobis form (x-mean)^T * inv(cov) * (x-mean)
341 for(f1=0;f1<_subfeatures;f1++)
342 {
343 tmpval=0.0;
344 for(f2=0;f2<_subfeatures;f2++)
345 {
346 tmpval+=(pattern[_index[f2]]-_model->get_mean()[c_cand].at(f2))*_inverse[c_cand].at_raw(f2,f1);
347 }
348 ecoef+=tmpval*(pattern[_index[f1]]-_model->get_mean()[c_cand].at(f1));
349 }
350 _ecoef[c_cand]=ecoef; // buffered for the log-domain fallback below
351 _pxw[c_cand]=exp(-0.5*ecoef)/_constant[c_cand];
352 px+=_pxw[c_cand]*_model->get_Pc(c_cand);
353 }
354 // log-domain fallback: without it, exp() underflow on distant patterns or (2pi)^d overflow
355 // in high dimension yields px==0 (or inf/NaN) -> NaN posteriors -> the argmax below never
356 // fires -> systematic misclassification into class 0 on exactly the hard patterns. The
357 // fallback decides by log p(x|w)P(w) instead, which is mathematically the same argmax; the
358 // plain-domain path above is used unchanged whenever it is healthy.
359 // (A NaN px fails both tests below and so takes the fallback, as intended.)
360 if(!(px>(REALTYPE)0.0) || !std::isfinite(px)) {
361 REALTYPE lbest=0.0, lc;
362 for(c_cand=0;c_cand<_classes;c_cand++) {
363 lc=-0.5*_ecoef[c_cand]-_log_constant[c_cand]+std::log(_model->get_Pc(c_cand));
364 _Pwx[c_cand]=lc; // temporarily holds log-posteriors (unnormalized)
365 if(c_cand==0 || lc>lbest) {lbest=lc; cls=c_cand;}
366 }
367 // meaningful posteriors via max-shifted exponentiation
368 REALTYPE psum=0.0;
369 for(c_cand=0;c_cand<_classes;c_cand++) {_Pwx[c_cand]=exp(_Pwx[c_cand]-lbest); psum+=_Pwx[c_cand];}
370 for(c_cand=0;c_cand<_classes;c_cand++) {_Pwx[c_cand]/=psum; _pxw[c_cand]=_Pwx[c_cand];} // _pxw left proportional, no absolute scale survives the shift
371 return true;
372 }
373 // compute P(w|x)
374 for(c_cand=0;c_cand<_classes;c_cand++) _Pwx[c_cand]=(_pxw[c_cand]*_model->get_Pc(c_cand))/px;
375 // find maximum P(w|x)
376 tmpval=_Pwx[0]; cls=0;
377 for(c_cand=1;c_cand<_classes;c_cand++) if(_Pwx[c_cand]>tmpval) {tmpval=_Pwx[c_cand]; cls=c_cand;}
378
379 return true;
380}
381
382template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
384{
385 // NOTE: train() must have been called for the subset being tested (it fills the model and
386 // the per-class buffers classify() reads); the accessor must be positioned on the
387 // split whose TEST part is to be classified
388 notify("Classifier_Normal_Bayes::test().");
389 assert(_model);
390 assert(get_n()>0);
391 assert(_model->get_classes()>1);
392 assert(_classes==_model->get_classes());
393 assert(da);
394 if(_prelearn_mode) assert(da->getNoOfFeatures()==get_n());
395 else assert(da->getNoOfFeatures()>=get_n());
396 assert(da->getNoOfClasses()>0);
397 assert(_index);
398 assert(_subfeatures==_model->get_d());
399 assert(_subfeatures>0);
400
401 typename DATAACCESSOR::PPattern p;
402 IDXTYPE s,i;
403 IDXTYPE count, correct;
404 DIMTYPE clstmp;
405 DIMTYPE _features=da->getNoOfFeatures();
406
407
408 count=0;
409 correct=0;
410 for(DIMTYPE c_test=0;c_test<_classes;c_test++)
411 {
412 da->setClass(c_test);
413 for(const auto &blk : da->blocks(TEST)) for(i=0,p=blk.data,s=blk.size;i<s;i++)
414 {
415 if(!classify(clstmp,&p[(std::size_t)i*_features])) return false;
416 if(clstmp==c_test) correct++;
417 count++;
418 }
419 }
420 assert(count>0);
421 result=(RETURNTYPE)correct/(RETURNTYPE)count;
422#ifdef DEBUG
423 {
424 std::ostringstream sos; sos << " result=" << result << std::endl;
425 syncout::print(std::cout,sos);
426 }
427#endif
428 return true;
429}
430
431
432} // namespace
433#endif // FSTCLASSIFIERNORMALBAYES_H ///:~
DIMTYPE _classes
number of classes; sizes the per-class arrays below
Definition classifier_normal_bayes.hpp:168
DIMTYPE _features
raw (full) feature count
Definition classifier_normal_bayes.hpp:169
std::unique_ptr< REALTYPE[]> _pxw
per-class likelihood p(x|class), cached by classify() (lazy allocation)
Definition classifier_normal_bayes.hpp:174
std::unique_ptr< REALTYPE[]> _det
per-class covariance determinant (lazy allocation)
Definition classifier_normal_bayes.hpp:172
std::unique_ptr< REALTYPE[]> _log_constant
ln of _constant, computed without forming _constant itself, for the log-domain fallback in classify()...
Definition classifier_normal_bayes.hpp:176
DIMTYPE _subfeatures
current subset size (== sub->get_d_raw() at the last train() call)
Definition classifier_normal_bayes.hpp:182
void enable_prelearn_mode(const PDataAccessor da)
Definition classifier_normal_bayes.hpp:223
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET >[]> _inverse
per-class inverse covariance matrix (lazy allocation)
Definition classifier_normal_bayes.hpp:171
Clonable_Impl< Classifier_Normal_Bayes, Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > parent_impl
implements clone(); sharing/stateless_clone throw in Classifier
Definition classifier_normal_bayes.hpp:118
std::unique_ptr< REALTYPE[]> _constant
per-class normalizing constant sqrt((2*pi)^d * _det[c]) (lazy allocation)
Definition classifier_normal_bayes.hpp:173
virtual bool test(RETURNTYPE &result, const PDataAccessor da) override
Definition classifier_normal_bayes.hpp:383
virtual bool train(const PDataAccessor da, const PSubset sub) override
learns from designated training part of data
Definition classifier_normal_bayes.hpp:260
virtual bool classify_scores(std::vector< RETURNTYPE > &scores, const PPattern &pattern) override
Definition classifier_normal_bayes.hpp:143
std::unique_ptr< REALTYPE[]> _ecoef
per-class Mahalanobis terms buffered for the fallback (lazy allocation)
Definition classifier_normal_bayes.hpp:177
DIMTYPE get_n() const
"full feature set" dimensionality the model was learned at (see Model_Normal::get_n())
Definition classifier_normal_bayes.hpp:154
std::shared_ptr< DATAACCESSOR > PDataAccessor
shared pointer to the data accessor supplying train/test blocks
Definition classifier_normal_bayes.hpp:119
void initialize(const PDataAccessor da)
(Re)allocates the per-class inverse-covariance, determinant, constant, posterior and log-domain-fallb...
Definition classifier_normal_bayes.hpp:235
std::unique_ptr< REALTYPE[]> _Pwx
per-class posterior P(class|x), cached by classify()/classify_scores() (lazy allocation)
Definition classifier_normal_bayes.hpp:175
bool get_prelearn_mode() const
true if pre-learn mode is active (see enable_prelearn_mode())
Definition classifier_normal_bayes.hpp:132
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _LUtemp
shared LU-decomposition scratch matrix, reused across classes in train()
Definition classifier_normal_bayes.hpp:170
std::unique_ptr< Model_Normal< DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > _model
the underlying normal (Gaussian) model supplying per-class mean/covariance
Definition classifier_normal_bayes.hpp:166
DIMTYPE get_d() const
dimensionality currently exposed by the model (see Model_Normal::get_d())
Definition classifier_normal_bayes.hpp:155
virtual bool classify(DIMTYPE &cls, const PPattern &pattern) override
Definition classifier_normal_bayes.hpp:312
virtual std::ostream & print(std::ostream &os) const override
writes a human-readable identification of the object; base default writes nothing
Definition classifier_normal_bayes.hpp:159
DATAACCESSOR::PPattern PPattern
one data sample as exposed by DATAACCESSOR (a raw pointer to its feature vector)
Definition classifier_normal_bayes.hpp:121
std::unique_ptr< DIMTYPE[]> _index
subset position -> raw feature index, filled by train() (first _subfeatures entries valid)
Definition classifier_normal_bayes.hpp:181
std::shared_ptr< SUBSET > const PSubset
shared pointer to the (fixed, non-reassignable) feature subset being trained/classified on
Definition classifier_normal_bayes.hpp:120
void disable_prelearn_mode()
reverts to the default: learn a new model in every train() call
Definition classifier_normal_bayes.hpp:131
bool _prelearn_mode
true = model learned once via enable_prelearn_mode(), narrow()ed per train(); false (default) = relea...
Definition classifier_normal_bayes.hpp:180
CRTP mixin implementing the Clonable protocol for a concrete class.
Definition clonable.hpp:184
Matrix representation and operations, allows operation in selected subspace.
Definition indexed_matrix.hpp:102
Implements normal (gaussian) model.
Definition model_normal.hpp:112
static void print(std::ostream &os, std::ostringstream &sos)
Writes sos's buffered content to os, serializing concurrent writers under FST_THREADED via a shared m...
Definition global.hpp:86
Defines interface for classifier implementations.
#define M_PI
value of pi; POSIX <cmath> extension, provided here as a fallback since strict C++17 does not guarant...
Definition classifier_normal_bayes.hpp:55
FST4 specific error passing class.
Global definitions.
Matrix representation and operations, allows operation in selected subspace.
Implements normal (gaussian) model.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112
@ TEST
the split's test part
Definition data_accessor.hpp:86
@ f1
classification, two-class data: F1 of the positive class, which is Metric_Spec::f1_positive (class in...
Definition wrapper_metrics.hpp:63
Copyright © 2000–present ÚTIA, Institute of Information Theory and Automation of the Czech Academy of Sciences · Contacts · This site sets no cookies and uses no analytics.