MEPP2 Project
genericparametricmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <vector>
14 #include <Eigen/Core>
15 
16 template< typename TParam, typename TIn = double, typename TOut = double >
18 {
19 
20  //-----------------------------------------------------------------------------------
21 
22 public:
23  typedef TParam ParameterType;
24  typedef TIn InputType;
25  typedef TOut OutputType;
26 
27  //-----------------------------------------------------------------------------------
28 
29 public:
31  {
32  // default_params();
33  }
34 
36 
38 
39  //-----------------------------------------------------------------------------------
40 
41 public:
43 
44  const ParameterType &param() const { return m_param; } // read only
45  ParameterType &param() { return m_param; }
46 
47  //-----------------------------------------------------------------------------------
48 
49 public:
50  virtual void compute(const InputType &in, OutputType &out) const = 0;
51 
52  //-----------------------------------------------------------------------------------
53 
54 public:
55  OutputType compute(const InputType &in) const
56  {
57  OutputType out;
58  compute(in, out);
59 
60  return out;
61  }
62 
63  void compute(const std::vector< InputType > &in,
64  std::vector< OutputType > &out) const
65  {
66  out.clear();
67 
68  for(const InputType i : in)
69  out.push_back(compute(i));
70  }
71 
72  OutputType operator()(const InputType &in) const { return compute(in); }
73 
74  void operator()(const InputType &in, OutputType &out) const
75  {
76  out = compute(in);
77  }
78 
79  //-----------------------------------------------------------------------------------
80 
81 protected:
83  virtual void default_params() = 0;
84 
85  //-----------------------------------------------------------------------------------
86 
87 protected:
89 };
GenericParametricModel::GenericParametricModel
GenericParametricModel(const ParameterType &param)
Definition: genericparametricmodel.h:35
GenericParametricModel::compute
OutputType compute(const InputType &in) const
Definition: genericparametricmodel.h:55
GenericParametricModel::InputType
TIn InputType
Definition: genericparametricmodel.h:24
GenericParametricModel::ParameterType
TParam ParameterType
Definition: genericparametricmodel.h:23
GenericParametricModel::default_params
virtual void default_params()=0
sets default values to m_params
GenericParametricModel::param
const ParameterType & param() const
Definition: genericparametricmodel.h:44
GenericParametricModel::GenericParametricModel
GenericParametricModel()
Definition: genericparametricmodel.h:30
GenericParametricModel::compute
virtual void compute(const InputType &in, OutputType &out) const =0
GenericParametricModel::operator()
void operator()(const InputType &in, OutputType &out) const
Definition: genericparametricmodel.h:74
GenericParametricModel::~GenericParametricModel
virtual ~GenericParametricModel()
Definition: genericparametricmodel.h:37
GenericParametricModel::param
ParameterType & param()
Definition: genericparametricmodel.h:45
GenericParametricModel::m_param
ParameterType m_param
Definition: genericparametricmodel.h:88
GenericParametricModel::operator()
OutputType operator()(const InputType &in) const
Definition: genericparametricmodel.h:72
GenericParametricModel::compute
void compute(const std::vector< InputType > &in, std::vector< OutputType > &out) const
Definition: genericparametricmodel.h:63
GenericParametricModel
Definition: genericparametricmodel.h:18
GenericParametricModel::OutputType
TOut OutputType
Definition: genericparametricmodel.h:25
GenericParametricModel::setParameters
void setParameters(const ParameterType &param)
Definition: genericparametricmodel.h:42