2626#include < geode/stochastic/common.hpp>
2727
2828#include < geode/stochastic/spatial/object_sets.hpp>
29+ #include < geode/stochastic/spatial/spatial_domain.hpp>
2930
3031#include < geode/stochastic/inference/target_statistics.hpp>
3132
3233#include < geode/stochastic/models/model.hpp>
3334
3435#include < geode/stochastic/sampling/direct/object_set_sampler/object_set_sampler.hpp>
35- #include < geode/stochastic/sampling/mcmc/metropolis_hasting_sampler .hpp>
36+ #include < geode/stochastic/sampling/direct/object_set_sampler/point_set_sampler .hpp>
3637
37- #include < geode/stochastic/spatial/spatial_domain.hpp>
38+ #include < geode/stochastic/sampling/mcmc/proposal/classical_proposals.hpp>
39+
40+ #include < geode/stochastic/sampling/mcmc/metropolis_hasting_sampler.hpp>
41+ #include < geode/stochastic/sampling/mcmc/proposal/object_set_dynamic_config.hpp>
3842
3943namespace geode
4044{
@@ -65,4 +69,88 @@ namespace geode
6569 std::unique_ptr< geode::MetropolisHastings< ObjectType > > mh_sampler;
6670 };
6771
72+ template < typename ObjectType >
73+ struct SimulationContextConfig
74+ {
75+ SpatialDomainConfig< ObjectType::dim > domain;
76+
77+ std::vector< ObjectSetConfig > sets;
78+ std::vector< ObjectSetDynamicsConfig > proposals;
79+
80+ geode::ModelConfig model;
81+ };
82+
83+ template < typename ObjectType >
84+ [[nodiscard]] geode::SimulationContext< ObjectType >
85+ build_simulation_context (
86+ const SimulationContextConfig< ObjectType >& config )
87+ {
88+ geode::SimulationContext< ObjectType > context;
89+
90+ // -------------------------
91+ // Domain
92+ // -------------------------
93+ context.domain = geode::build_spatial_domain ( config.domain );
94+
95+ // -------------------------
96+ // Sets
97+ // -------------------------
98+
99+ // auto proposal_kernel =
100+ // std::make_unique< geode::ProposalKernel< geode::Point2D >
101+ // >();
102+ // for( const auto& set_desc : set_descriptors_ )
103+ // {
104+ // const auto set_id = context.object_sets->add_set(
105+ // set_desc.name ); context.set_samplers.push_back(
106+ // std::make_unique< geode::UniformPointSetSampler< 2 >
107+ // >(
108+ // *context.domain ) );
109+ // geode::add_birth_death_change_moves(
110+ // context.set_samplers.back(),
111+ // *proposal_kernel, set_id, set_desc.birth_ratio,
112+ // set_desc.death_ratio, set_desc.change_ratio );
113+ // }
114+ // return proposal_kernel;
115+
116+ for ( const auto & set_cfg : config.sets )
117+ {
118+ const auto set_id = context.object_sets ->add_set ( set_cfg.name );
119+ geode_unused ( set_id );
120+ }
121+
122+ // -------------------------
123+ // Model
124+ // -------------------------
125+ context.model = geode::build_model< ObjectType >(
126+ config.model , *context.object_sets , *context.domain );
127+
128+ // -------------------------
129+ // Proposal
130+ // -------------------------
131+ auto proposal_kernel =
132+ std::make_unique< geode::ProposalKernel< ObjectType > >();
133+ for ( const auto & set_proposal : config.proposals )
134+ {
135+ const auto set_id =
136+ context.object_sets ->get_set_uuid ( set_proposal.name );
137+ context.set_samplers .push_back (
138+ std::make_unique< geode::UniformPointSetSampler< 2 > >(
139+ *context.domain ) );
140+
141+ geode::add_birth_death_change_moves ( context.set_samplers .back (),
142+ *proposal_kernel, set_id, set_proposal.birth_ratio ,
143+ set_proposal.death_ratio , set_proposal.change_ratio );
144+ }
145+
146+ // -------------------------
147+ // MH sampler
148+ // -------------------------
149+ context.mh_sampler =
150+ std::make_unique< geode::MetropolisHastings< geode::Point2D > >(
151+ *context.model , std::move ( proposal_kernel ) );
152+
153+ return context;
154+ }
155+
68156} // namespace geode
0 commit comments