molpopgen / fwdpp

fwdpp is a C++ template library for implementing efficient forward-time population genetic simulations
http://fwdpp.readthedocs.io
GNU General Public License v3.0
27 stars 11 forks source link

Update additive_diploid and multiplicative_diploid to facilitate calculation of trait values vs. fitness #49

Closed molpopgen closed 7 years ago

molpopgen commented 7 years ago

fwdpp was initially designed with "standard pop gen" models in mind, meaning a direct mapping from genotype to fitness. However, the library is seeing more and more use in simulating quantitative traits, which brings up an issue. Currently, additive_diploid returns std::max(0., 1 + site_dependent_fitness()(...)), where ... is a bunch of details. This return value inherently assumes that the function is being used to calculate fitness, which is bounded to be a non-negative double. However, it would be easy to modify the function to allow any value to be returned when a trait is being simulated. Further, this change can be made silently, meaning that the current interpretation of additive_diploid remains unchanged. In other words, this does not break the API, but rather enhances its flexibility.

Proposed change:

  1. Add a std::function<double(double)> to additive_diploid and multiplicative_diploid. This function takes the return value of site_dependent_fitness and "does the right thing".
  2. Add a constructor taking a std::function<double(double)> whose default is the current behavior. For example:
//new constructor
additive_diploid(std::function<double(double)> f = [](const double v)->double { return std::max(0.,1.+v);}) :
make_return_value{std::move(f)}
{
}

The default in the above matches the current behavior (fitness).

The analogous closure for a trait value calculation would be:

[](const double d)->double{return d;}

The call operators would have to be modified to call this function.

molpopgen commented 7 years ago

Addressed in 0.5.6