Skip to content

Commit 2e18077

Browse files
remove GroupId to use a uuid.
1 parent 9c0a28c commit 2e18077

17 files changed

Lines changed: 104 additions & 99 deletions

include/geode/stochastic/configuration/configuration.hpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,29 @@
2525

2626
#include <vector>
2727

28+
#include <geode/basic/uuid.hpp>
2829
#include <geode/geometry/basic_objects/segment.hpp>
2930
#include <geode/geometry/bounding_box.hpp>
3031
#include <geode/geometry/point.hpp>
3132

3233
// #include <geode/stochastic/configuration/neighbors_object_ids.hpp>
3334
namespace geode
3435
{
35-
// can be a index_t used as a key in unordored map but maybe a "string is
36-
// beter?"
37-
struct GroupId
36+
struct GroupDescriptor
3837
{
39-
index_t value;
40-
bool operator==( GroupId const& other ) const noexcept
38+
geode::uuid unique_id;
39+
bool operator==( GroupDescriptor const& other ) const noexcept
4140
{
4241
{
43-
return value == other.value;
42+
return unique_id == other.unique_id;
4443
}
4544
}
4645
};
4746

4847
struct ObjectId
4948
{
5049
index_t object;
51-
GroupId group;
50+
uuid group;
5251
bool operator==( const ObjectId& other ) const noexcept
5352
{
5453
return object == other.object && group == other.group;
@@ -58,14 +57,14 @@ namespace geode
5857
// Hash support for unordered_map
5958
namespace std
6059
{
61-
template <>
62-
struct hash< geode::GroupId >
63-
{
64-
std::size_t operator()( geode::GroupId const& g ) const noexcept
65-
{
66-
return std::hash< geode::index_t >()( g.value );
67-
}
68-
};
60+
// template <>
61+
// struct hash< geode::uuid >
62+
//{
63+
// std::size_t operator()( geode::uuid const& g ) const noexcept
64+
// {
65+
// return std::hash< geode::index_t >()( g.unique_id );
66+
// }
67+
// };
6968

7069
// template <>
7170
// struct hash< geode::ObjectId >
@@ -83,16 +82,16 @@ namespace geode
8382
class Configuration
8483
{
8584
public:
86-
const std::vector< Object >& get_group( const GroupId& group_id ) const;
85+
const std::vector< Object >& get_group( const uuid& group_id ) const;
8786
const Object& get_object( const ObjectId& object_id ) const;
8887
std::vector< ObjectId > get_all_object() const;
8988

9089
index_t nb_groups() const;
91-
index_t nb_objects_in_group( const GroupId& group_id ) const;
90+
index_t nb_objects_in_group( const uuid& group_id ) const;
9291
index_t nb_objects() const;
9392

94-
void add_group( const GroupId& group_id );
95-
ObjectId add_object( Object&& object, const GroupId& group_id );
93+
void add_group( const uuid& group_id );
94+
ObjectId add_object( Object&& object, const uuid& group_id );
9695
void update_object( const ObjectId& object_id, Object&& object );
9796
void remove_object( const ObjectId& object_id );
9897

@@ -105,10 +104,10 @@ namespace geode
105104
const Object& object, double searching_distance ) const;
106105

107106
private:
108-
std::vector< Object >& get_group( const GroupId& group_id );
107+
std::vector< Object >& get_group( const uuid& group_id );
109108

110109
private:
111-
std::unordered_map< GroupId, std::vector< Object > > groups_;
110+
std::unordered_map< uuid, std::vector< Object > > groups_;
112111
// ObjectIndexRTree< 2 > tree_;
113112
};
114113
} // namespace geode

include/geode/stochastic/sampling/direct/configuration_sampler/configuration_sampler.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ namespace geode
3232
class ConfigurationSampler
3333
{
3434
public:
35-
ConfigurationSampler( GroupId group_id ) : group_id_{ group_id } {}
35+
ConfigurationSampler( uuid group_id ) : group_id_{ group_id } {}
3636
virtual ~ConfigurationSampler() = default;
3737

38-
virtual std::pair< Object, GroupId > sample(
38+
virtual std::pair< Object, uuid > sample(
3939
RandomEngine& engine ) const = 0;
4040

4141
std::optional< ObjectId > sample_id(
@@ -54,12 +54,12 @@ namespace geode
5454
return result;
5555
}
5656

57-
virtual std::pair< Object, GroupId > change(
57+
virtual std::pair< Object, uuid > change(
5858
const Object& object, RandomEngine& engine ) const = 0;
5959

6060
virtual double log_pdf( const Object& obj ) const = 0;
6161

6262
protected:
63-
GroupId group_id_;
63+
uuid group_id_;
6464
};
6565
} // namespace geode

include/geode/stochastic/sampling/direct/configuration_sampler/point_configuration_sampler.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace geode
3737
{
3838
public:
3939
UniformPointConfigurationSampler(
40-
const BoundingBox< dimension >& box, GroupId group_id )
40+
const BoundingBox< dimension >& box, uuid group_id )
4141
: ConfigurationSampler< Point< dimension > >{ group_id },
4242
box_( box )
4343
{
@@ -48,14 +48,14 @@ namespace geode
4848
}
4949
}
5050

51-
std::pair< Point< dimension >, GroupId > sample(
51+
std::pair< Point< dimension >, uuid > sample(
5252
RandomEngine& engine ) const override
5353
{
5454
return { PointUniformSampler::sample< dimension >( engine, box_ ),
5555
this->group_id_ };
5656
}
5757

58-
std::pair< Point< dimension >, GroupId > change(
58+
std::pair< Point< dimension >, uuid > change(
5959
const Point< dimension >& obj, RandomEngine& engine ) const override
6060
{
6161
double ratio = 0.1;

include/geode/stochastic/sampling/mcmc/metropolis_hasting_sampler.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace geode
6262

6363
Configuration< Object > initialise_configuration_with_sampling(
6464
RandomEngine& engine,
65-
const std::unordered_map< GroupId, index_t >& group_targets ) const
65+
const std::unordered_map< uuid, index_t >& group_targets ) const
6666
{
6767
Configuration< Object > config;
6868
for( const auto& [gid, target] : group_targets )
@@ -87,23 +87,24 @@ namespace geode
8787
}
8888
OPENGEODE_EXCEPTION( added,
8989
"[MH] Birth move need to be more probable for group: ",
90-
gid.value );
90+
gid.string() );
9191
}
9292
}
9393
return config;
9494
}
9595

96-
Configuration< Object > initialise_configuration_with_burnin(
97-
RandomEngine& engine, index_t number_of_steps ) const
98-
{
99-
Configuration< Object > configuration;
100-
for( const auto count : geode::Range{ number_of_steps } )
101-
{
102-
geode_unused( count );
103-
step( configuration, engine );
104-
}
105-
return configuration;
106-
}
96+
// Configuration< Object > initialise_configuration_with_burnin(
97+
// RandomEngine& engine, index_t number_of_steps ) const
98+
// {
99+
// Configuration< Object > configuration;
100+
//
101+
// for( const auto count : geode::Range{ number_of_steps } )
102+
// {
103+
// geode_unused( count );
104+
// step( configuration, engine );
105+
// }
106+
// return configuration;
107+
// }
107108

108109
StepResult< Object > step(
109110
Configuration< Object >& state, RandomEngine& engine ) const

include/geode/stochastic/sampling/mcmc/models/components/energy_term.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace geode
8787

8888
virtual double delta_log_add( const Configuration< Object >& state,
8989
const Object& object,
90-
const GroupId group_id ) const = 0;
90+
const uuid group_id ) const = 0;
9191

9292
virtual double delta_log_remove( const Configuration< Object >& state,
9393
ObjectId object_id ) const = 0;

include/geode/stochastic/sampling/mcmc/models/components/intensity_term.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace geode
3232
class IntensityTerm : public EnergyTerm< Object >
3333
{
3434
public:
35-
explicit IntensityTerm( double lambda, GroupId group_id )
35+
explicit IntensityTerm( double lambda, uuid group_id )
3636
: EnergyTerm< Object >( lambda ), group_id_{ group_id }
3737
{
3838
}
@@ -45,7 +45,7 @@ namespace geode
4545

4646
double delta_log_add( const Configuration< Object >& state,
4747
const Object& sample,
48-
const GroupId target_group_id ) const final
48+
const uuid target_group_id ) const final
4949
{
5050
return target_group_id == group_id_
5151
? this->neg_log_parameter_.scale( 1. )
@@ -79,6 +79,6 @@ namespace geode
7979
}
8080

8181
private:
82-
GroupId group_id_;
82+
uuid group_id_;
8383
};
8484
} // namespace geode

include/geode/stochastic/sampling/mcmc/models/components/pairwise_term.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace geode
4747

4848
double delta_log_add( const Configuration< Object >& state,
4949
const Object& new_object,
50-
GroupId group_id ) const final
50+
uuid group_id ) const final
5151
{
5252
geode_unused( group_id );
5353
const auto neighbors = state.neighbors( new_object, 1.1 );

include/geode/stochastic/sampling/mcmc/models/gibbs_energy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace geode
7878

7979
double delta_log_energy_add( const Configuration< Object > state,
8080
const Object& sample,
81-
GroupId group_id ) const
81+
uuid group_id ) const
8282
{
8383
double log_energy{ 0.0 };
8484
for( const auto& term : energy_terms_ )

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace geode
3939
};
4040

4141
Type type{ Type::Invalid };
42-
std::optional< std::pair< Object, GroupId > >
42+
std::optional< std::pair< Object, uuid > >
4343
new_object; // for birth/change
4444
std::optional< ObjectId > old_object_id; // for death/change
4545
double log_forward_prob{ 0. };

src/geode/stochastic/configuration/configuration.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace geode
99
{
1010
template < typename Object >
1111
const std::vector< Object >& Configuration< Object >::get_group(
12-
const GroupId& group_id ) const
12+
const uuid& group_id ) const
1313
{
1414
auto it = groups_.find( group_id );
1515
OPENGEODE_EXCEPTION( it != groups_.end(), "[Configuration] - group (",
16-
group_id.value, ") is not defined." );
16+
group_id.string(), ") is not defined." );
1717
return it->second;
1818
}
1919

@@ -50,7 +50,7 @@ namespace geode
5050

5151
template < typename Object >
5252
index_t Configuration< Object >::nb_objects_in_group(
53-
const GroupId& group_id ) const
53+
const uuid& group_id ) const
5454
{
5555
return get_group( group_id ).size();
5656
}
@@ -68,17 +68,17 @@ namespace geode
6868
}
6969

7070
template < typename Object >
71-
void Configuration< Object >::add_group( const GroupId& group_id )
71+
void Configuration< Object >::add_group( const uuid& group_id )
7272
{
7373
auto [it, inserted] =
7474
groups_.emplace( group_id, std::vector< Object >{} );
7575
OPENGEODE_EXCEPTION( inserted, "[Configuration]- group (",
76-
group_id.value, ") already exists." );
76+
group_id.string(), ") already exists." );
7777
}
7878

7979
template < typename Object >
8080
ObjectId Configuration< Object >::add_object(
81-
Object&& object, const GroupId& group_id )
81+
Object&& object, const uuid& group_id )
8282
{
8383
auto& group = get_group( group_id );
8484
ObjectId new_object_id{ static_cast< index_t >( group.size() ),
@@ -148,7 +148,7 @@ namespace geode
148148

149149
template < typename Object >
150150
std::vector< Object >& Configuration< Object >::get_group(
151-
const GroupId& group_id )
151+
const uuid& group_id )
152152
{
153153
return const_cast< std::vector< Object >& >(
154154
static_cast< const Configuration* >( this )->get_group(

0 commit comments

Comments
 (0)