IParameterizable.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief IParameterizable interface
6  *
7  *
8  *
9  * \author 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 
35 #ifndef SHARK_CORE_IPARAMETERIZABLE_H
36 #define SHARK_CORE_IPARAMETERIZABLE_H
37 
38 
39 #include <shark/LinAlg/Base.h>
40 
41 
42 namespace shark {
43 
44 /// \brief Top level interface for everything that holds parameters.
45 ///
46 /// This interface is inherited by AbstractModel for unified
47 /// access to the parameters of models, but also by objective
48 /// functions and algorithms with hyper-parameters.
49 ///
50 /// the type of parameter vector can be chosen, e.g. to change precision
51 /// or port parameters to GPU
52 template<class VectorType= RealVector>
54 public:
56  virtual ~IParameterizable () { }
57 
58  /// Return the parameter vector.
59  virtual ParameterVectorType parameterVector() const
60  {
61  return ParameterVectorType();
62  }
63 
64  /// Set the parameter vector.
65  virtual void setParameterVector(ParameterVectorType const& newParameters)
66  {
67  SHARK_ASSERT(newParameters.size() == 0);
68  }
69 
70  /// Return the number of parameters.
71  virtual std::size_t numberOfParameters() const {
72  return parameterVector().size();
73  }
74 };
75 
76 
77 }
78 #endif