vSMC
vSMC: Scalable Monte Carlo
vsmc.h
Go to the documentation of this file.
1 /*============================================================================
2  * vSMC/include/vsmc/vsmc.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_VSMC_H
33 #define VSMC_VSMC_H
34 
35 #include <stddef.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
43 
46 
48 typedef struct {
49  int state[64];
50 } vsmc_rng;
51 
53 int vsmc_rng_size();
54 
56 void vsmc_rng_init(vsmc_rng *rng_ptr, int seed);
57 
59 void vsmc_rng_seed(vsmc_rng *rng_ptr, int seed);
60 
62 void vsmc_rng_get_key(const vsmc_rng *rng_ptr, int n, int *key);
63 
65 void vsmc_rng_set_key(vsmc_rng *rng_ptr, int n, const int *key);
66 
68 void vsmc_rng_get_ctr(const vsmc_rng *rng_ptr, int n, int *ctr);
69 
71 void vsmc_rng_set_ctr(vsmc_rng *rng_ptr, int n, const int *ctr);
72 
74 void vsmc_rng_rand(vsmc_rng *rng_ptr, int n, int *r);
75 
77 void vsmc_rng_u01_sorted(int n, const double *u01, double *u01seq);
78 
80 void vsmc_rng_u01_stratified(int n, const double *u01, double *u01seq);
81 
83 void vsmc_rng_u01_systematic(int n, double u01, double *u01seq);
84 
86 void vsmc_rng_discrete(vsmc_rng *rng_ptr, int n, int *r, int m,
87  const double *weight, int normalized);
88 
90 void vsmc_rng_uniform_int(vsmc_rng *rng_ptr, int n, int *r, int a, int b);
91 
93 void vsmc_rng_bernoulli(vsmc_rng *rng_ptr, int n, int *r, double p);
94 
96 void vsmc_rng_binomial(vsmc_rng *rng_ptr, int n, int *r, int t, double p);
97 
100  vsmc_rng *rng_ptr, int n, int *r, int k, double p);
101 
103 void vsmc_rng_geometric(vsmc_rng *rng_ptr, int n, int *r, double p);
104 
106 void vsmc_rng_poisson(vsmc_rng *rng_ptr, int n, int *r, double mean);
107 
109 void vsmc_rng_beta(
110  vsmc_rng *rng_ptr, int n, double *r, double alpha, double beta);
111 
113 void vsmc_rng_cauchy(vsmc_rng *rng_ptr, int n, double *r, double a, double b);
114 
116 void vsmc_rng_chi_squared(vsmc_rng *rng_ptr, int n, double *r, double df);
117 
119 void vsmc_rng_exponential(vsmc_rng *rng_ptr, int n, double *r, double lambda);
120 
123  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
124 
126 void vsmc_rng_fisher_f(
127  vsmc_rng *rng_ptr, int n, double *r, double df1, double df2);
128 
130 void vsmc_rng_gamma(
131  vsmc_rng *rng_ptr, int n, double *r, double alpha, double beta);
132 
134 void vsmc_rng_laplace(vsmc_rng *rng_ptr, int n, double *r, double a, double b);
135 
137 void vsmc_rng_levy(vsmc_rng *rng_ptr, int n, double *r, double a, double b);
138 
140 void vsmc_rng_logistic(
141  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
142 
144 void vsmc_rng_lognormal(
145  vsmc_rng *rng_ptr, int n, double *r, double m, double s);
146 
148 void vsmc_rng_normal(
149  vsmc_rng *rng_ptr, int n, double *r, double mean, double stddev);
150 
152 void vsmc_rng_normal_mv(vsmc_rng *rng_ptr, int n, double *r, int dim,
153  const double *mean, const double *chol);
154 
156 void vsmc_rng_pareto(vsmc_rng *rng_ptr, int n, double *r, double a, double b);
157 
159 void vsmc_rng_rayleigh(vsmc_rng *rng_ptr, int n, double *r, double b);
160 
162 void vsmc_rng_student_t(vsmc_rng *rng_ptr, int n, double *r, double df);
163 
165 void vsmc_rng_u01(vsmc_rng *rng_ptr, int n, double *r);
166 
169  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
170 
172 void vsmc_rng_weibull(vsmc_rng *rng_ptr, int n, double *r, double a, double b);
173 
175 
178 
179 int vsmc_mkl_brng_mt19937(void);
181 int vsmc_mkl_brng_minstd_rand(void);
182 int vsmc_mkl_brng_mt19937_64(void);
185 int vsmc_mkl_brng_ranlux24(void);
186 int vsmc_mkl_brng_ranlux48(void);
187 int vsmc_mkl_brng_knuth_b(void);
188 int vsmc_mkl_brng_philox2x32(void);
189 int vsmc_mkl_brng_philox4x32(void);
190 int vsmc_mkl_brng_philox2x64(void);
191 int vsmc_mkl_brng_philox4x64(void);
204 int vsmc_mkl_brng_aes128_1x32(void);
205 int vsmc_mkl_brng_aes128_2x32(void);
206 int vsmc_mkl_brng_aes128_4x32(void);
207 int vsmc_mkl_brng_aes128_8x32(void);
208 int vsmc_mkl_brng_aes128_1x64(void);
209 int vsmc_mkl_brng_aes128_2x64(void);
210 int vsmc_mkl_brng_aes128_4x64(void);
211 int vsmc_mkl_brng_aes128_8x64(void);
212 int vsmc_mkl_brng_aes192_1x32(void);
213 int vsmc_mkl_brng_aes192_2x32(void);
214 int vsmc_mkl_brng_aes192_4x32(void);
215 int vsmc_mkl_brng_aes192_8x32(void);
216 int vsmc_mkl_brng_aes192_1x64(void);
217 int vsmc_mkl_brng_aes192_2x64(void);
218 int vsmc_mkl_brng_aes192_4x64(void);
219 int vsmc_mkl_brng_aes192_8x64(void);
220 int vsmc_mkl_brng_aes256_1x32(void);
221 int vsmc_mkl_brng_aes256_2x32(void);
222 int vsmc_mkl_brng_aes256_4x32(void);
223 int vsmc_mkl_brng_aes256_8x32(void);
224 int vsmc_mkl_brng_aes256_1x64(void);
225 int vsmc_mkl_brng_aes256_2x64(void);
226 int vsmc_mkl_brng_aes256_4x64(void);
227 int vsmc_mkl_brng_aes256_8x64(void);
228 int vsmc_mkl_brng_ars_1x32(void);
229 int vsmc_mkl_brng_ars_2x32(void);
230 int vsmc_mkl_brng_ars_4x32(void);
231 int vsmc_mkl_brng_ars_8x32(void);
232 int vsmc_mkl_brng_ars_1x64(void);
233 int vsmc_mkl_brng_ars_2x64(void);
234 int vsmc_mkl_brng_ars_4x64(void);
235 int vsmc_mkl_brng_ars_8x64(void);
236 int vsmc_mkl_brng_rdrand16(void);
237 int vsmc_mkl_brng_rdrand32(void);
238 int vsmc_mkl_brng_rdrand64(void);
239 
241 
244 
246 int vsmc_random_walk(vsmc_rng *rng_ptr, int dim, double *x, double *ltx,
247  double (*log_target)(int, const double *),
248  double (*proposal)(vsmc_rng *, int, const double *, double *));
249 
251 int vsmc_random_walk_g(vsmc_rng *rng_ptr, int dim_x, int dim_g, double *x,
252  double *ltx, double *g,
253  double (*log_target)(int, int, const double *, double *),
254  double (*proposal)(vsmc_rng *, int, const double *, double *));
255 
257 double vsmc_normal_proposal(vsmc_rng *rng_ptr, int, const double *x, double *y,
258  double stddev, double a, double b);
259 
261 double vsmc_normal_mv_proposal(vsmc_rng *rng_ptr, int dim, const double *x,
262  double *y, const double *chol, const double *a, const double *b);
263 
265 
268 
269 void *vsmc_malloc(size_t n, int alignment);
270 void vsmc_free(void *ptr);
271 
273 
276 
277 typedef enum {
285 
287  int m, int n, const double *weight, const double *u01, int *replication);
289  int m, int n, const double *weight, const double *u01, int *index);
291  int m, int n, const int *replication, int *index);
293  int m, int n, const int *index, int *replication);
295  int m, int n, const double *weight, double *resid, int *integ);
296 
298  int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication);
300  int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication);
302  int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication);
304  int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication);
306  int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication);
308  int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication);
309 void vsmc_resample(int m, int n, vsmc_rng *rng_ptr, const double *weight,
310  int *replication, vsmc_resample_scheme scheme);
311 
313 
315 
316 #ifdef __cplusplus
317 } // extern "C"
318 #endif
319 
320 #endif // VSMC_VSMC_H
void vsmc_rng_set_ctr(vsmc_rng *rng_ptr, int n, const int *ctr)
vsmc::RNG::ctr
void vsmc_rng_exponential(vsmc_rng *rng_ptr, int n, double *r, double lambda)
vsmc::ExponentialDistribution<double>
int vsmc_mkl_brng_threefry4x64sse2(void)
int vsmc_mkl_brng_threefry2x64sse2(void)
int vsmc_mkl_brng_rdrand16(void)
void vsmc_rng_rand(vsmc_rng *rng_ptr, int n, int *r)
vsmc::RNG::operator()
void vsmc_resample_stratified(int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication)
void vsmc_resample_residual_systematic(int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication)
int vsmc_mkl_brng_threefry2x64(void)
int vsmc_mkl_brng_ranlux48(void)
int vsmc_mkl_brng_rdrand64(void)
void vsmc_rng_uniform_real(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::UniformRealDistribution<double>
void vsmc_rng_levy(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::LevyDistribution<double>
int vsmc_mkl_brng_philox4x32(void)
int vsmc_mkl_brng_aes192_8x32(void)
int vsmc_mkl_brng_ranlux48_base(void)
void vsmc_rng_init(vsmc_rng *rng_ptr, int seed)
vsmc::RNG constructor
void vsmc_rng_normal_mv(vsmc_rng *rng_ptr, int n, double *r, int dim, const double *mean, const double *chol)
vsmc::NormalMVDistribution<double, vsmc::Dynamic>
void vsmc_resample_trans_u01_index(int m, int n, const double *weight, const double *u01, int *index)
void vsmc_rng_chi_squared(vsmc_rng *rng_ptr, int n, double *r, double df)
vsmc::ChiSquaredDistribution<double>
int vsmc_mkl_brng_aes128_4x32(void)
int vsmc_mkl_brng_mt19937(void)
void vsmc_rng_beta(vsmc_rng *rng_ptr, int n, double *r, double alpha, double beta)
vsmc::BetaDistribution<double>
void vsmc_rng_u01_systematic(int n, double u01, double *u01seq)
vsmc::u01_systematic
void vsmc_rng_poisson(vsmc_rng *rng_ptr, int n, int *r, double mean)
std::poisson_distribution<int>
void vsmc_rng_bernoulli(vsmc_rng *rng_ptr, int n, int *r, double p)
std::bernoulli_distribution
void vsmc_resample_residual(int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication)
int vsmc_mkl_brng_threefry2x32(void)
void vsmc_free(void *ptr)
double vsmc_normal_mv_proposal(vsmc_rng *rng_ptr, int dim, const double *x, double *y, const double *chol, const double *a, const double *b)
vsmc::NormalMVProposal<double, vsmc::Dynamic>
void vsmc_rng_weibull(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::WeibullDistribution<double>
int vsmc_mkl_brng_threefry4x64avx2(void)
int vsmc_mkl_brng_ars_8x32(void)
void vsmc_resample_trans_rep_index(int m, int n, const int *replication, int *index)
int vsmc_mkl_brng_aes192_2x64(void)
int vsmc_mkl_brng_ars_4x64(void)
void vsmc_rng_geometric(vsmc_rng *rng_ptr, int n, int *r, double p)
std::geometri_distribution<int>
void vsmc_rng_logistic(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::LogisticDistribution<double>
void vsmc_rng_pareto(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::ParetoDistribution<double>
int vsmc_mkl_brng_aes192_8x64(void)
int vsmc_mkl_brng_aes256_4x64(void)
int vsmc_mkl_brng_aes192_4x64(void)
int vsmc_mkl_brng_aes256_4x32(void)
int vsmc_mkl_brng_aes128_2x64(void)
int vsmc_mkl_brng_aes256_8x32(void)
int vsmc_mkl_brng_aes256_2x32(void)
void vsmc_rng_u01_stratified(int n, const double *u01, double *u01seq)
vsmc::u01_stratifed
int vsmc_mkl_brng_aes256_1x64(void)
int vsmc_mkl_brng_aes128_8x64(void)
void vsmc_resample(int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication, vsmc_resample_scheme scheme)
int vsmc_mkl_brng_threefry2x32avx2(void)
int vsmc_mkl_brng_aes256_2x64(void)
int vsmc_mkl_brng_aes128_1x64(void)
int vsmc_mkl_brng_aes128_1x32(void)
int vsmc_mkl_brng_ars_2x64(void)
int vsmc_mkl_brng_aes256_8x64(void)
int vsmc_mkl_brng_knuth_b(void)
int vsmc_mkl_brng_ranlux24(void)
void vsmc_rng_lognormal(vsmc_rng *rng_ptr, int n, double *r, double m, double s)
vsmc::LognormalDistribution<double>
void vsmc_resample_systematic(int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication)
int vsmc_mkl_brng_threefry4x32(void)
void vsmc_resample_trans_index_rep(int m, int n, const int *index, int *replication)
void vsmc_rng_u01(vsmc_rng *rng_ptr, int n, double *r)
vsmc::U01Distribution<double>
int vsmc_random_walk(vsmc_rng *rng_ptr, int dim, double *x, double *ltx, double(*log_target)(int, const double *), double(*proposal)(vsmc_rng *, int, const double *, double *))
vsmc::RandomWalk<double, vsmc::Dynamic>
int vsmc_mkl_brng_aes192_2x32(void)
int vsmc_mkl_brng_aes128_2x32(void)
void vsmc_resample_multinomial(int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication)
int vsmc_mkl_brng_philox2x64(void)
int vsmc_mkl_brng_minstd_rand0(void)
void vsmc_rng_student_t(vsmc_rng *rng_ptr, int n, double *r, double df)
vsmc::StudentTDistribution<double>
void vsmc_rng_extreme_value(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::ExtremeValueDistribution<double>
int vsmc_mkl_brng_aes192_4x32(void)
void vsmc_rng_laplace(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::LaplaceDistribution<double>
int vsmc_mkl_brng_ars_8x64(void)
void vsmc_rng_gamma(vsmc_rng *rng_ptr, int n, double *r, double alpha, double beta)
vsmc::GammaDistribution<double>
void vsmc_rng_u01_sorted(int n, const double *u01, double *u01seq)
vsmc::u01_sorted
int vsmc_mkl_brng_mt19937_64(void)
int vsmc_mkl_brng_threefry4x32avx2(void)
vsmc_resample_scheme
Definition: vsmc.h:277
void * vsmc_malloc(size_t n, int alignment)
double vsmc_normal_proposal(vsmc_rng *rng_ptr, int, const double *x, double *y, double stddev, double a, double b)
vsmc::NormalProposal<double>
void vsmc_rng_binomial(vsmc_rng *rng_ptr, int n, int *r, int t, double p)
std::binomial_distribution<int>
int vsmc_random_walk_g(vsmc_rng *rng_ptr, int dim_x, int dim_g, double *x, double *ltx, double *g, double(*log_target)(int, int, const double *, double *), double(*proposal)(vsmc_rng *, int, const double *, double *))
vsmc::RandomWalkG<double, vsmc::Dynamic, vsmc::Dynamic>
int vsmc_mkl_brng_aes128_8x32(void)
int vsmc_mkl_brng_aes192_1x64(void)
void vsmc_rng_get_key(const vsmc_rng *rng_ptr, int n, int *key)
vsmc::RNG::key
void vsmc_rng_discrete(vsmc_rng *rng_ptr, int n, int *r, int m, const double *weight, int normalized)
vsmc::DiscreteDistribution<int>
int vsmc_mkl_brng_threefry2x32sse2(void)
int vsmc_resample_trans_residual(int m, int n, const double *weight, double *resid, int *integ)
int vsmc_mkl_brng_ars_2x32(void)
int vsmc_mkl_brng_ars_4x32(void)
int vsmc_mkl_brng_philox2x32(void)
int vsmc_mkl_brng_threefry2x64avx2(void)
void vsmc_rng_cauchy(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::CachyDistribution<double>
void vsmc_resample_trans_u01_rep(int m, int n, const double *weight, const double *u01, int *replication)
int vsmc_mkl_brng_rdrand32(void)
void vsmc_rng_uniform_int(vsmc_rng *rng_ptr, int n, int *r, int a, int b)
std::uniform_int_distribution<int>
int vsmc_rng_size()
sizeof(vsmc::RNG) + 4
int vsmc_mkl_brng_ranlux24_base(void)
void vsmc_rng_get_ctr(const vsmc_rng *rng_ptr, int n, int *ctr)
vsmc::RNG::ctr
int vsmc_mkl_brng_aes192_1x32(void)
void vsmc_rng_set_key(vsmc_rng *rng_ptr, int n, const int *key)
vsmc::RNG::key
int vsmc_mkl_brng_aes256_1x32(void)
int vsmc_mkl_brng_philox4x64(void)
int vsmc_mkl_brng_minstd_rand(void)
int vsmc_mkl_brng_threefry4x64(void)
void vsmc_rng_fisher_f(vsmc_rng *rng_ptr, int n, double *r, double df1, double df2)
vsmc::FisherFDistribution<double>
void vsmc_rng_seed(vsmc_rng *rng_ptr, int seed)
vsmc::RNG::seed
int vsmc_mkl_brng_ars_1x64(void)
void vsmc_resample_residual_stratified(int m, int n, vsmc_rng *rng_ptr, const double *weight, int *replication)
void vsmc_rng_normal(vsmc_rng *rng_ptr, int n, double *r, double mean, double stddev)
vsmc::NormalDistribution<double>
vsmc::RNG
Definition: vsmc.h:48
int vsmc_mkl_brng_ars_1x32(void)
int vsmc_mkl_brng_threefry4x32sse2(void)
int vsmc_mkl_brng_aes128_4x64(void)
void vsmc_rng_rayleigh(vsmc_rng *rng_ptr, int n, double *r, double b)
vsmc::RayleighDistribution<double>
void vsmc_rng_negative_binomial(vsmc_rng *rng_ptr, int n, int *r, int k, double p)
std::negative_binomial_distribution<int>