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

QuasiMonteCarlo.h

Go to the documentation of this file.
00001 /* WARANTY NOTICE AND COPYRIGHT
00002 This program is free software; you can redistribute it and/or
00003 modify it under the terms of the GNU General Public License
00004 as published by the Free Software Foundation; either version 2
00005 of the License, or (at your option) any later version.
00006 
00007 This program is distributed in the hope that it will be useful,
00008 but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 GNU General Public License for more details.
00011 
00012 You should have received a copy of the GNU General Public License
00013 along with this program; if not, write to the Free Software
00014 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00015 
00016 Copyright (C) Michael J. Meyer
00017 
00018 matmjm@mindspring.com
00019 spyqqqdia@yahoo.com
00020 
00021 */
00022 
00023 
00024 /*
00025  * QuasiMonteCarlo.h
00026  *
00027  * Created on March 21, 2003, 12:45 PM
00028  */
00029  
00030  
00031 #ifndef martingale_lowdiscrepancysequence_h    
00032 #define martingale_lowdiscrepancysequence_h    
00033 
00034 #include "TypedefsMacros.h"
00035 #include "Array.h"
00036 
00037 MTGL_BEGIN_NAMESPACE(Martingale)
00038 
00039 
00040 
00041 
00049 /*******************************************************************************
00050  *
00051  *                     LOW DISCREPANCY SEQUENCE
00052  *
00053  ******************************************************************************/
00054 
00055 
00060 class LowDiscrepancySequence {
00061         
00062 protected:
00063     
00064     int dim;           // dimension
00065     int index;         // index of current point in sequence
00066     
00067     RealArray1D x;     // current uniform point
00068     RealArray1D z;     // current quasi normal transform of x
00069         
00070 public:
00071         
00072 // ACCESSORS
00073         
00076         int getDimension(){ return dim; }
00077         
00079         virtual void restart(){ };
00080         
00081         
00082 // CONSTRUCTOR
00083     
00087     LowDiscrepancySequence(int d);
00088         
00090         virtual ~LowDiscrepancySequence(){ }
00091     
00092     
00093 
00094 // POINT GENERATION
00095 
00098     virtual const RealArray1D& nextPoint() = 0;
00099     
00103     void writeNextPoint(RealArray1D& r);
00104      
00105     
00106     
00107 // L^2-DISCREPANCY 
00108     
00109     
00116      Real l2Discrepancy(int N, const RealArray2D& r);
00117          
00118         
00132      Real l2Discrepancy(int N, const RealArray2D& r, Real T_N);     
00133      
00134 
00135 // TRANSFORM UNIFORM -> MULTINORMAL
00136 
00137          
00143      const RealArray1D& nextQuasiNormalVector();
00144          
00145          
00146 private:
00147          
00149      // r[j][] is the jth point in the low discrepancy sequence
00150      Real product(int i, int j, const RealArray2D& r);
00151          
00152      
00154      // r[j][] is the jth point in the low discrepancy sequence
00155      Real product(int i, const RealArray2D& r);
00156      
00157      
00159      // r[j][] is the jth point in the low discrepancy sequence
00160      Real productSQ(int i, const RealArray2D& r);
00161 
00162 
00163 }; // end LowDiscrepancySequence
00164 
00165 
00166 
00167 /*******************************************************************************
00168  *
00169  *                     NIEDERREITER-XING SEQUENCE
00170  *
00171  ******************************************************************************/
00172 
00173 
00197 class NX : public LowDiscrepancySequence {
00198     
00199     static const int M=30;               // we are using 30 bit integers
00200     static const Real N=1073741842;      // 2^30
00201     
00202     IntArray1D x_int;    // current vector of NX integers
00203     
00217     int*** genMats; 
00218         
00219         int d;  // max(dim,4), see above.
00220         
00221         
00222 public:
00223 
00228     NX(int dim);
00229         
00230         ~NX();
00231     void restart();
00232         
00235     const RealArray1D& nextPoint();
00236     
00237 }; // end NXT
00238 
00239 
00240 
00241 
00242 /*******************************************************************************
00243  *
00244  *                     SOBOL SEQUENCE
00245  *
00246  ******************************************************************************/
00247 
00248 
00289 class Sobol : public LowDiscrepancySequence {
00290     
00291     static const int bits=32;             // we are using 32 bit integers
00292     static const Real N=4294967296.0;     // 2^32 to big for int
00293     
00294     
00295     UnsignedLongArray2D v;        // v[k] - array of direction numbers for dimension k
00296     IntArray2D p;                 // p[k] - coefficient array of the k-th primitive polynomial
00297     IntArray1D g;                 // g[k] - degree of the k-th primitive polynomial
00298     UnsignedLongArray1D x_int;    // current vector of Sobol integers
00299         
00300         int index;      // index of current Sobol point
00301     
00302 public:
00303     
00304 // THE SOBOL POINTS
00305 
00306     void restart();
00307     
00308 
00311     const RealArray1D& nextPoint();
00312     
00313     
00314         
00315 // CONSTRUCTOR
00316         
00317         
00336      void read_prim_pol(int k, int n, int d);
00337          
00340      void printInitialization();
00341 
00342 
00346      Sobol(int dim);   
00347     
00348 }; // end Sobol
00349 
00350 
00351  
00352 
00353 
00354 MTGL_END_NAMESPACE(Martingale)
00355 
00356 #endif
00357 

Generated on Mon Sep 22 02:16:32 2003 for Libor-Library by doxygen1.3-rc3