|
|
|||
Warning, file /include/unuran_tests.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /***************************************************************************** 0002 * * 0003 * UNURAN -- Universal Non-Uniform Random number generator * 0004 * * 0005 ***************************************************************************** 0006 * * 0007 * FILE: unuran_tests.h * 0008 * * 0009 * PURPOSE: * 0010 * defines macros and function prototypes for testing routines. * 0011 * * 0012 ***************************************************************************** 0013 * * 0014 * Copyright (c) 2000-2010 Wolfgang Hoermann and Josef Leydold * 0015 * Department of Statistics and Mathematics, WU Wien, Austria * 0016 * * 0017 * This program is free software; you can redistribute it and/or modify * 0018 * it under the terms of the GNU General Public License as published by * 0019 * the Free Software Foundation; either version 2 of the License, or * 0020 * (at your option) any later version. * 0021 * * 0022 * This program is distributed in the hope that it will be useful, * 0023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0025 * GNU General Public License for more details. * 0026 * * 0027 * You should have received a copy of the GNU General Public License * 0028 * along with this program; if not, write to the * 0029 * Free Software Foundation, Inc., * 0030 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA * 0031 * * 0032 *****************************************************************************/ 0033 0034 /*---------------------------------------------------------------------------*/ 0035 #ifndef UNURAN_TESTS_H_SEEN 0036 #define UNURAN_TESTS_H_SEEN 0037 /*---------------------------------------------------------------------------*/ 0038 0039 /* 0040 =NODE Testing Testing 0041 0042 =UP TOP [75] 0043 0044 =DESCRIPTION 0045 The following routines can be used to test the performance of the 0046 implemented generators and can be used to verify the implementions. 0047 They are declared in @file{unuran_tests.h} which has to be included. 0048 0049 =END 0050 0051 */ 0052 0053 /*---------------------------------------------------------------------------*/ 0054 /* possible tests */ 0055 #define UNUR_TEST_ALL (~0u) /* make all possible tests */ 0056 #define UNUR_TEST_TIME 0x001u /* estimate time */ 0057 #define UNUR_TEST_N_URNG 0x002u /* count number of calls to urng */ 0058 #define UNUR_TEST_N_PDF 0x004u /* count PDF calls */ 0059 #define UNUR_TEST_CHI2 0x008u /* run chi^2 test for goodness of fit */ 0060 #define UNUR_TEST_SAMPLE 0x010u /* print a sample file */ 0061 0062 /*---------------------------------------------------------------------------*/ 0063 /* =ROUTINES */ 0064 0065 /*---------------------------------------------------------------------------*/ 0066 0067 void unur_run_tests( UNUR_PAR *parameters, unsigned tests, FILE *out ); 0068 /* 0069 Run a battery of tests. 0070 The following tests are available (use @code{|} to combine these 0071 tests): 0072 @table @code 0073 @item UNUR_TEST_ALL 0074 run all possible tests. 0075 @item UNUR_TEST_TIME 0076 estimate generation times. 0077 @item UNUR_TEST_N_URNG 0078 count number of uniform random numbers 0079 @item UNUR_TEST_N_PDF 0080 count number of PDF calls 0081 @item UNUR_TEST_CHI2 0082 run chi^2 test for goodness of fit 0083 @item UNUR_TEST_SAMPLE 0084 print a small sample. 0085 @end table 0086 All these tests can be started individually (see below). 0087 */ 0088 0089 /*---------------------------------------------------------------------------*/ 0090 /* particular tests */ 0091 0092 void unur_test_printsample( UNUR_GEN *generator, int n_rows, int n_cols, FILE *out ); 0093 /* 0094 Print a small sample with @var{n_rows} rows and @var{n_cols} columns. 0095 @var{out} is the output stream to which all results are written. 0096 */ 0097 0098 UNUR_GEN *unur_test_timing( UNUR_PAR *parameters, int log10_samplesize, 0099 double *time_setup, double *time_sample, 0100 int verbosity, FILE *out ); 0101 /* 0102 Timing. @var{parameters} is an parameter object for which setup 0103 time and marginal generation times have to be measured. The results 0104 are written into @var{time_setup} and @var{time_sample}, 0105 respectively. @var{log10_samplesize} is the common logarithm of the 0106 sample size that is used for timing. 0107 0108 If @var{verbosity} is TRUE then a small table is printed to 0109 output stream @var{out} with setup time, marginal generation time and 0110 average generation times for generating 10, 100, @dots{} random 0111 variates. All times are given in micro seconds and relative to 0112 the generation times for the underlying uniform random number 0113 (using the UNIF interface) and an exponential distributed 0114 random variate using the inversion method. 0115 0116 The created generator object is returned. 0117 If a generator object could not be created successfully, then NULL 0118 is returned. 0119 0120 If @var{verbosity} is TRUE the result is written to the output 0121 stream @var{out}. 0122 0123 Notice: All timing results are subject to heavy changes. Reruning 0124 timings usually results in different results. Minor changes in 0125 the source code can cause changes in such timings up to 25 percent. 0126 */ 0127 0128 double unur_test_timing_R( UNUR_PAR *parameters, const char *distrstr, const char *methodstr, 0129 double log10_samplesize, double *time_setup, double *time_marginal ); 0130 /* 0131 Timing. @var{parameters} is an parameter object for which setup 0132 time and marginal generation times have to be measured. The results 0133 are written into @var{time_setup} and @var{time_marginal}, 0134 respectively. @var{log10_samplesize} is the common logarithm of the 0135 sample size that is used for timing. 0136 0137 Alternatively, one could provide the "parameter object" using 0138 strings @var{distrstr} and @var{methodstr} as used for unur_makegen_ssu(). 0139 0140 The results are more accurate than those of function 0141 unur_test_timing() as the timings are computed using linear 0142 regression with several timings for sample size 1 and 0143 10^@var{log10_samplesize}. 0144 For each sample size total generation time (including setup) is 0145 measured 10 times. Since the these timings can be influenced by 0146 external effects (like disc sync or handling of interupts) the 2 0147 fastest and the 3 slowest timings are discarded. 0148 Intercept and slope for simple linear regression are than stored 0149 and @unurmath{R^2} is returned. 0150 0151 In case of an error @code{-100.} is returned. 0152 0153 Notice: All timing results are subject to heavy changes. Reruning 0154 timings usually results in different results. Minor changes in 0155 the source code can cause changes in such timings up to 25 percent. 0156 */ 0157 0158 double unur_test_timing_uniform( const UNUR_PAR *parameters, int log10_samplesize ); 0159 /* */ 0160 0161 double unur_test_timing_exponential( const UNUR_PAR *parameters, int log10_samplesize ); 0162 /* 0163 Marginal generation times for the underlying uniform random number 0164 (using the UNIF interface) and an exponential distributed 0165 random variate using the inversion method. These times are used in 0166 unur_test_timing() to compute the relative timings results. 0167 */ 0168 0169 double unur_test_timing_total( const UNUR_PAR *parameters, int samplesize, double avg_duration ); 0170 /* 0171 Timing. @var{parameters} is an parameter object for which average 0172 times a sample of size @var{samplesize} (including setup) are 0173 estimated. Thus sampling is repeated and the median of these timings 0174 is returned (in micro seconds). The number of iterations is computed 0175 automatically such that the total amount of time necessary for the 0176 test ist approximately @var{avg_duration} (given in seconds). 0177 However, for very slow generator with expensive setup time the time 0178 necessary for this test may be (much) larger. 0179 0180 If an error occurs then @code{-1} is returned. 0181 0182 Notice: All timing results are subject to heavy changes. Reruning 0183 timings usually results in different results. Minor changes in 0184 the source code can cause changes in such timings up to 25 percent. 0185 */ 0186 0187 int unur_test_count_urn( UNUR_GEN *generator, int samplesize, int verbosity, FILE *out ); 0188 /* 0189 Count used uniform random numbers. It returns the total number of 0190 uniform random numbers required for a sample of non-uniform random 0191 variates of size @var{samplesize}. In case of an error @code{-1} 0192 is returned. 0193 0194 If @var{verbosity} is TRUE the result is written to the output 0195 stream @var{out}. 0196 0197 @emph{Notice:} This test uses global variables to store 0198 counters. Thus it is not thread save. 0199 */ 0200 0201 int unur_test_count_pdf( UNUR_GEN *generator, int samplesize, int verbosity, FILE *out ); 0202 /* 0203 Count evaluations of PDF and similar functions. It returns the 0204 total number of evaluations of all such functions required for a 0205 sample of non-uniform random variates of size @var{samplesize}. 0206 If @var{verbosity} is TRUE then a more detailed report is printed 0207 to the output stream @var{out}. 0208 In case of an error @code{-1} is returned. 0209 This test is run on a copy of the given generator object. 0210 0211 @emph{Notice:} The printed numbers of evaluation should be interpreted 0212 with care. For example, methods either use the PDF or the logPDF; 0213 if only the logPDF is given, but a method needs the PDF then both 0214 the logPDF and the PDF (a wrapper around the logPDF) are called and 0215 thus one call to the PDF is counted twice. 0216 0217 @emph{Notice:} This test uses global variables to store function 0218 pointers and counters. Thus it is not thread save. 0219 */ 0220 0221 int unur_test_par_count_pdf( UNUR_PAR *parameters, int samplesize, int verbosity, FILE *out ); 0222 /* 0223 Same as unur_test_count_pdf() except that it is run on a parameter 0224 object. Thus it also prints the number of function evaluations for 0225 the setup. The temporary created generator object is destroyed 0226 before the results are returned. 0227 */ 0228 0229 double unur_test_chi2( UNUR_GEN *generator, int intervals, int samplesize, int classmin, 0230 int verbosity, FILE *out ); 0231 /* 0232 Run a Chi^2 test with the @var{generator}. 0233 The resulting p-value is returned. 0234 0235 It works with discrete und continuous univariate distributions. 0236 For the latter the CDF of the distribution is required. 0237 0238 @var{intervals} is the number of intervals that is used for 0239 continuous univariate distributions. @var{samplesize} is the size 0240 of the sample that is used for testing. If it is set to @code{0} 0241 then a sample of size @var{intervals}^2 is used (bounded to some 0242 upper bound). 0243 0244 @var{classmin} is the minimum number of expected entries per 0245 class. If a class has to few entries then some classes are joined. 0246 0247 @var{verbosity} controls the output of the routine. If it is set 0248 to @code{1} then the result is written to the output stream 0249 @var{out}. If it is set to @code{2} additionally the list of 0250 expected and observed data is printed. 0251 If it is set to @code{3} then all generated numbers are printed. 0252 There is no output when it is set to @code{0}. 0253 0254 @emph{Notice:} For multivariate distributions the generated points 0255 are transformed by the inverse of the Cholesky factor of the 0256 covariance matrix and the mean vectors (if given for the underlying 0257 distribution). The marginal distributions of the transformed 0258 vectors are then tested against the marginal distribution given by 0259 a unur_distr_cvec_set_marginals() or 0260 unur_distr_cvec_set_marginal_array() call. 0261 (Notice that these marginal distributions are never set by default 0262 for any of the distributions provided by UNU.RAN.) 0263 Then the Bonferroni corrected p-value of all these tests is returned. 0264 However, the test may not be performed correctly if the domain of the 0265 underlying distribution is truncated by a 0266 unur_distr_cvec_set_domain_rect() call and the components of the 0267 distribution are correlated (i.e. unur_distr_cvec_set_covar() is 0268 called with the non-NULL argument). Then it almost surely will fail. 0269 */ 0270 0271 int unur_test_moments( UNUR_GEN *generator, double *moments, int n_moments, int samplesize, 0272 int verbosity, FILE *out ); 0273 /* 0274 Computes the first @var{n_moments} central moments for a sample of 0275 size @var{samplesize}. The result is stored into the array 0276 @var{moments}. 0277 @var{n_moments} must be an integer between @code{1} and @code{4}. 0278 For multivariate distributions the moments are stored consecutively 0279 for each dimension and the provided @var{moments}-array must have 0280 a length of at least (@var{n_moments}+1) * @var{dim}, where @var{dim} 0281 is the dimension of the multivariate distribution. 0282 The @var{m}'th moment for the @var{d}'th dimension (0<=@var{d}<@var{dim}) 0283 is thus stored in the array element 0284 @var{moments}[@var{d}*@var{n_moments}+@var{m}] 0285 0286 If @var{verbosity} is TRUE the result is written to the output 0287 stream @var{out}. 0288 */ 0289 0290 double unur_test_correlation( UNUR_GEN *generator1, UNUR_GEN *generator2, 0291 int samplesize, int verbosity, FILE *out ); 0292 /* 0293 Compute the correlation coefficient between streams from 0294 @var{generator1} and @var{generator2} for two samples of size 0295 @var{samplesize}. 0296 The resultung correlation is returned. 0297 0298 If @var{verbosity} is TRUE the result is written to the output 0299 stream @var{out}. 0300 */ 0301 0302 int unur_test_quartiles( UNUR_GEN *generator, 0303 double *q0, double *q1, double *q2, double *q3, double *q4, 0304 int samplesize, int verbosity, FILE *out ); 0305 /* 0306 Estimate quartiles of sample of size @var{samplesize}. 0307 The resulting quantiles are stored in the variables @var{q}: 0308 @table @var 0309 @item q0 0310 minimum 0311 @item q1 0312 25% 0313 @item q2 0314 median (50%) 0315 @item q3 0316 75% 0317 @item q4 0318 maximum 0319 @end table 0320 0321 If @var{verbosity} is TRUE the result is written to the output 0322 stream @var{out}. 0323 */ 0324 0325 double unur_test_u_error( const UNUR_GEN *generator, 0326 double *max_error, double *MAE, double threshold, 0327 int samplesize, int randomized, int testtails, 0328 int verbosity, FILE *out ); 0329 /* 0330 Estimate U-error of an inversion method, i.e. 0331 @unurmath{error = | CDF^{-1}(U) - U |}, by means of a simple Monte 0332 Carlo method. 0333 Maximum and mean absolute errors are stored in @var{max_error} and 0334 @var{MAE}, respectively. 0335 The particular computed U-errors should not exceed the given 0336 @var{threshold}. However, approximization and round-off errors 0337 might occasionally trigger such an event. 0338 Thus the function returns a penalty score. It is @code{0.} when the 0339 U-error never exceed the @var{threshold} value. It roughly gives the 0340 portion of particular test points where the U-error is too larger. 0341 However, each such event is weighted with 0342 @unurmath{1 + 10 \times (uerror - threshold) / threshold}. 0343 0344 If @var{randomized} is TRUE a pseudo-random sequence is used for 0345 the estimation. 0346 0347 If @var{randomized} is FALSE then the U-values are choosen 0348 equidistributed. 0349 If in addition @var{randomized} is set to TRUE then the tails of 0350 the distributions are tested with a more dense set of points. 0351 0352 If @var{verbosity} is TRUE the result is written to the output 0353 stream @var{out}. 0354 0355 When the domain of the distribution is truncated then the u-error 0356 might be larger due to rescaling of floating point numbers. Thus 0357 the observed u-errors are corrected by the corresponding rescaling 0358 factor. 0359 0360 The test also works for discrete distributions albeit with some 0361 restrictions: 0362 It does not work correctly with truncated distributions and the 0363 @var{testtails} flag is ignored. 0364 Moreover, the value stored in @var{MAE} is rather useless. 0365 0366 In case of an error a negative value is returned. 0367 */ 0368 0369 /* =END */ 0370 0371 /*---------------------------------------------------------------------------*/ 0372 0373 int unur_test_cvec_rankcorr( double *rc, UNUR_GEN *gen, int samplesize, int verbose, FILE *out ); 0374 0375 /*---------------------------------------------------------------------------*/ 0376 #endif /* UNURAN_TESTS_H_SEEN */ 0377 /*---------------------------------------------------------------------------*/
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|