Xmipp  v3.23.11-Nereus
base_algorithm.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Alberto Pascual Montano (pascual@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 //-----------------------------------------------------------------------------
27 // ClassificationAlgorithm.h
28 // Base class for all algorithms within Xmipp Library
29 //-----------------------------------------------------------------------------
30 
31 
32 #ifndef BASEALGORITHM_H
33 #define BASEALGORITHM_H
34 
35 #include <iostream>
36 
37 #include "training_set.h"
38 #include "data_set.h"
39 
40 #include <core/xmipp_funcs.h>
41 
45 //-----------------------------------------------------------------------------
53 template<class DSClass>
55 {
56 public:
57 
58  typedef DSClass DS;
59  typedef typename DS::TS TS;
60 
65  ClassificationAlgorithm(const std::string& _ID = ""): ID(_ID)
66  {};
67 
73  {};
74 
81  virtual void train(DS& _ds, const TS& _examples) const
82  {};
83 
90  virtual void train(DS& _ds, TS& _examples) const
91  {};
92 
102  virtual double test(const DS& _ds, const TS& _examples) const = 0;
103 
106  virtual void printSelf(std::ostream& _os) const
107  {
108  _os << "xmippBaseAlgo" << std::endl; // to identify it as an algorith
109  _os << ID << std::endl;
110  };
111 
114  virtual const std::string& setID() const
115  {
116  return ID;
117  };
118 
121  virtual std::string& setID()
122  {
123  return ID;
124  };
125 
126 
129  void setListener(BaseListener* _listener)
130  {
131  listener = _listener;
132  };
133 
134 protected:
135  std::string ID;// algorithm ID, an unique name to recognize the algorithm
136  BaseListener* listener; // Listener class
137 
138 };
139 
140 //-----------------------------------------------------------------------------
141 template<class DS>
142 std::ostream& operator << (std::ostream& _os, const ClassificationAlgorithm<DS>& _algo)
143 {
144  _algo.printSelf(_os);
145  return _os;
146 }
148 #endif//XMIPPBASEALGO_H
virtual double test(const DS &_ds, const TS &_examples) const =0
void setListener(BaseListener *_listener)
virtual const std::string & setID() const
virtual ~ClassificationAlgorithm()
virtual void train(DS &_ds, TS &_examples) const
ClassificationAlgorithm(const std::string &_ID="")
virtual void train(DS &_ds, const TS &_examples) const
virtual void printSelf(std::ostream &_os) const
virtual std::string & setID()