forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
FitnessFunctionImplementation.hpp
1 //
2 // FitnessFunctionImplementation.hpp
3 //
4 // Created by Darren Kessner with John Novembre
5 //
6 // Copyright (c) 2013 Regents of the University of California
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // * Neither UCLA nor the names of its contributors may be used to endorse or
20 // promote products derived from this software without specific prior
21 // written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34 
35 
36 #ifndef _FITNESSFUNCTIONIMPLEMENTATION_HPP_
37 #define _FITNESSFUNCTIONIMPLEMENTATION_HPP_
38 
39 
40 #include "QuantitativeTrait.hpp"
41 #include "PopulationData.hpp"
42 #include "shared_ptr.hpp"
43 #include <stdexcept>
44 
45 
51 
52 
53 //
54 // FitnessFunction_Trivial
55 //
56 
66 
67 class FitnessFunction_Trivial : public QuantitativeTrait
68 {
69  public:
70 
71  FitnessFunction_Trivial(const std::string& id) : QuantitativeTrait(id) {}
72 
73  virtual void calculate_trait_values(const PopulationData& population_data) const
74  {
75  (*population_data.trait_values)[object_id()] =
76  DataVectorPtr(new DataVector(population_data.population_size, 1));
77  }
78 
79  // Configurable interface
80 
81  virtual std::string class_name() const {return "FitnessFunction_Trivial";}
82  virtual Parameters parameters() const {return Parameters();}
83  virtual void configure(const Parameters& parameters, const Registry& registry) {}
84 };
85 
86 
87 //
88 // FitnessFunction_Optimum
89 //
90 
117 
118 class FitnessFunction_Optimum : public QuantitativeTrait
119 {
120  public:
121 
122  FitnessFunction_Optimum(const std::string& id, const std::string& quantitative_trait_id = "",
123  double optimum = 0, double radius = 0, double power = 0);
124 
125  virtual void calculate_trait_values(const PopulationData& population_data) const;
126 
127  // Configurable interface
128 
129  virtual std::string class_name() const {return "FitnessFunction_Optimum";}
130  virtual Parameters parameters() const;
131  virtual void configure(const Parameters& parameters, const Registry& registry);
132 
133  private:
134 
135  std::string qtid_;
136  double optimum_;
137  double radius_;
138  double power_;
139  double gaussian_width_;
140 };
141 
142 
143 //
144 // FitnessFunction_TruncationSelection
145 //
146 
164 
165 class FitnessFunction_TruncationSelection : public QuantitativeTrait
166 {
167  public:
168 
169  FitnessFunction_TruncationSelection(const std::string& id);
170 
171  void calculate_trait_values_with_threshold(const PopulationData& population_data, double threshold) const;
172 
173  virtual void calculate_trait_values(const PopulationDataPtrs& population_datas) const;
174 
175  // Configurable interface
176 
177  virtual std::string class_name() const {return "FitnessFunction_TruncationSelection";}
178  virtual Parameters parameters() const;
179  virtual void configure(const Parameters& parameters, const Registry& registry);
180 
181  private:
182 
183  std::string qtid_;
184  double proportion_selected_;
185  bool lower_tail_;
186  bool single_threshold_;
187  size_t single_threshold_population_index_;
188  bool ignore_zero_;
189 
190  double calculate_threshold(const PopulationData& population_data) const;
191 };
192 
193 
194 #endif // _FITNESSFUNCTIONIMPLEMENTATION_HPP_
195