Skip to content

Commit bd65a7a

Browse files
forgotten names
1 parent 21da839 commit bd65a7a

3 files changed

Lines changed: 52 additions & 45 deletions

File tree

include/geode/stochastic/sampling/mcmc/proposal/classical_proposals.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,30 @@
3030

3131
namespace geode
3232
{
33-
template < typename Type >
34-
std::unique_ptr< ProposalKernel< Type > > create_birth_death_kernel(
35-
const ObjectSetSampler< Type >& sampler, double birth_prob )
33+
template < typename ObjectType >
34+
std::unique_ptr< ProposalKernel< ObjectType > > create_birth_death_kernel(
35+
const ObjectSetSampler< ObjectType >& sampler, double birth_prob )
3636
{
37-
auto kernel = std::make_unique< ProposalKernel< Type > >();
38-
kernel->add_move( std::make_unique< BirthDeathMove< Type > >(
37+
auto kernel = std::make_unique< ProposalKernel< ObjectType > >();
38+
kernel->add_move( std::make_unique< BirthDeathMove< ObjectType > >(
3939
sampler, 1., birth_prob ) );
4040
return kernel;
4141
}
4242

43-
template < typename Type >
44-
std::unique_ptr< ProposalKernel< Type > > create_birth_death_change_kernel(
45-
const ObjectSetSampler< Type >& sampler,
46-
double birth_prob,
47-
double death_prob )
43+
template < typename ObjectType >
44+
std::unique_ptr< ProposalKernel< ObjectType > >
45+
create_birth_death_change_kernel(
46+
const ObjectSetSampler< ObjectType >& sampler,
47+
double birth_prob,
48+
double death_prob )
4849
{
4950
auto birth_death_prob = birth_prob + death_prob;
5051
OPENGEODE_EXCEPTION( birth_death_prob < 1.,
5152
"[Proposal Kernel] - changes should be allowed." );
52-
auto kernel = std::make_unique< ProposalKernel< Type > >();
53-
kernel->add_move( std::make_unique< BirthDeathMove< Type > >(
53+
auto kernel = std::make_unique< ProposalKernel< ObjectType > >();
54+
kernel->add_move( std::make_unique< BirthDeathMove< ObjectType > >(
5455
sampler, birth_death_prob, birth_prob / birth_death_prob ) );
55-
kernel->add_move( std::make_unique< ChangeMove< Type > >(
56+
kernel->add_move( std::make_unique< ChangeMove< ObjectType > >(
5657
sampler, 1. - birth_death_prob ) );
5758
return kernel;
5859
}

include/geode/stochastic/sampling/mcmc/proposal/moves.hpp

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace 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 =

include/geode/stochastic/sampling/mcmc/proposal/proposal_kernel.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
namespace geode
3030
{
3131

32-
template < typename Type >
32+
template < typename ObjectType >
3333
class ProposalKernel
3434
{
3535
public:
3636
virtual ~ProposalKernel() = default;
3737

38-
Proposal< Type > propose(
39-
const ObjectSet< Type >& current, RandomEngine& engine ) const
38+
Proposal< ObjectType > propose(
39+
const ObjectSet< ObjectType >& current, RandomEngine& engine ) const
4040
{
4141
OPENGEODE_EXCEPTION( !moves_.empty(),
4242
"[MCMC Proposal Kernel] - no move are defined in the Kernel." );
@@ -58,7 +58,7 @@ namespace geode
5858
return moves_.back()->propose_move( current, engine );
5959
}
6060

61-
void add_move( std::unique_ptr< Move< Type > > move )
61+
void add_move( std::unique_ptr< Move< ObjectType > > move )
6262
{
6363
moves_.push_back( std::move( move ) );
6464
compute_cumulative_sum_probs();
@@ -92,7 +92,7 @@ namespace geode
9292
}
9393

9494
private:
95-
std::vector< std::unique_ptr< Move< Type > > > moves_;
95+
std::vector< std::unique_ptr< Move< ObjectType > > > moves_;
9696
std::vector< double > cumulative_probs_;
9797

9898
geode::UniformClosed< double > uniform_closed_double_;

0 commit comments

Comments
 (0)