Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

trnglib.h

00001 // ---------------------------------------------------------------------
00002 // Time-stamp: <Samstag, 25.01.2003, 14:00:07; edited by heiko>
00003 // 
00004 // Tina's random number generators TRNG
00005 //
00006 // useful functions for Tina's random number generators 
00007 //
00008 // Copyright (C) 2001, 2002 Heiko Bauke
00009 //
00010 // heiko.bauke@physik.uni-magdeburg.de
00011 //
00012 // TRNG is free software; you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License
00014 // as published by the Free Software Foundation. This program
00015 // is distributed WITHOUT ANY WARRANTY; without even the implied
00016 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 // See the GNU General Public License for more details.
00018 //
00019 // ---------------------------------------------------------------------
00020 
00021 #if !defined TRNGLIB_H
00022 
00023 #define TRNGLIB_H
00024 
00025 #include <vector>
00026 #include <stdexcept>
00027 #include <string>
00028 
00029 namespace TRNG {
00030 
00032 
00035   class error : public std::exception {
00036     std::string _what;
00037   public:
00038     error(const std::string &what_arg) : _what(what_arg) {
00039     };
00040     const char * what(void) const {
00041       return _what.c_str();
00042     };
00043   };
00044 
00046 
00051   class power {
00052     long b, modulus;
00053     std::vector<long> b_power1, b_power0;
00054   
00055     void calc_b_power(void) {
00056       long long c=1ll;
00057       for (long i=0l; i<0x10000l; ++i) {
00058         b_power0[i]=c;
00059         c*=b;
00060         c%=modulus;
00061       }
00062       long long b_2_16=b;
00063       for (long i=0; i<16; ++i) {
00064         b_2_16*=b_2_16;
00065         b_2_16%=modulus;
00066       }
00067       c=1ll;
00068       for (long i=0l; i<0x10000l; ++i) {
00069         b_power1[i]=c;
00070         c*=b_2_16;
00071         c%=modulus;
00072       }
00073     }
00074 
00075   public:
00076     long operator()(const long n) const {
00077       return static_cast<long int>((static_cast<long long>(b_power1[n>>16])*
00078                                     static_cast<long long>(b_power0[n&0xffff]))
00079                                    %modulus);
00080     }
00081     
00082     long operator()(void) const {
00083       return b;
00084     }
00085 
00086     void set(const long b_, const long modulus_) {
00087       b=b_;
00088       modulus=modulus_;
00089       calc_b_power();
00090     }
00091     
00092     power(const long b_, const long modulus_) : 
00093       b_power0(0x10000), 
00094       b_power1(0x10000),
00095       b(b_),
00096       modulus(modulus_) {
00097       calc_b_power();
00098     }
00099 
00100     virtual ~power() {
00101     }
00102   };
00103 
00104   const char * version(void);
00105   long modulo_invers(long, long);
00106   void gauss(std::vector<long> &, std::vector<long> &, long);
00107   void matrix_mult(const std::vector<long> &, const std::vector<long> &,
00108                    std::vector<long> &, long);
00109   void matrix_vec_mult(const std::vector<long> &, const std::vector<long> &, 
00110                        std::vector<long> &, long);
00111 
00112   double Gamma(double);
00113   double ln_Gamma(double);
00114   double Gamma_P(double, double);
00115   double Gamma_Q(double, double);
00116   double incomp_Gamma(double, double);
00117   double comp_incomp_Gamma(double, double);
00118   double Gamma_ser(double, double);
00119   double Gamma_cf(double, double);
00120   double ln_factorial(long);
00121   long binomial_coeff(long, long);
00122   double errf(double);
00123   double chi_square_test(const std::vector<double> &, 
00124                          const std::vector<double> &);
00125   double chi_square_prob(double, long);
00126   double Stirling_num2(long, long);
00127   double Student_t(double, long, bool=true);
00128   long find_interval(const std::vector<double> &, const double);
00129 
00130   double uniform_pdf(double);
00131   double uniform_pdf(double, double, double);
00132   double uniformco_pdf(double);
00133   double uniformco_pdf(double, double, double);
00134   double uniformcc_pdf(double);
00135   double uniformcc_pdf(double, double, double);
00136   double uniformoc_pdf(double);
00137   double uniformoc_pdf(double, double, double);
00138   double uniformoo_pdf(double);
00139   double uniformoo_pdf(double, double, double);
00140   double normal_dist_pdf(double, double, double);
00141   double exp_dist_pdf(double, double);
00142   double laplace_dist_pdf(double, double);
00143   double tent_dist_pdf(double, double);
00144   double Gamma_dist_pdf(double, double, double);
00145   double Beta_dist_pdf(double, double, double);
00146   double chi_square_dist_pdf(double, double);
00147   double Student_t_dist_pdf(double, double);
00148   double binomial_dist_pdf(long, long, double);
00149   double poisson_dist_pdf(long, double);
00150   double geometric_dist_pdf(long, double);
00151 
00152 }
00153   
00154 #endif
00155 
00156 

Generated on Wed Feb 19 02:00:03 2003 for Tina's Random Number Generators by doxygen1.2.15