... | ... |
@@ -5,42 +5,48 @@ |
5 | 5 |
// nn by default is equal 1 |
6 | 6 |
// n array con las poblaciones de cada genotipo y su ncols(diferentes tipos de genotipos en la población) |
7 | 7 |
// target is the target size, to which number the population would get reduced to. |
8 |
-void reduceTotalPopulation(InterventionsInfo& iif, double target, double totPopSize){ |
|
8 |
+void reduceTotalPopulation(InterventionsInfo& iif, double target){ |
|
9 | 9 |
|
10 |
- // first we take all the population from the structure, and we create a vector with its populations |
|
11 |
- std::vector<double> populations; |
|
12 |
- Rcpp::NumericMatrix rcpp_mhgeo_distribution; |
|
13 |
- Rcpp::NumericMatrix rcpp_populations_matrix; |
|
14 |
- Rcpp::NumericVector rcpp_populations; |
|
15 |
- Rcpp::NumericVector rcpp_target; |
|
16 |
- //auxiliar variable to check the structure (and the atribute mapGenoToPop) is well populated |
|
17 |
- double totalPop = 0.0; |
|
18 |
- for(auto map : iif.mapGenoToPop){ |
|
19 |
- totalPop += map.second; |
|
20 |
- populations.push_back(map.second); |
|
21 |
- } |
|
22 |
- // we convert the vector to something R can understand |
|
23 |
- rcpp_populations = Rcpp::wrap(populations); |
|
24 |
- rcpp_populations.attr("dim") = Dimension(1, populations.size()); |
|
10 |
+ // first we take all the population from the structure, and we create a vector with its populations |
|
11 |
+ std::vector<double> populations; |
|
12 |
+ Rcpp::NumericMatrix rcpp_mhgeo_distribution; |
|
13 |
+ Rcpp::NumericMatrix rcpp_populations_matrix; |
|
14 |
+ Rcpp::NumericVector rcpp_populations; |
|
15 |
+ Rcpp::NumericVector rcpp_target; |
|
16 |
+ //auxiliar variable to check the structure (and the atribute mapGenoToPop) is well populated |
|
17 |
+ double totalPop = 0.0; |
|
18 |
+ for(auto map : iif.mapGenoToPop){ |
|
19 |
+ totalPop += map.second; |
|
20 |
+ populations.push_back(map.second); |
|
21 |
+ } |
|
25 | 22 |
|
26 |
- rcpp_populations_matrix = Rcpp::wrap(rcpp_populations); |
|
27 |
- rcpp_target = Rcpp::wrap(target); |
|
23 |
+ // // this is never triggered as caught before calling this |
|
24 |
+ // if (totalPop >= target) { |
|
25 |
+ // throw std::runtime_error("Intervention: target population size must be strictly less than existing one"); |
|
26 |
+ // } |
|
27 |
+ |
|
28 |
+ // we convert the vector to something R can understand |
|
29 |
+ rcpp_populations = Rcpp::wrap(populations); |
|
30 |
+ rcpp_populations.attr("dim") = Dimension(1, populations.size()); |
|
31 |
+ |
|
32 |
+ rcpp_populations_matrix = Rcpp::wrap(rcpp_populations); |
|
33 |
+ rcpp_target = Rcpp::wrap(target); |
|
28 | 34 |
|
29 |
- // then, we specify the total genotypes of the populations and we obtain a distribution |
|
30 |
- rcpp_mhgeo_distribution = my_rmvhyper(1, rcpp_populations_matrix, rcpp_target); |
|
35 |
+ // then, we specify the total genotypes of the populations and we obtain a distribution |
|
36 |
+ rcpp_mhgeo_distribution = my_rmvhyper(1, rcpp_populations_matrix, rcpp_target); |
|
31 | 37 |
|
32 |
- populations = Rcpp::as<std::vector<double>>(rcpp_mhgeo_distribution); |
|
38 |
+ populations = Rcpp::as<std::vector<double>>(rcpp_mhgeo_distribution); |
|
33 | 39 |
|
34 |
- //quick check before creating the matrix CANT BE DONE HERE (totPopSize is not updated until crude is filled) |
|
35 |
- //if(totPopSize != totalPop){ |
|
36 |
- // throw std::runtime_error("TotalPop != totPopSize, exiting..."); |
|
37 |
- //} |
|
40 |
+ //quick check before creating the matrix CANT BE DONE HERE (totPopSize is not updated until crude is filled) |
|
41 |
+ //if(totPopSize != totalPop){ |
|
42 |
+ // throw std::runtime_error("TotalPop != totPopSize, exiting..."); |
|
43 |
+ //} |
|
38 | 44 |
|
39 |
- int i=0; |
|
40 |
- for(auto &map : iif.mapGenoToPop){ |
|
41 |
- //check if it goes out of bounds |
|
42 |
- map.second = populations[i]; |
|
43 |
- i++; |
|
44 |
- } |
|
45 |
+ int i=0; |
|
46 |
+ for(auto &map : iif.mapGenoToPop){ |
|
47 |
+ //check if it goes out of bounds |
|
48 |
+ map.second = populations[i]; |
|
49 |
+ i++; |
|
50 |
+ } |
|
45 | 51 |
|
46 | 52 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,46 @@ |
1 |
+#include "intervention.h" |
|
2 |
+ |
|
3 |
+ |
|
4 |
+// This function is needed if what we are trying to descrease is the whole population, and not just the population of 1 genotype |
|
5 |
+// nn by default is equal 1 |
|
6 |
+// n array con las poblaciones de cada genotipo y su ncols(diferentes tipos de genotipos en la población) |
|
7 |
+// target is the target size, to which number the population would get reduced to. |
|
8 |
+void reduceTotalPopulation(InterventionsInfo& iif, double target, double totPopSize){ |
|
9 |
+ |
|
10 |
+ // first we take all the population from the structure, and we create a vector with its populations |
|
11 |
+ std::vector<double> populations; |
|
12 |
+ Rcpp::NumericMatrix rcpp_mhgeo_distribution; |
|
13 |
+ Rcpp::NumericMatrix rcpp_populations_matrix; |
|
14 |
+ Rcpp::NumericVector rcpp_populations; |
|
15 |
+ Rcpp::NumericVector rcpp_target; |
|
16 |
+ //auxiliar variable to check the structure (and the atribute mapGenoToPop) is well populated |
|
17 |
+ double totalPop = 0.0; |
|
18 |
+ for(auto map : iif.mapGenoToPop){ |
|
19 |
+ totalPop += map.second; |
|
20 |
+ populations.push_back(map.second); |
|
21 |
+ } |
|
22 |
+ // we convert the vector to something R can understand |
|
23 |
+ rcpp_populations = Rcpp::wrap(populations); |
|
24 |
+ rcpp_populations.attr("dim") = Dimension(1, populations.size()); |
|
25 |
+ |
|
26 |
+ rcpp_populations_matrix = Rcpp::wrap(rcpp_populations); |
|
27 |
+ rcpp_target = Rcpp::wrap(target); |
|
28 |
+ |
|
29 |
+ // then, we specify the total genotypes of the populations and we obtain a distribution |
|
30 |
+ rcpp_mhgeo_distribution = my_rmvhyper(1, rcpp_populations_matrix, rcpp_target); |
|
31 |
+ |
|
32 |
+ populations = Rcpp::as<std::vector<double>>(rcpp_mhgeo_distribution); |
|
33 |
+ |
|
34 |
+ //quick check before creating the matrix CANT BE DONE HERE (totPopSize is not updated until crude is filled) |
|
35 |
+ //if(totPopSize != totalPop){ |
|
36 |
+ // throw std::runtime_error("TotalPop != totPopSize, exiting..."); |
|
37 |
+ //} |
|
38 |
+ |
|
39 |
+ int i=0; |
|
40 |
+ for(auto &map : iif.mapGenoToPop){ |
|
41 |
+ //check if it goes out of bounds |
|
42 |
+ map.second = populations[i]; |
|
43 |
+ i++; |
|
44 |
+ } |
|
45 |
+ |
|
46 |
+} |