2727
2828namespace geode
2929{
30- template < typename Type >
30+ template < typename ObjectType >
3131 struct Proposal
3232 {
3333 enum class Move
@@ -39,44 +39,48 @@ namespace geode
3939 };
4040
4141 Move type{ Move::Invalid };
42- std::optional< std::pair< Type, uuid > > new_object; // for birth/change
42+ std::optional< std::pair< ObjectType, uuid > >
43+ new_object; // for birth/change
4344 std::optional< ObjectId > old_object_id; // for death/change
4445 double log_forward_prob{ 0 . };
4546 double log_backward_prob{ 0 . };
4647 };
4748
4849 // Move does not hold the sampler... should it?
49- template < typename Type >
50+ template < typename ObjectType >
5051 class Move
5152 {
5253 public:
53- Move ( const ObjectSetSampler< Type >& sampler, double probability )
54+ Move (
55+ const ObjectSetSampler< ObjectType >& sampler, double probability )
5456 : sampler_( sampler ), p_move_{ probability }
5557 {
5658 }
5759 virtual ~Move () = default ;
5860
59- virtual Proposal< Type > propose_move (
60- const ObjectSet< Type >& current, RandomEngine& engine ) const = 0;
61+ virtual Proposal< ObjectType > propose_move (
62+ const ObjectSet< ObjectType >& current,
63+ RandomEngine& engine ) const = 0;
6164
6265 double probability () const
6366 {
6467 return p_move_;
6568 }
6669
6770 protected:
68- const ObjectSetSampler< Type >& sampler_;
71+ const ObjectSetSampler< ObjectType >& sampler_;
6972 double p_move_{ 1.0 };
7073 };
7174
72- template < typename Type >
73- class BirthDeathMove : public Move < Type >
75+ template < typename ObjectType >
76+ class BirthDeathMove : public Move < ObjectType >
7477 {
7578 public:
76- BirthDeathMove ( const ObjectSetSampler< Type >& sampler,
79+ BirthDeathMove ( const ObjectSetSampler< ObjectType >& sampler,
7780 double probability,
7881 double birth_ratio )
79- : Move< Type >( sampler, probability ), birth_ratio_( birth_ratio )
82+ : Move< ObjectType >( sampler, probability ),
83+ birth_ratio_ ( birth_ratio )
8084 {
8185 OPENGEODE_EXCEPTION ( birth_ratio_ > 0 . && birth_ratio_ < 1 .,
8286 " [BirthDeathMove]-the ratio of birth over mover should be in "
@@ -86,7 +90,8 @@ namespace geode
8690 log_p_death_ = std::log ( this ->p_move_ * ( 1.0 - birth_ratio ) );
8791 }
8892
89- Proposal< Type > propose_move ( const ObjectSet< Type >& current,
93+ Proposal< ObjectType > propose_move (
94+ const ObjectSet< ObjectType >& current,
9095 RandomEngine& engine ) const override
9196 {
9297 if ( engine.sample_bernoulli ( birth_ratio_ ) )
@@ -97,11 +102,11 @@ namespace geode
97102 }
98103
99104 private:
100- Proposal< Type > propose_birth_move (
101- const ObjectSet< Type >& current, RandomEngine& engine ) const
105+ Proposal< ObjectType > propose_birth_move (
106+ const ObjectSet< ObjectType >& current, RandomEngine& engine ) const
102107 {
103- Proposal< Type > birth;
104- birth.type = Proposal< Type >::Move::Birth;
108+ Proposal< ObjectType > birth;
109+ birth.type = Proposal< ObjectType >::Move::Birth;
105110 birth.new_object = this ->sampler_ .sample ( engine );
106111 if ( !birth.new_object .has_value () )
107112 {
@@ -116,17 +121,17 @@ namespace geode
116121 return birth;
117122 }
118123
119- Proposal< Type > propose_death_move (
120- const ObjectSet< Type >& current, RandomEngine& engine ) const
124+ Proposal< ObjectType > propose_death_move (
125+ const ObjectSet< ObjectType >& current, RandomEngine& engine ) const
121126 {
122- Proposal< Type > death;
127+ Proposal< ObjectType > death;
123128 death.old_object_id = this ->sampler_ .sample_id ( current, engine );
124129 if ( !death.old_object_id .has_value () )
125130 {
126131 return death;
127132 }
128133 const auto & cur_object_id = death.old_object_id .value ();
129- death.type = Proposal< Type >::Move::Death;
134+ death.type = Proposal< ObjectType >::Move::Death;
130135 death.log_forward_prob = log_p_death_
131136 - std::log ( current.nb_objects_in_subset (
132137 cur_object_id.subset ) );
@@ -142,26 +147,27 @@ namespace geode
142147 double log_p_death_{ 0 . };
143148 };
144149
145- template < typename Type >
146- class ChangeMove : public Move < Type >
150+ template < typename ObjectType >
151+ class ChangeMove : public Move < ObjectType >
147152 {
148153 public:
149154 ChangeMove (
150- const ObjectSetSampler< Type >& sampler, double probability )
151- : Move< Type >( sampler, probability )
155+ const ObjectSetSampler< ObjectType >& sampler, double probability )
156+ : Move< ObjectType >( sampler, probability )
152157 {
153158 }
154159
155- Proposal< Type > propose_move ( const ObjectSet< Type >& current,
160+ Proposal< ObjectType > propose_move (
161+ const ObjectSet< ObjectType >& current,
156162 RandomEngine& engine ) const override
157163 {
158- Proposal< Type > change;
164+ Proposal< ObjectType > change;
159165 change.old_object_id = this ->sampler_ .sample_id ( current, engine );
160166 if ( !change.old_object_id .has_value () )
161167 {
162168 return change;
163169 }
164- change.type = Proposal< Type >::Move::Change;
170+ change.type = Proposal< ObjectType >::Move::Change;
165171 const auto & object_to_change =
166172 current.get_object ( change.old_object_id .value () );
167173 change.new_object =
0 commit comments