Unfit  3.1.1
Data fitting and optimization software
GeneticSwitch.hpp
1 // Unfit: Data fitting and optimization software
2 //
3 // Copyright (C) 2012- Dr Martin Buist & Dr Alberto Corrias
4 // Contacts: martin.buist _at_ nus.edu.sg; alberto _at_ nus.edu.sg
5 //
6 // See the 'Contributors' file for a list of those who have contributed
7 // to this work.
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 #ifndef UNFIT_EXAMPLES_GENETICSWITCH_HPP_
23 #define UNFIT_EXAMPLES_GENETICSWITCH_HPP_
24 
25 #include <cmath>
26 #include <vector>
27 #include "GenericCostFunction.hpp"
28 
29 namespace Unfit
30 {
31 namespace Examples
32 {
50 {
51  public:
64  GeneticSwitch(const std::vector<double> &z_a, double dt)
65  : z_a_data_ {z_a},
66  dt_ {dt}
67  {}
68 
82  std::vector<double> operator() (const std::vector<double> &param)
83  {
84  double z_a = 10.0; // Initial condition
85  double z_b = 10.0; // Initial condition
86  auto residuals = z_a_data_; // Residuals
87  residuals[0] -= z_a;
88  for (auto i = 1u; i < residuals.size(); ++i) {
89  const auto l_z_a = z_a + dt_ * (param[0] / (1.0 + pow(z_b, param[1])) -
90  z_a - param[2]);
91  z_b += dt_ * (param[0] / (1.0 + pow(z_a, param[1])) - z_b - param[3]);
92  z_a = l_z_a;
93  residuals[i] -= z_a;
94  }
95  return residuals;
96  }
97  private:
99  const std::vector<double> z_a_data_;
101  const double dt_;
102 };
103 
104 } // namespace Examples
105 } // namespace Unfit
106 
107 #endif
Fit the parameters in a model of a genetic switch.
Definition: GeneticSwitch.hpp:49
const double dt_
Definition: GeneticSwitch.hpp:101
Definition: Bounds.hpp:27
GeneticSwitch(const std::vector< double > &z_a, double dt)
Definition: GeneticSwitch.hpp:64
const std::vector< double > z_a_data_
Definition: GeneticSwitch.hpp:99
Definition: GenericCostFunction.hpp:36
std::vector< double > operator()(const std::vector< double > &param)
Definition: GeneticSwitch.hpp:82