2010年4月23日 星期五

Java distribution function:SSJ 2.2

首頁:http://www.iro.umontreal.ca/~simardr/
線上文件:http://www.iro.umontreal.ca/~simardr/ssj/doc/html/
原始碼(.jar)下載位置:http://www.iro.umontreal.ca/~simardr/ssj/ssj-20091109.zip

匯入 .jar 檔的方法,以 JBuilder 2007 Turbo 為例
只要將檔案貼到 C:\JBuilder2007\jre\jre\lib\ext 後重新啟動 JBuilder 2007 即可。


使用方法以 Lognormal distribution generator 為例:

import umontreal.iro.lecuyer.randvar.LognormalGen;
import umontreal.iro.lecuyer.rng.*;

public class lognormalTest {
 private LognormalGen logNormal;
 double mu = 7.15; /* lognormal distribution generater 的 parameter */
 double sigma = 1;

 public lognormalTest () {
  logNormal = new LognormalGen(new WELL607(), mu, sigma);
  for(int i=0 ; i<10 ; i++)
   System.out.println(logNormal.nextDouble());
 }
}

其中參數 new WELL607() 是函式庫提供的一種 Random Number Generator
只要是實做函式庫中 RandomStream 這個 Interface 的 generator 就可以作為參數。
詳情可以參考線上文件中 RandomStream 的頁面:http://www.iro.umontreal.ca/~simardr/ssj/doc/html/umontreal/iro/lecuyer/rng/RandomStream.html
在例子中使用的 WELL607 為 RandomStreamBase 的其中一個 subclass,可參考:http://www.iro.umontreal.ca/~simardr/ssj/doc/html/umontreal/iro/lecuyer/rng/WELL607.html

印出的結果:
4544.13780133174
1818.3021176861146
3912.911276689462
1686.5159268708644
5635.515690751279
1546.5212670642882
1155.568513760517
215.44057678984063
10820.999018567574
1762.1212867097274
255.96127081126255
946.1457506937251
3693.040146087003
5798.044906297541
7676.43108018721
1999.7263370735532
394.65425469667724
670.642091439543
4861.763375428422
2863.063703840674

沒有留言: