Hello!
J'essaie de mettre au point une classe de politique qui spécialise le comportement d'un simulateur de généalogies dans une population. Le but de cette politique est de simuler un type de donnée particulière (le nombre de généalogies restantes quand on remonte le temps).
Je définis donc une classe de politique (NRL_policy) héritée par une classe hôte de simulateur (SpatiallyExplicit). SpatiallyExplicit gère la simulation d'une population et la simulation de la généalogie passée d'un échantillon de cette population: cette classe manipule des abstractions de généalogies (opération de création d'un nouveau node, de branchement d'un node à un autre), et la classe de politque NRL_policy définit les implémentations à utiliser pour calculer le NRL (number of remaining lineages) en remontant le temps: créer un nouveau node incrémente le NRL, brancher une lignée à une autre décrémente le NRL. De SpatiallyExplicit<NRL_policy>, je dérive une classe NRL_computer qui utilise une donnée membre de la classe de politique (le vecteur qui accumule le nombre de lignées perdues en remontant le temps) et une méthode de la classe hôte (celle qui simule la généalogie passée d'un échantillon donné). Cette dernière méthode a un comportement qui varie selon un type de Merger qui vise à réguler comment les collisions entre généalogies se déroulent (différent Mergers représentent différentes approximations mathématiques). Mon problème c'est justement l'appel de cette dernière fonction qui ne semble pas bien se passer:
Je compile mon script avec g++ NRL_spatial.cpp -o NRL_spatial -I/usr/include/gdal -lgdal -I/home/me/dev -std=c++17 -I/home/me/dev -lboost_program_options -Wall
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 NRL_spatial.cpp: In member function void NRL_computer<Space, Time, DemographicPolicy>::simulate(const sample_type&, unsigned int, unsigned int, const merger_ID_type&, G&): NRL_spatial.cpp:127:66: error: expected primary-expression before > token this->make_forest_and_coalesce_along_spatial_history<Merger>(sample, gen); ^ NRL_spatial.cpp: In instantiation of void NRL_computer<Space, Time, DemographicPolicy>::simulate(const sample_type&, unsigned int, unsigned int, const merger_ID_type&, G&) [with Merger = quetzal::coalescence::BinaryMerger; G = std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>; Space = quetzal::geography::GeographicCoordinates; Time = int; DemographicPolicy = quetzal::demography::strategy::mass_based; NRL_computer<Space, Time, DemographicPolicy>::sample_type = std::map<quetzal::geography::GeographicCoordinates, unsigned int>; NRL_computer<Space, Time, DemographicPolicy>::merger_ID_type = std::__cxx11::basic_string<char>]: NRL_spatial.cpp:289:59: required from here NRL_spatial.cpp:127:74: warning: left operand of comma operator has no effect [-Wunused-value] this->make_forest_and_coalesce_along_spatial_history<Merger>(sample, gen); ~~~~~~~^~~~~~ NRL_spatial.cpp: In instantiation of void NRL_computer<Space, Time, DemographicPolicy>::simulate(const sample_type&, unsigned int, unsigned int, const merger_ID_type&, G&) [with Merger = quetzal::coalescence::SimultaneousMultipleMerger<quetzal::coalescence::occupancy_spectrum::on_the_fly>; G = std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>; Space = quetzal::geography::GeographicCoordinates; Time = int; DemographicPolicy = quetzal::demography::strategy::mass_based; NRL_computer<Space, Time, DemographicPolicy>::sample_type = std::map<quetzal::geography::GeographicCoordinates, unsigned int>; NRL_computer<Space, Time, DemographicPolicy>::merger_ID_type = std::__cxx11::basic_string<char>]: NRL_spatial.cpp:290:66: required from here NRL_spatial.cpp:127:74: warning: left operand of comma operator has no effect [-Wunused-value] NRL_spatial.cpp: In instantiation of void NRL_computer<Space, Time, DemographicPolicy>::simulate(const sample_type&, unsigned int, unsigned int, const merger_ID_type&, G&) [with Merger = HybridMerger; G = std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>; Space = quetzal::geography::GeographicCoordinates; Time = int; DemographicPolicy = quetzal::demography::strategy::mass_based; NRL_computer<Space, Time, DemographicPolicy>::sample_type = std::map<quetzal::geography::GeographicCoordinates, unsigned int>; NRL_computer<Space, Time, DemographicPolicy>::merger_ID_type = std::__cxx11::basic_string<char>]: NRL_spatial.cpp:291:61: required from he re NRL_spatial.cpp:127:74: warning: left operand of comma operator has no effect [-Wunused-value]
Le code est ici :
Sauriez-vous m'indiquer ce qui se passe mal ? J'avoue avoir vraiment essayé pas mal de trucs, et je vais de problèmes en problèmes ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 * * @brief Implementation of the CoalescencePolicy Interface to compute the number of * remaining lineages. * */ template<typename Space> class NRL_policy{ public: using coord_type = Space; // number of sampled gene copies by location using sample_type = std::map<coord_type, unsigned int>; protected: // Instantaneous loss rate of lineages by generation std::vector<int> _loss; private: // Trees are just counting generations using tree_type = int; // Spatial forest using forest_type = quetzal::coalescence::Forest<coord_type, tree_type>; public: // initalization event when a parent node is created. Loss at time t is incremented, // present time is returned to be used in the branching event. auto init(){ return [this](coord_type, int t){ return [&, t](){ this->_loss.at(t) += 1; return t; }; }; } // event to trigger when a coalescence event happens and that a child is connected // to its parent. Loss at time at which the parent was created is decremented. auto branch(){ return [this](int parent, int child){ this->_loss.at(parent) -= 1; return parent; }; } // Transform a spatial sample density into an appropriate forest forest_type make_forest(sample_type const& sample_counts) const { forest_type forest; for(auto const& it: sample_counts){ // nodes are initialized with generation = 0 forest.insert(it.first, std::vector<tree_type>(it.second, 0)); } return forest; } }; /** * @brief Coalescence simulator in a spatially explicit landscape. * * @tparam Space deme identifiers (like the populations geographic coordinates) * @tparam Time time identifier (like an integer representing the year) * @tparam Strategy a politic for the demographic expansion (e.g. individual_based) * */ template<typename Space, typename Time, typename Strategy, typename CoalescencePolicy> class SpatiallyExplicit : public CoalescencePolicy { public: using coord_type = Space; using time_type = Time; using strategy_type = Strategy; using N_value_type = typename strategy_type::value_type; template<typename Tree> using forest_type = quetzal::coalescence::Forest<coord_type, Tree>; private: ... public: ... template<typename Merger, typename Generator> auto make_forest_and_coalesce_along_spatial_history(std::map<coord_type, unsigned int> sample, Generator &gen) { test_sample_consistency(sample); auto forest = this->make_forest(sample); return coalesce_along_spatial_history<Merger>(forest, this->branch(), gen, this->init() ); } ... }; template<typename Space, typename Time, typename DemographicPolicy> class NRL_computer : public quetzal::simulators::SpatiallyExplicit<Space, Time, DemographicPolicy, NRL_policy<Space>> { // the key type used to remember which type of merger was used using merger_ID_type = std::string; // a NRL function of time using trajectory_type = std::vector<unsigned int>; // several NRL trajectoris using trajectories_type = std::vector<trajectory_type>; // dictionary to store NRL functions by merger type std::map<merger_ID_type, trajectories_type> _trajectories; public: using coord_type = Space; using sample_type = typename NRL_policy<coord_type>::sample_type; using quetzal::simulators::SpatiallyExplicit<Space, Time, DemographicPolicy, NRL_policy<Space>>::SpatiallyExplicit; /*! * Simulate trajectories of Number of Remaining Lineages * @param sample a map of sampling density (number of gene copies by location) * @param nb_rep number of NRL trajectories repetitions * @param nb_generations number of generations to simulate * @param ID identifiant for the merger used * @param gen random number generator * @tparam G Random Number Generator */ template<typename Merger, typename G> void simulate(sample_type const& sample, unsigned int nb_rep, unsigned int nb_generations, merger_ID_type const& ID, G& gen) { int k = std::accumulate(sample.cbegin(), sample.cend(), 0, [] (int v, auto const& p){ return v + p.second; }); _trajectories[ID] = std::vector<std::vector<unsigned int>>(nb_rep,std::vector<unsigned int>(nb_generations)); for(unsigned int i_rep = 0; i_rep < nb_rep ; ++i_rep) { this->_loss = std::vector<int>(nb_generations, 0); // update the loss vector this->make_forest_and_coalesce_along_spatial_history<Merger>(sample, gen); // <----- -------- Problem here // Compute NRL by sustracting the instantaneous linages loss to k unsigned int NRL = k; size_t t = 0; for(auto const& it : this->_loss){ NRL = NRL + it; _trajectories.at(ID).at(i_rep).at(t) = NRL; ++t; } } } };
Merci d'avance !
Seab
Partager