Skip to content

Commit deed2f5

Browse files
tidy
1 parent 0f67b68 commit deed2f5

17 files changed

Lines changed: 607 additions & 404 deletions

File tree

include/geode/stochastic/applications/poisson_process.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace geode
1313
ObjectSamplerConfig< ObjectType > sampler;
1414

1515
std::string density_name;
16-
double lambda;
16+
double lambda{ 0. };
1717
std::optional< double > expected_nb_objects;
1818

1919
double birth_ratio{ 1.0 };

include/geode/stochastic/applications/strauss_process.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace geode
1313

1414
std::vector< std::string > set_names;
1515

16-
double gamma;
17-
double distance;
16+
double gamma{ 1. };
17+
double distance{ 0. };
1818

1919
bool include_intra_set{ true };
2020
bool include_inter_set{ false };

include/geode/stochastic/inference/target_statistics.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626

2727
namespace geode
2828
{
29+
constexpr double STATISTIC_TOLERANCE_VALUE{ 0.1 };
30+
2931
struct TargetStatisticConfig
3032
{
3133
std::string term_name;
3234
double value;
33-
double tolerance;
35+
double tolerance{ STATISTIC_TOLERANCE_VALUE };
3436
};
3537

3638
template < typename ObjectType >

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ namespace geode
3434
template < typename Type >
3535
class ObjectSetSampler
3636
{
37+
OPENGEODE_DISABLE_COPY_AND_MOVE( ObjectSetSampler );
38+
3739
public:
40+
ObjectSetSampler() = default;
3841
virtual ~ObjectSetSampler() = default;
3942

4043
[[nodiscard]] virtual Type sample( RandomEngine& engine ) const = 0;
@@ -53,9 +56,13 @@ namespace geode
5356
}
5457

5558
protected:
56-
virtual bool is_valid_object( const Type& obj ) const = 0;
59+
[[nodiscard]] virtual bool is_valid_object( const Type& obj ) const = 0;
60+
void set_log_pdf( double value )
61+
{
62+
log_pdf_ = value;
63+
}
5764

58-
protected:
65+
private:
5966
double log_pdf_{ LOG_PROB_INVALID };
6067
};
6168

include/geode/stochastic/sampling/direct/object_set_sampler/point_set_sampler.hpp

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -23,106 +23,38 @@
2323

2424
#pragma once
2525

26-
#include <geode/geometry/basic_objects/sphere.hpp>
27-
#include <geode/geometry/point.hpp>
28-
2926
#include <geode/stochastic/sampling/direct/object_set_sampler/object_set_sampler.hpp>
30-
#include <geode/stochastic/sampling/direct/point_uniform_sampler.hpp>
31-
#include <geode/stochastic/spatial/spatial_domain.hpp>
3227

3328
namespace geode
3429
{
30+
template < index_t dimension >
31+
struct ObjectSamplerConfig< Point< dimension > >
32+
{
33+
// use to define the step for change move (move_ratio*domain volume)
34+
double move_ratio{ 0.1 };
35+
};
36+
3537
template < index_t dimension >
3638
class UniformPointSetSampler : public ObjectSetSampler< Point< dimension > >
3739
{
3840
public:
3941
UniformPointSetSampler( const SpatialDomain< dimension >& domain,
40-
const ObjectSamplerConfig< Point< dimension > >& config )
41-
: ObjectSetSampler< Point< dimension > >{}, domain_( domain )
42-
{
43-
auto volume = domain_.extended_n_volume();
44-
OpenGeodeStochasticStochasticException::check_exception(
45-
volume != 0., nullptr, OpenGeodeException::TYPE::data,
46-
"[UniformPointSetSampler] Undefined Extended Bounding "
47-
"Box (volume ==0)." );
48-
this->log_pdf_ = -std::log( volume );
49-
step_move_ = define_step_for_move( config.move_ratio );
50-
OpenGeodeStochasticStochasticException::check_exception(
51-
step_move_ > 0., nullptr, OpenGeodeException::TYPE::data,
52-
"[UniformPointSetSampler] Undefined step length for move "
53-
"(value == ",
54-
step_move_, ")." );
55-
}
56-
57-
Point< dimension > sample( RandomEngine& engine ) const override
58-
{
59-
return PointUniformSampler::sample< dimension >(
60-
engine, domain_.extended_box() );
61-
}
42+
const ObjectSamplerConfig< Point< dimension > >& config );
6243

63-
Point< dimension > change(
64-
const Point< dimension >& obj, RandomEngine& engine ) const override
65-
{
66-
geode::Sphere< dimension > ball{ obj, step_move_ };
44+
[[nodiscard]] Point< dimension > sample(
45+
RandomEngine& engine ) const override;
6746

68-
auto new_point =
69-
PointUniformSampler::sample< dimension >( engine, ball );
70-
constexpr index_t max_try{ 100 };
71-
for( const auto try_id : geode::Range{ max_try } )
72-
{
73-
geode_unused( try_id );
74-
if( domain_.extended_contains( new_point ) )
75-
{
76-
return new_point;
77-
}
78-
new_point =
79-
PointUniformSampler::sample< dimension >( engine, ball );
80-
}
81-
throw OpenGeodeStochasticStochasticException{ nullptr,
82-
OpenGeodeException::TYPE::internal,
83-
"[UniformPointSetSampler] Cannot find a point in the "
84-
"extended domain" };
85-
}
47+
[[nodiscard]] Point< dimension > change( const Point< dimension >& obj,
48+
RandomEngine& engine ) const override;
8649

8750
private:
88-
double define_step_for_move( double ratio )
89-
{
90-
return ratio * domain_.smallest_length();
91-
}
92-
93-
bool is_valid_object( const Point< dimension >& obj ) const override
94-
{
95-
return domain_.extended_contains( obj );
96-
}
51+
[[nodiscard]] double define_step_for_move( double ratio );
52+
[[nodiscard]] bool is_valid_object(
53+
const Point< dimension >& obj ) const override;
9754

9855
private:
9956
const SpatialDomain< dimension >& domain_;
10057
double step_move_{ 0. };
10158
};
10259

103-
template < index_t dimension >
104-
struct ObjectSamplerConfig< Point< dimension > >
105-
{
106-
// use to define the step for change move (move_ratio*domain volume)
107-
double move_ratio = 0.1;
108-
};
109-
110-
template <>
111-
std::unique_ptr< ObjectSetSampler< Point2D > >
112-
build_objectset_sampler< Point2D >( const SpatialDomain< 2 >& domain,
113-
const ObjectSamplerConfig< Point2D >& config )
114-
{
115-
return std::make_unique< UniformPointSetSampler< 2 > >(
116-
domain, config );
117-
}
118-
119-
template <>
120-
std::unique_ptr< ObjectSetSampler< Point3D > >
121-
build_objectset_sampler< Point3D >( const SpatialDomain< 3 >& domain,
122-
const ObjectSamplerConfig< Point3D >& config )
123-
{
124-
return std::make_unique< UniformPointSetSampler< 3 > >(
125-
domain, config );
126-
}
127-
12860
} // namespace geode

include/geode/stochastic/sampling/direct/object_set_sampler/segment_set_sampler.hpp

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -23,79 +23,37 @@
2323

2424
#pragma once
2525

26-
#include <geode/geometry/basic_objects/segment.hpp>
27-
#include <geode/geometry/basic_objects/sphere.hpp>
26+
// #include <geode/geometry/basic_objects/segment.hpp>
2827

28+
#include <geode/stochastic/sampling/direct/double_sampler.hpp>
2929
#include <geode/stochastic/sampling/direct/object_set_sampler/object_set_sampler.hpp>
30-
#include <geode/stochastic/sampling/direct/point_uniform_sampler.hpp>
31-
#include <geode/stochastic/sampling/direct/segment_uniform_sampler.hpp>
32-
#include <geode/stochastic/spatial/spatial_domain.hpp>
3330

3431
namespace geode
3532
{
33+
template <>
34+
struct ObjectSamplerConfig< OwnerSegment2D >
35+
{
36+
double move_ratio = 0.1;
37+
38+
DoubleSampler::DistributionDescription length;
39+
DoubleSampler::DistributionDescription azimuth;
40+
};
41+
3642
class UniformSegmentSetSampler : public ObjectSetSampler< OwnerSegment2D >
3743
{
3844
public:
3945
UniformSegmentSetSampler( const SpatialDomain< 2 >& domain,
40-
const ObjectSamplerConfig< Segment2D >& config )
41-
: ObjectSetSampler< OwnerSegment2D >{},
42-
domain_{ domain },
43-
length_{ DoubleSampler::build_distribution( config.length ) },
44-
azimuth_{ DoubleSampler::build_distribution( config.azimuth ) },
45-
move_ratio_{ config.move_ratio }
46-
{
47-
auto volume = domain_.extended_n_volume();
48-
OpenGeodeStochasticStochasticException::check_exception(
49-
volume != 0., nullptr, OpenGeodeException::TYPE::data,
50-
"[UniformSegmentSetSampler] Undefined Extended Bounding "
51-
"Box (volume ==0)." );
52-
this->log_pdf_ = -std::log( volume );
53-
}
46+
const ObjectSamplerConfig< OwnerSegment2D >& config );
5447

55-
OwnerSegment2D sample( RandomEngine& engine ) const override
56-
{
57-
auto seg = SegmentUniformSampler::sample(
58-
engine, domain_.extended_box(), length_, azimuth_ );
59-
return seg;
60-
}
48+
[[nodiscard]] OwnerSegment2D sample(
49+
RandomEngine& engine ) const override;
6150

62-
OwnerSegment2D change(
63-
const OwnerSegment2D& obj, RandomEngine& engine ) const override
64-
{
65-
const auto& extremities = obj.vertices();
66-
const auto current =
67-
static_cast< local_index_t >( engine.sample_bernoulli( 0.5 ) );
68-
const auto other = 1 - current;
69-
70-
geode::Sphere< 2 > ball{ extremities[current],
71-
move_ratio_ * obj.length() };
72-
73-
auto new_point = PointUniformSampler::sample< 2 >( engine, ball );
74-
constexpr index_t max_try{ 100 };
75-
for( const auto try_id : geode::Range{ max_try } )
76-
{
77-
if( domain_.extended_contains( new_point )
78-
|| domain_.extended_contains( extremities[other] ) )
79-
{
80-
OwnerSegment2D new_segment{ obj };
81-
new_segment.set_point( current, new_point );
82-
return new_segment;
83-
}
84-
new_point = PointUniformSampler::sample< 2 >( engine, ball );
85-
}
86-
throw OpenGeodeStochasticStochasticException{ nullptr,
87-
OpenGeodeException::TYPE::internal,
88-
"[SegmentSetSampler] - Cannot find a point in the box" };
89-
return obj;
90-
}
51+
[[nodiscard]] OwnerSegment2D change(
52+
const OwnerSegment2D& obj, RandomEngine& engine ) const override;
9153

9254
private:
93-
bool is_valid_object( const OwnerSegment2D& obj ) const override
94-
{
95-
const auto& extremities = obj.vertices();
96-
return domain_.extended_contains( extremities[0] )
97-
|| domain_.extended_contains( extremities[1] );
98-
}
55+
[[nodiscard]] bool is_valid_object(
56+
const OwnerSegment2D& obj ) const override;
9957

10058
private:
10159
const SpatialDomain< 2 >& domain_;
@@ -104,21 +62,4 @@ namespace geode
10462
double move_ratio_{ 0.1 };
10563
};
10664

107-
template <>
108-
struct ObjectSamplerConfig< OwnerSegment2D >
109-
{
110-
double move_ratio = 0.1;
111-
112-
DoubleSampler::DistributionDescription length;
113-
DoubleSampler::DistributionDescription azimuth;
114-
};
115-
116-
template <>
117-
std::unique_ptr< ObjectSetSampler< OwnerSegment2D > >
118-
build_objectset_sampler( const SpatialDomain< 2 >& domain,
119-
const ObjectSamplerConfig< OwnerSegment2D >& config )
120-
{
121-
return std::make_unique< UniformSegmentSetSampler >( domain, config );
122-
}
123-
12465
} // namespace geode

0 commit comments

Comments
 (0)