AbstractTrainer.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief Abstract Trainer Interface.
6  *
7  *
8  *
9  * \author O. Krause, T.Glasmachers
10  * \date 2010-2011
11  *
12  *
13  * \par Copyright 1995-2017 Shark Development Team
14  *
15  * <BR><HR>
16  * This file is part of Shark.
17  * <http://shark-ml.org/>
18  *
19  * Shark is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU Lesser General Public License as published
21  * by the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * Shark is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
33 //===========================================================================
34 #ifndef SHARK_ALGORITHMS_TRAINERS_ABSTRACTTRAINER_H
35 #define SHARK_ALGORITHMS_TRAINERS_ABSTRACTTRAINER_H
36 
37 #include <shark/Core/INameable.h>
39 #include <shark/Data/Dataset.h>
41 
42 namespace shark {
43 
44 
45 ///
46 /// \brief Superclass of supervised learning algorithms
47 ///
48 /// \par
49 /// AbstractTrainer is the super class of all trainers,
50 /// i.e., procedures for training or learning model
51 /// parameters. It provides a single virtual function to
52 /// train the model.
53 ///
54 /// \par
55 /// Note: Most learning algorithms of this type operate on
56 /// a special model type, such as a linear model, a kernel
57 /// expansion, etc. Thus, these algorithms should provide
58 /// a specialized train method accepting only this model
59 /// type. The virtual train method should be overriden
60 /// with a method that checks the type of the model and
61 /// calls the specialized train method.
62 ///
63 template <class Model, class LabelTypeT = typename Model::OutputType>
65 {
66 public:
67  typedef Model ModelType;
68  typedef typename ModelType::InputType InputType;
69  typedef LabelTypeT LabelType;
71  /// Core of the Trainer interface
72  virtual void train(ModelType& model, DatasetType const& dataset) = 0;
73 };
74 
75 
76 ///
77 /// \brief Superclass of unsupervised learning algorithms
78 ///
79 /// \par
80 /// AbstractUnsupervisedTrainer is the superclass of all
81 /// unsupervised learning algorithms. It consists of a
82 /// single virtual function to train the model.
83 ///
84 /// \par
85 /// Note: Most learning algorithms of this type operate on
86 /// a special model type, such as a linear model, a kernel
87 /// expansion, or a nearest neighbor model. Thus, these
88 /// algorithms should provide a specialized train method
89 /// that accepts only this model type. The virtual train
90 /// method should be overriden with a method that checks
91 /// the type of the model and calls the specialized train
92 /// method.
93 ///
94 template <class Model>
96 {
97 public:
98  typedef Model ModelType;
99  typedef typename Model::InputType InputType;
100  /// Core of the Trainer interface
101  virtual void train(ModelType& model, const UnlabeledData<InputType>& inputset) = 0;
102 };
103 
104 
105 }
106 #endif