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-2015, 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_pareto(vsmc_rng *rng_ptr, int n, double *r, double a, double b);
153 
155 void vsmc_rng_rayleigh(vsmc_rng *rng_ptr, int n, double *r, double b);
156 
158 void vsmc_rng_student_t(vsmc_rng *rng_ptr, int n, double *r, double df);
159 
161 void vsmc_rng_u01(vsmc_rng *rng_ptr, int n, double *r);
162 
164 void vsmc_rng_u01_cc(vsmc_rng *rng_ptr, int n, double *r);
165 
167 void vsmc_rng_u01_co(vsmc_rng *rng_ptr, int n, double *r);
168 
170 void vsmc_rng_u01_oc(vsmc_rng *rng_ptr, int n, double *r);
171 
173 void vsmc_rng_u01_oo(vsmc_rng *rng_ptr, int n, double *r);
174 
177  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
178 
181  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
182 
185  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
186 
189  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
190 
193  vsmc_rng *rng_ptr, int n, double *r, double a, double b);
194 
196 void vsmc_rng_weibull(vsmc_rng *rng_ptr, int n, double *r, double a, double b);
197 
199 
202 
203 int vsmc_mkl_brng_mt19937(void);
205 int vsmc_mkl_brng_minstd_rand(void);
206 int vsmc_mkl_brng_mt19937_64(void);
209 int vsmc_mkl_brng_ranlux24(void);
210 int vsmc_mkl_brng_ranlux48(void);
211 int vsmc_mkl_brng_knuth_b(void);
212 int vsmc_mkl_brng_philox2x32(void);
213 int vsmc_mkl_brng_philox4x32(void);
214 int vsmc_mkl_brng_philox2x64(void);
215 int vsmc_mkl_brng_philox4x64(void);
228 int vsmc_mkl_brng_aes128_1x32(void);
229 int vsmc_mkl_brng_aes128_2x32(void);
230 int vsmc_mkl_brng_aes128_4x32(void);
231 int vsmc_mkl_brng_aes128_8x32(void);
232 int vsmc_mkl_brng_aes128_1x64(void);
233 int vsmc_mkl_brng_aes128_2x64(void);
234 int vsmc_mkl_brng_aes128_4x64(void);
235 int vsmc_mkl_brng_aes128_8x64(void);
236 int vsmc_mkl_brng_aes192_1x32(void);
237 int vsmc_mkl_brng_aes192_2x32(void);
238 int vsmc_mkl_brng_aes192_4x32(void);
239 int vsmc_mkl_brng_aes192_8x32(void);
240 int vsmc_mkl_brng_aes192_1x64(void);
241 int vsmc_mkl_brng_aes192_2x64(void);
242 int vsmc_mkl_brng_aes192_4x64(void);
243 int vsmc_mkl_brng_aes192_8x64(void);
244 int vsmc_mkl_brng_aes256_1x32(void);
245 int vsmc_mkl_brng_aes256_2x32(void);
246 int vsmc_mkl_brng_aes256_4x32(void);
247 int vsmc_mkl_brng_aes256_8x32(void);
248 int vsmc_mkl_brng_aes256_1x64(void);
249 int vsmc_mkl_brng_aes256_2x64(void);
250 int vsmc_mkl_brng_aes256_4x64(void);
251 int vsmc_mkl_brng_aes256_8x64(void);
252 int vsmc_mkl_brng_ars_1x32(void);
253 int vsmc_mkl_brng_ars_2x32(void);
254 int vsmc_mkl_brng_ars_4x32(void);
255 int vsmc_mkl_brng_ars_8x32(void);
256 int vsmc_mkl_brng_ars_1x64(void);
257 int vsmc_mkl_brng_ars_2x64(void);
258 int vsmc_mkl_brng_ars_4x64(void);
259 int vsmc_mkl_brng_ars_8x64(void);
260 int vsmc_mkl_brng_rdrand16(void);
261 int vsmc_mkl_brng_rdrand32(void);
262 int vsmc_mkl_brng_rdrand64(void);
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 *src_idx);
291  int m, int n, const int *replication, int *src_idx);
293  int m, int n, const int *src_idx, 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)
void vsmc_rng_uniform_real_cc(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::UniformRealCCDistribution<double>
void vsmc_resample_trans_index_rep(int m, int n, const int *src_idx, int *replication)
int vsmc_mkl_brng_ranlux48_base(void)
void vsmc_rng_init(vsmc_rng *rng_ptr, int seed)
vsmc::RNG constructor
void vsmc_rng_uniform_real_oo(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::UniformRealOODistribution<double>
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)
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)
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)
void vsmc_resample_trans_rep_index(int m, int n, const int *replication, int *src_idx)
int vsmc_mkl_brng_aes192_4x64(void)
int vsmc_mkl_brng_aes256_4x32(void)
void vsmc_rng_uniform_real_oc(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::UniformRealOCDistribution<double>
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_oo(vsmc_rng *rng_ptr, int n, double *r)
vsmc::U01OODistribution<double>
void vsmc_rng_u01_oc(vsmc_rng *rng_ptr, int n, double *r)
vsmc::U01OCDistribution<double>
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)
void vsmc_rng_u01_co(vsmc_rng *rng_ptr, int n, double *r)
vsmc::U01CODistribution<double>
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_rng_u01(vsmc_rng *rng_ptr, int n, double *r)
vsmc::U01Distribution<double>
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)
void vsmc_rng_uniform_real_co(vsmc_rng *rng_ptr, int n, double *r, double a, double b)
vsmc::UniformRealCODistribution<double>
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)
void vsmc_rng_binomial(vsmc_rng *rng_ptr, int n, int *r, int t, double p)
std::binomial_distribution<int>
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_u01_cc(vsmc_rng *rng_ptr, int n, double *r)
vsmc::U01CCDistribution<double>
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_resample_trans_u01_index(int m, int n, const double *weight, const double *u01, int *src_idx)
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>