vSMC  v3.0.0
Scalable Monte Carlo
core.h
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/core/core.h
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2016, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_CORE_CORE_H
33 #define VSMC_CORE_CORE_H
34 
35 #include <vsmc/internal/common.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
43 
46 
48 void vsmc_weight_delete(vsmc_weight *weight_ptr);
49 
51 void vsmc_weight_assign(vsmc_weight weight, vsmc_weight other);
52 
54 size_t vsmc_weight_size(vsmc_weight weight);
55 
57 void vsmc_weight_resize(vsmc_weight weight, size_t n);
58 
60 void vsmc_weight_reserve(vsmc_weight weight, size_t n);
61 
64 
66 double vsmc_weight_ess(vsmc_weight weight);
67 
69 void vsmc_weight_read_weight(vsmc_weight weight, double *first, int stride);
70 
72 const double *vsmc_weight_data(vsmc_weight weight);
73 
76 
78 void vsmc_weight_set(vsmc_weight weight, const double *first, int stride);
79 
81 void vsmc_weight_mul(vsmc_weight weight, const double *first, int stride);
82 
84 void vsmc_weight_set_log(vsmc_weight weight, const double *first, int stride);
85 
87 void vsmc_weight_add_log(vsmc_weight weight, const double *first, int stride);
88 
90 size_t vsmc_weight_draw(vsmc_weight weight, vsmc_rng rng);
91 
93 
96 
98 vsmc_state_matrix vsmc_state_matrix_new(size_t n, size_t dim);
99 
101 void vsmc_state_matrix_delete(vsmc_state_matrix *state_matrix_ptr);
102 
105  vsmc_state_matrix state_matrix, vsmc_state_matrix other);
106 
108 size_t vsmc_state_matrix_size(vsmc_state_matrix state_matrix);
109 
111 size_t vsmc_state_matrix_dim(vsmc_state_matrix state_matrix);
112 
115  vsmc_state_matrix state_matrix, size_t n, size_t dim);
116 
119  vsmc_state_matrix state_matrix, size_t n, size_t dim);
120 
123 
125 double vsmc_state_matrix_get(
126  vsmc_state_matrix state_matrix, size_t id, size_t pos);
127 
130  vsmc_state_matrix state_matrix, size_t id, size_t pos, double s);
131 
133 double *vsmc_state_matrix_data(vsmc_state_matrix state_matrix);
134 
136 double *vsmc_state_matrix_row_data(vsmc_state_matrix state_matrix, size_t id);
137 
139 double *state_matrix_row_data(vsmc_state_matrix state_matrix, size_t id);
140 
143  vsmc_state_matrix state_matrix, size_t pos, double *first);
144 
147  vsmc_state_matrix state_matrix, vSMCMatrixLayout layout, double *first);
148 
151  vsmc_state_matrix state_matrix, size_t n, const size_t *index);
152 
155  vsmc_state_matrix state_matrix, size_t src, size_t dst);
156 
158 
161 
163 vsmc_particle vsmc_particle_new(size_t n, size_t dim);
164 
166 void vsmc_particle_delete(vsmc_particle *particle_ptr);
167 
169 void vsmc_particle_assign(vsmc_particle particle, vsmc_particle other);
170 
173 
175 size_t vsmc_particle_size(vsmc_particle particle);
176 
179  vsmc_particle particle, size_t n, const size_t *index);
180 
183  vsmc_particle particle, size_t n, vSMCResampleScheme scheme);
184 
186 void vsmc_particle_resize_by_uniform(vsmc_particle particle, size_t n);
187 
190 
193 
195 vsmc_rng vsmc_particle_rng(vsmc_particle particle, size_t id);
196 
199 
201 
204 
207  int record_only, vSMCMonitorStage stage);
208 
210 void vsmc_monitor_delete(vsmc_monitor *monitor_ptr);
211 
213 void vsmc_monitor_assign(vsmc_monitor monitor, vsmc_monitor other);
214 
216 size_t vsmc_monitor_dim(vsmc_monitor monitor);
217 
220 
223 
225 size_t vsmc_monitor_iter_size(vsmc_monitor monitor);
226 
228 void vsmc_monitor_reserve(vsmc_monitor monitor, size_t num);
229 
231 int vsmc_monitor_empty(vsmc_monitor monitor);
232 
234 void vsmc_monitor_set_name(vsmc_monitor monitor, size_t id, const char *name);
235 
237 size_t vsmc_monitor_get_name(vsmc_monitor monitor, size_t id, char *name);
238 
240 size_t vsmc_monitor_index(vsmc_monitor monitor, size_t iter);
241 
243 void vsmc_monitor_read_index(vsmc_monitor monitor, size_t *fist);
244 
246 double vsmc_monitor_record(vsmc_monitor monitor, size_t id, size_t iter);
247 
249 void vsmc_monitor_read_record(vsmc_monitor monitor, size_t id, double *first);
250 
253  vsmc_monitor monitor, vSMCMatrixLayout layout, double *first);
254 
257  int record_only, vSMCMonitorStage stage);
258 
260 void vsmc_monitor_compute(vsmc_monitor monitor, size_t iter,
261  vsmc_particle particle, vSMCMonitorStage stage);
262 
264 void vsmc_monitor_clear(vsmc_monitor monitor);
265 
267 
270 
272 vsmc_sampler vsmc_sampler_new(size_t n, size_t dim);
273 
275 void vsmc_sampler_delete(vsmc_sampler *sampler_ptr);
276 
278 void vsmc_sampler_assign(vsmc_sampler sampler, vsmc_sampler other);
279 
282 
284 size_t vsmc_sampler_size(vsmc_sampler sampler);
285 
287 void vsmc_sampler_reserve(vsmc_sampler sampler, size_t num);
288 
290 size_t vsmc_sampler_iter_size(vsmc_sampler sampler);
291 
293 size_t vsmc_sampler_iter_num(vsmc_sampler sampler);
294 
297  vSMCSamplerStage stage, int append);
298 
301  vsmc_sampler sampler, vSMCResampleScheme scheme, double threshold);
302 
305  vsmc_sampler sampler, vsmc_sampler_eval_type res_move, double threshold);
306 
309 
311 void vsmc_sampler_set_threshold(vsmc_sampler sampler, double threshold);
312 
315 
318 
321  vsmc_sampler sampler, const char *name, vsmc_monitor mon);
322 
324 vsmc_monitor vsmc_sampler_get_monitor(vsmc_sampler sampler, const char *name);
325 
327 int vsmc_sampler_monitor_clear(vsmc_sampler sampler, const char *name);
328 
331 
334 
336 void vsmc_sampler_iterate(vsmc_sampler sampler, size_t num);
337 
340 
342 size_t vsmc_sampler_size_history(vsmc_sampler sampler, size_t iter);
343 
345 void vsmc_sampler_read_size_history(vsmc_sampler sampler, size_t *first);
346 
348 double vsmc_sampler_ess_history(vsmc_sampler sampler, size_t iter);
349 
351 void vsmc_sampler_read_ess_history(vsmc_sampler sampler, double *first);
352 
354 int vsmc_sampler_resampled_history(vsmc_sampler sampler, size_t iter);
355 
357 void vsmc_sampler_read_resampled_history(vsmc_sampler sampler, int *first);
358 
361  vsmc_sampler sampler, size_t iter, size_t id);
362 
364 size_t vsmc_sampler_print(vsmc_sampler sampler, char *buf, char sepchar);
365 
368  vsmc_sampler sampler, const char *filename, char sepchar);
369 
371 
372 #ifdef __cplusplus
373 } // extern "C"
374 #endif
375 
376 #endif // VSMC_CORE_CORE_H
void vsmc_state_matrix_read_state(vsmc_state_matrix state_matrix, size_t pos, double *first)
vsmc::StateMatrix::read_state
void vsmc_monitor_delete(vsmc_monitor *monitor_ptr)
vsmc::Monitor::~Monitor
void vsmc_monitor_read_record_matrix(vsmc_monitor monitor, vSMCMatrixLayout layout, double *first)
vsmc::Monitor::read_record_matrix
size_t vsmc_sampler_iter_size(vsmc_sampler sampler)
vsmc::Sampler::iter_size
void vsmc_sampler_delete(vsmc_sampler *sampler_ptr)
vsmc::Sampler::~Sampler
size_t vsmc_monitor_iter_size(vsmc_monitor monitor)
vsmc::Monitor::iter_size
void vsmc_monitor_reserve(vsmc_monitor monitor, size_t num)
vsmc::Monitor::reserve
void vsmc_state_matrix_shrink_to_fit(vsmc_state_matrix state_matrix)
vsmc::StateMatrix::shrink_to_fit
void(* vsmc_monitor_eval_type)(size_t, size_t, vsmc_particle, double *)
vsmc::Monitor::eval_type
Definition: defines.h:222
vsmc_monitor vsmc_sampler_get_monitor(vsmc_sampler sampler, const char *name)
vsmc::Sampler::monitor
vsmc::SingleParticle
Definition: defines.h:188
void vsmc_sampler_set_monitor(vsmc_sampler sampler, const char *name, vsmc_monitor mon)
vsmc::Sampler::monitor
vsmc_state_matrix vsmc_state_matrix_new(size_t n, size_t dim)
vsmc::StateMatrix::StateMatrix
vsmc_weight vsmc_particle_weight(vsmc_particle particle)
vsmc::Particle::weight
size_t(* vsmc_sampler_eval_type)(size_t, vsmc_particle)
vsmc::Sampler::eval_type
Definition: defines.h:219
void vsmc_state_matrix_select(vsmc_state_matrix state_matrix, size_t n, const size_t *index)
vsmc::StateMatrix::copy
void vsmc_state_matrix_reserve(vsmc_state_matrix state_matrix, size_t n, size_t dim)
vsmc::StateMatrix::reserve
int vsmc_sampler_monitor_clear(vsmc_sampler sampler, const char *name)
vsmc::Sampler::monitor_clear
int vsmc_monitor_empty(vsmc_monitor monitor)
vsmc::Monitor::empty
size_t vsmc_sampler_iter_num(vsmc_sampler sampler)
vsmc::Sampler::iter_num
size_t vsmc_monitor_dim(vsmc_monitor monitor)
vsmc::Monitor::dim
void vsmc_sampler_set_threshold(vsmc_sampler sampler, double threshold)
vsmc::Sampler::resample_threshold
double * state_matrix_row_data(vsmc_state_matrix state_matrix, size_t id)
vsmc::StateMatrix::row_data
vsmc::Particle
Definition: defines.h:194
size_t vsmc_sampler_print(vsmc_sampler sampler, char *buf, char sepchar)
vsmc::Sampler::print
void vsmc_monitor_compute(vsmc_monitor monitor, size_t iter, vsmc_particle particle, vSMCMonitorStage stage)
vsmc::Monitor::operator()
void vsmc_weight_set_log(vsmc_weight weight, const double *first, int stride)
vsmc::Weight::set_log
double * vsmc_state_matrix_row_data(vsmc_state_matrix state_matrix, size_t id)
vsmc::StateMatrix::row_data
size_t vsmc_monitor_index(vsmc_monitor monitor, size_t iter)
vsmc::Monitor::index
void vsmc_weight_resize(vsmc_weight weight, size_t n)
vsmc::Weight::resize
double vsmc_state_matrix_get(vsmc_state_matrix state_matrix, size_t id, size_t pos)
vsmc::StateMatrix::state
vsmc_single_particle vsmc_particle_sp(vsmc_particle particle, size_t id)
vsmc::Particle::sp
vsmc_state_matrix vsmc_particle_state(vsmc_particle particle)
vsmc::Particle::state
int vsmc_monitor_record_only(vsmc_monitor monitor)
vsmc::Monitor::record_only
void vsmc_weight_add_log(vsmc_weight weight, const double *first, int stride)
vsmc::Weight::add_log
size_t vsmc_sampler_size(vsmc_sampler sampler)
vsmc::Sampler::size
vSMCMonitorStage
vsmc::MonitorStage
Definition: defines.h:61
double vsmc_monitor_record(vsmc_monitor monitor, size_t id, size_t iter)
vsmc::Monitor::record
vsmc_weight vsmc_weight_new(size_t n)
vsmc::Weight::Weight
void vsmc_weight_mul(vsmc_weight weight, const double *first, int stride)
vsmc::Weight::mul
void vsmc_particle_delete(vsmc_particle *particle_ptr)
vsmc::Particle::~Particle
void vsmc_particle_resize_by_index(vsmc_particle particle, size_t n, const size_t *index)
vsmc::Particle::resize_by_index
void vsmc_state_matrix_read_state_matrix(vsmc_state_matrix state_matrix, vSMCMatrixLayout layout, double *first)
vsmc::StateMatrix::read_state_matrix
size_t vsmc_monitor_get_name(vsmc_monitor monitor, size_t id, char *name)
vsmc::Monitor::name
void vsmc_particle_resize_by_resample(vsmc_particle particle, size_t n, vSMCResampleScheme scheme)
vsmc::Particle::resize_by_resample
void vsmc_monitor_read_record(vsmc_monitor monitor, size_t id, double *first)
vsmc::Monitor::read_record
void vsmc_sampler_resample_eval(vsmc_sampler sampler, vsmc_sampler_eval_type res_move, double threshold)
vsmc::Sampler::resample_method
vsmc::Monitor
Definition: defines.h:204
vsmc_sampler vsmc_sampler_new(size_t n, size_t dim)
vsmc::Sampler::Sampler
void vsmc_weight_assign(vsmc_weight weight, vsmc_weight other)
vsmc::Weight::operator=
void vsmc_state_matrix_delete(vsmc_state_matrix *state_matrix_ptr)
vsmc::StateMatrix::~StateMatrix
vsmc_particle vsmc_sampler_particle(vsmc_sampler sampler)
vsmc::Sampler::particle
double vsmc_sampler_resample_threshold_never(void)
vsmc::Sampler::resample_threshold_never
size_t vsmc_particle_size(vsmc_particle particle)
vsmc::Particle::size
vSMCSamplerStage
vsmc::SamplerStage
Definition: defines.h:68
vsmc_particle vsmc_particle_new(size_t n, size_t dim)
vsmc::Particle::Particle
void vsmc_sampler_iterate(vsmc_sampler sampler, size_t num)
vsmc::Sampler::iterate
void vsmc_monitor_clear(vsmc_monitor monitor)
vsmc::Monitor::clear
vsmc_monitor vsmc_monitor_new(size_t dim, vsmc_monitor_eval_type eval, int record_only, vSMCMonitorStage stage)
vsmc::Monitor::Monitor
double vsmc_sampler_ess_history(vsmc_sampler sampler, size_t iter)
vsmc::Sampler::ess_history
size_t vsmc_weight_size(vsmc_weight weight)
vsmc::Weight::size
void vsmc_sampler_print_f(vsmc_sampler sampler, const char *filename, char sepchar)
vsmc::Sampler::print directly to an external file
void vsmc_sampler_eval(vsmc_sampler sampler, vsmc_sampler_eval_type new_eval, vSMCSamplerStage stage, int append)
vsmc::Sampler::eval
vSMCMonitorStage vsmc_monitor_stage(vsmc_monitor monitor)
vsmc::Monitor::stage
void vsmc_weight_read_weight(vsmc_weight weight, double *first, int stride)
vsmc::Weight::read_weight
void vsmc_monitor_read_index(vsmc_monitor monitor, size_t *fist)
vsmc::Monitor::read_index
vSMCMatrixLayout
vsmc::MatrixLayout
Definition: defines.h:45
vsmc_sampler vsmc_sampler_clone(vsmc_sampler sampler)
vsmc::Sampler::clone
void vsmc_sampler_assign(vsmc_sampler sampler, vsmc_sampler other)
vsmc::Sampler::operator=
void vsmc_sampler_initialize(vsmc_sampler sampler)
vsmc::Sampler::initialize
void vsmc_sampler_read_ess_history(vsmc_sampler sampler, double *first)
vsmc::Sampler::read_ess_history
vsmc::Weight
Definition: defines.h:183
void vsmc_weight_reserve(vsmc_weight weight, size_t n)
vsmc::Weight::reserve
void vsmc_sampler_read_size_history(vsmc_sampler sampler, size_t *first)
vsmc::Sampler::read_size_history
void vsmc_weight_shrink_to_fit(vsmc_weight weight)
vsmc::Weight::shrink_to_fit
int vsmc_sampler_resampled_history(vsmc_sampler sampler, size_t iter)
vsmc::Sampler::resampled_history
const double * vsmc_weight_data(vsmc_weight weight)
vsmc::Weight::data
vsmc_rng vsmc_particle_rng(vsmc_particle particle, size_t id)
vsmc::Particle::rng
void vsmc_weight_delete(vsmc_weight *weight_ptr)
vsmc::Weight::~Weight
void vsmc_state_matrix_set(vsmc_state_matrix state_matrix, size_t id, size_t pos, double s)
vsmc::StateMatrix::state
size_t vsmc_state_matrix_size(vsmc_state_matrix state_matrix)
vsmc::StateMatrix::size
void vsmc_weight_set_equal(vsmc_weight weight)
vsmc::Weight::set_equal
size_t vsmc_weight_draw(vsmc_weight weight, vsmc_rng rng)
vsmc::Weight::draw
void vsmc_particle_resize_by_uniform(vsmc_particle particle, size_t n)
vsmc::Particle::resize_by_uniform
double vsmc_sampler_resample_threshold_always(void)
vsmc::Sampler::resample_threshold_always
void vsmc_sampler_reserve(vsmc_sampler sampler, size_t num)
vsmc::Sampler::reserve
void vsmc_weight_set(vsmc_weight weight, const double *first, int stride)
vsmc::Weight::set
vsmc_particle vsmc_particle_clone(vsmc_particle particle)
vsmc::Particle::clone
vsmc::Sampler
Definition: defines.h:199
`vsmc::StateMatrix<vsmc::RowMajor, vsmc::Dynamic, double>
Definition: defines.h:178
void vsmc_state_matrix_resize(vsmc_state_matrix state_matrix, size_t n, size_t dim)
vsmc::StateMatrix::resize
void vsmc_sampler_read_resampled_history(vsmc_sampler sampler, int *first)
vsmc::Sampler::read_resampled_history
void vsm_state_matrix_assign(vsmc_state_matrix state_matrix, vsmc_state_matrix other)
vsmc::StateMatrix::operator=
size_t vsmc_sampler_status_history(vsmc_sampler sampler, size_t iter, size_t id)
vsmc::Sampler::status_history
double vsmc_weight_ess(vsmc_weight weight)
vsmc::Weight::ess
void vsmc_monitor_eval(vsmc_monitor monitor, vsmc_monitor_eval_type new_eval, int record_only, vSMCMonitorStage stage)
vsmc::Monitor::eval
size_t vsmc_state_matrix_dim(vsmc_state_matrix state_matrix)
vsmc::StateMatrix::dim
vSMC RNG types
Definition: defines.h:172
void vsmc_state_matrix_duplicate(vsmc_state_matrix state_matrix, size_t src, size_t dst)
vsmc::StateMatrix::duplicate
double vsmc_sampler_get_threshold(vsmc_sampler sampler)
vsmc::Sampler::resample_threshold
void vsmc_particle_assign(vsmc_particle particle, vsmc_particle other)
vsmc::Particle::operator=
vSMCResampleScheme
vsmc::ResampleScheme
Definition: defines.h:51
size_t vsmc_sampler_size_history(vsmc_sampler sampler, size_t iter)
vsmc::Sampler::size_history
void vsmc_monitor_set_name(vsmc_monitor monitor, size_t id, const char *name)
vsmc::Monitor::name
void vsmc_sampler_monitor_clear_all(vsmc_sampler sampler)
vsmc::Sampler::monitor_clear
void vsmc_sampler_resample_scheme(vsmc_sampler sampler, vSMCResampleScheme scheme, double threshold)
vsmc::Sampler::resample_method
void vsmc_monitor_assign(vsmc_monitor monitor, vsmc_monitor other)
vsmc::Monitor::operator=
double * vsmc_state_matrix_data(vsmc_state_matrix state_matrix)
vsmc::StateMatrix::data