Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
criterion_multinom.hpp
Go to the documentation of this file.
1#ifndef FSTCRITERIONMULTINOM_H
2#define FSTCRITERIONMULTINOM_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 <cmath>
53#include "error.hpp"
54#include "global.hpp"
55#include "criterion.hpp"
56#include "model_multinom.hpp"
57
58/*============== Template parameter type naming conventions ==============
59--------- Numeric types: -------------------------------------------------
60DATATYPE - data sample values - usually real numbers (but may be integers
61 in text processing etc.)
62REALTYPE - must be real numbers - for representing intermediate results of
63 calculations like mean, covariance etc.
64IDXTYPE - index values for enumeration of data samples - (nonnegative) integers,
65 extent depends on numbers of samples in data
66DIMTYPE - index values for enumeration of features (dimensions), or classes (not
67 class sizes) - (nonnegative) integers, usually lower extent than IDXTYPE,
68 but be aware of expressions like _classes*_features*_features !
69 in linearized representations of feature matrices for all classes
70BINTYPE - feature selection marker type - represents ca. <10 different feature
71 states (selected, deselected, sel./desel. temporarily 1st nested loop, 2nd...)
72RETURNTYPE - criterion value: real value, but may be extended in future to support
73 multiple values
74--------- Class types: ---------------------------------------------------
75SUBSET - class of class type Subset
76CLASSIFIER - class implementing interface defined in abstract class Classifier
77EVALUATOR - class implementing interface defined in abstract class Sequential_Step
78DISTANCE - class implementing interface defined in abstract class Distance
79DATAACCESSOR - class implementing interface defined in abstract class Data_Accessor
80INTERVALCONTAINER - class of class type Data_Intervaller
81CONTAINER - STL container of class type Data_Interval
82========================================================================== */
83
84namespace FST {
85
95template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
96class Criterion_Multinomial : public Criterion_Filter<RETURNTYPE,SUBSET> { // abstract class
97public:
98 typedef std::shared_ptr<DATAACCESSOR> PDataAccessor;
99 typedef std::shared_ptr<SUBSET> PSubset;
100 Criterion_Multinomial();
101 virtual ~Criterion_Multinomial() {notify("Criterion_Multinomial destructor.");}
104 virtual bool initialize(PDataAccessor da);
105
106 virtual bool evaluate(RETURNTYPE &result, const PSubset sub) override =0;
107
112 virtual bool is_monotonic() const override {return true;}
113
114 DIMTYPE get_n() const {assert(_model); return _model->get_n();}
115 DIMTYPE get_d() const {assert(_model); return _model->get_d();}
116
117protected:
120protected:
121 std::unique_ptr<Model_Multinomial<DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR> > _model;
122};
123
124template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
125Criterion_Multinomial<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>::Criterion_Multinomial(const Criterion_Multinomial& cm)
126{
127 notify("Criterion_Multinomial copy-constructor.");
129}
130
131template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
132Criterion_Multinomial<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>::Criterion_Multinomial()
133{
134 notify("Criterion_Multinomial constructor.");
136}
137
138template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
140{
141 notify("Criterion_Multinomial::initialize().");
142 assert(_model);
143 _model->learn(da);
144 return true;
145}
146
147
148} // namespace
149#endif // FSTCRITERIONMULTINOM_H ///:~
Abstract class, defines interface for feature selection criterion implementations based on multinomia...
Definition criterion_multinom.hpp:96
virtual bool evaluate(RETURNTYPE &result, const PSubset sub) override=0
Scores the given feature subset; higher is better (FST4 searches maximize).
std::unique_ptr< Model_Multinomial< DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > _model
the learned per-class multinomial (term-probability) model
Definition criterion_multinom.hpp:121
virtual bool is_monotonic() const override
Definition criterion_multinom.hpp:112
std::shared_ptr< DATAACCESSOR > PDataAccessor
shared pointer to the data accessor the model is learned from
Definition criterion_multinom.hpp:98
virtual bool initialize(PDataAccessor da)
learns the multinomial model from da; subclasses must call this base before their own initialize() wo...
Definition criterion_multinom.hpp:139
DIMTYPE get_d() const
the currently active (narrowed) feature count
Definition criterion_multinom.hpp:115
std::shared_ptr< SUBSET > PSubset
shared pointer to the feature subset being evaluated
Definition criterion_multinom.hpp:99
DIMTYPE get_n() const
the full (raw, unnarrowed) feature count the model was learned for
Definition criterion_multinom.hpp:114
Multinomial ("bag of words") model: per-class term-count sums and the Laplace-smoothed term probabili...
Definition model_multinom.hpp:120
Defines interface for feature selection criterion classes.
FST4 specific error passing class.
Global definitions.
Implements multinomial 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
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.