⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 l2discrepancygraph.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 JAVA
字号:
/* WARANTY NOTICE AND COPYRIGHTThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.Copyright (C) Michael J. Meyermatmjm@mindspring.comspyqqqdia@yahoo.com*//* * L2DiscrepancyGraph.java * * Created on April 30, 2002, 5:58 AM */package Examples.QuasiMonteCarlo;import com.skylit.io.EasyReader;import QuasiRandom.*;import Graphics.*;import Statistics.LoopStatus;/**<p>Graphs the L2-discrepancy of Halton and Sobol sequence or the ratio * of the two L2-discrepancies for the first 10000 points.</p>  * * @author  Michael J. Meyer */public class L2DiscrepancyGraph {        public static void main(String[] args)    {        int dim=1,            N=10000,            nPoints=1+(N-1000)/100;            // discrepancies evaluated at each point n=k*100            // starting with n=1000.                            double x_min=1000,               x_max=N;                        // discrepancies[n] and their ratios        double[] HaltonL2D=new double[nPoints],                 SobolL2D=new double[nPoints],                 NX2D=new double[nPoints],                 //Uniform2D=new double[nPoints];                 ratio=new double[nPoints];                //main loop, exits progressbar-frame on close        while(true){                // get user input        EasyReader io=new EasyReader();                System.out.print        ("Graphing L2-Discrepancies of the Halton, Sobol and NX sequences\n"+         "Enter dimension (at most 20): ");        dim=io.readInt();                System.out.print        ("All discrepancies individually (0) or ratio Halton/Sobol (1)?\n"+         "Enter choice (0/1): ");        int choice=io.readInt();                                LowDiscrepancySequence H=new Halton(dim),                               S=new Sobol(dim),                               NX=new NX(dim);                               //U=new Uniform(dim);                        // arrays of low discrepancy points        double[][] rh=new double[N][dim],                   rs=new double[N][dim],                   rnx=new double[N][dim];                   //ru=new double[N][dim];                        // fill the point arrays        for(int i=0;i<N;i++)        {            H.nextPoint(rh[i]);   // write the point into rh[i]            S.nextPoint(rs[i]);             NX.nextPoint(rnx[i]);             //U.nextPoint(ru[i]);        }                        double hT_N=0,     // Halton sequence discrepancy               sT_N=0,     // Sobol sequence discrepancy               nxT_N=0;    // NX sequence discrepancy               //uT_N=0;   // Uniform sequence discrepancy                // recursive computation, report progress         LoopStatus loopStatus=new LoopStatus();        long before=System.currentTimeMillis();        for(int n=0;n<N;n++)        {             hT_N=H.L2_discrepancy(n,rh,hT_N);             sT_N=S.L2_discrepancy(n,rs,sT_N);             nxT_N=S.L2_discrepancy(n,rnx,nxT_N);             //uT_N=U.L2_discrepancy(n,ru,uT_N);                          // current number of points is 1+m             int m=1+n;             if((m%100==0)&&(m>999))             {                 HaltonL2D[(m-1000)/100]=hT_N;                SobolL2D[(m-1000)/100]=sT_N;                 NX2D[(m-1000)/100]=nxT_N;                 //UniformL2D[(m-1000)/100]=uT_N;                 ratio[(m-1000)/100]=hT_N/sT_N;             }                                                 // progress report           int loops=n*n;    // algorithm is quadratic           if(loops%37==36)           loopStatus.progressReport(loops,N*N,37,before);         }                        // plot them                JGraph graph=new JGraph(1000,N);        graph.setTitle("L2-discrepancies, dimension "+dim);        graph.setXAxisLabel("points");        graph.setBounds(120,30,550,400);                if(choice==0){ graph.addSeries(HaltonL2D,"Halton");                       graph.addSeries(SobolL2D,"Sobol");                        graph.addSeries(NX2D,"NX"); }                       //graph.addSeries(UniformL2D,"Uniform"); }        else graph.addSeries(ratio,"ratio Halton/Sobol");        graph.setVisible(true);                 try{  Thread.currentThread().sleep(5000); }         catch( InterruptedException e){}                String filename="l2d"+dim+".dat";        graph.saveAsASCII(filename);        graph.saveAsPNG();        } // end main loop           } // end main} // end L2DiscrepancyGraph

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -