📄 binormal.java,v
字号:
{ for(k=0; k<jm1; k++) { t = a[k+(j-1)*lda] - sdot(k, a, k*lda, 1, a, (j-1)*lda, 1); t /= a[k+k*lda]; a[k+(j-1)*lda] = t; s += (t*t); } } s = a[j-1+(j-1)*lda] - s; if(s <= 0.0) { flag = 1; break S40; } a[j-1+(j-1)*lda] = Math.sqrt(s); } if (flag == 0) info = new Integer(0); return; } /** * Generates binormal gaussian random deviates * * @@param max number of deviates * @@param mx mean, X-COORDINATE * @@param my mean, y-coordinate * @@param c11 a11 element of the covariance matrix * @@param c12 a12 element of the covariance matrix * @@param c21 a21 element of the covariance matrix * @@param c22 a22 element of the covariance matrix * @@param xval x-vector of the gaussian random deviates * @@param yval y-vector of the gaussian random deviates * * */ public void gaussian(int max, double mx, double my, double[] xval,double[] yval, double c11, double c12, double c21, double c22) { // declare local variables // double[] val = null; double[] work = null; double[] mean = null; double[] covm = null; double[] param = null; // allocate memory // mean = new double[2]; covm = new double[4]; val = new double[2]; work = new double[max]; param = new double[max]; // set the mean for the binormal gaussian generator // mean[0] = mx; mean[1] = my; // set the covariance matrix for the binormal gaussian generator // covm[0] = c11; covm[1] = c12; covm[2] = c21; covm[3] = c22; // initialize the binormal gaussian random generator // setgmn(mean, covm, 2, param); // generate the binormal gaussian random deviates // for(int i = 0; i < max; i++) { genmn(param, val, work); xval[i] = val[0]; yval[i] = val[1]; } }}@1.4log@fixed javadoc errors.@text@d1 1a1 1/**d17 3a19 1@1.3log@ Changed the comments to Java Documentation Style. Aligned the for loops and If statements as well.@text@d4 3d8 1d97 2a98 1 * method: setgmnd100 3a102 2 * @@param double[] meanv: mean vector of multivariate normal distribution * @@param double[] covm: covariance matrix of multivariate d104 2a105 2 * @@param int p: dimension of the normal * @@param double[] parm: array of parameters needed to generate a107 10 * @@return none * * methods sets up the parameters needed to generate the multivariate * normal deviates form the inputs given * * param 1 : 1 - p * 2 : P + 1 - meanv * P+2 : P*(P+3)/2 + 1 - Cholesky decomposition of covm * needed dimension is (p*(p+3)/2 + 1) *a162 9 * method: genmn * * @@param double[] x: vector deviate generated * @@param double[] work: scratch array * @@param double[] parm: array of parameters needed to generate * multivariate normal deviates * * @@return none *d168 5d174 1a174 1 public void genmn(double[] parm,double[] x,double[] work) d221 1a221 1 * method: ranfa222 1 * @@param nonea225 2 * generates a uniform distribution over 0 - 1 *a232 4 * method: snorm40 * * @@param none * @@return nonea248 4 * method: snorm50 * * @@param none * @@return nonea261 4 * method: snorm60 * * @@param none * @@return nonea275 4 * method: snorm70 * * @@param none * @@return nonea288 4 * method: snorm80 * * @@param none * @@return nonea311 4 * method: snorm100 * * @@param none * @@return nonea324 4 * method: snorm110 * * @@param none * @@return nonea337 4 * method: snorm120 * * @@param none * @@return nonea355 4 * method: snorm140 * * @@param none * @@return nonea368 4 * method: snorm150 * * @@param none * @@return nonea380 4 * method: snorm160 * * @@param none * @@return nonea404 5 * method: snorm * * @@param none * @@return standard normal distribution *d410 3a450 1 * method: sdotd455 9a543 2 * method: spofa *d547 3d597 1a597 11 * method: gaussian * * @@param int max: number of deviates * @@param double mx: mean, x-coordinate * @@param double my: mean, y-coordinate * @@param double c11: a11 element of the covariance matrix * @@param double c12: a12 element of the covariance matrix * @@param double c21: a21 element of the covariance matrix * @@param double c22: a22 element of the covariance matrix * @@param double[] xval: x-vector of the gaussian random deviates * @@param double[] yval: y-vector of the gaussian random deviatesd599 9a607 1 * @@return nonea608 1 * method generates binormal Gaussian random deviates@1.2log@Algorithm Complete and debug statements commented@text@d1 11a11 9// file: BiNormal.java////These imports are not needed - Phil T. 6-23-03//import java.awt.*;//import java.applet.*;//import javax.swing.*;//import java.lang.*;//import java.io.*;d14 3a16 2public class BiNormal {d92 21a112 19 // method: setgmn // // arguments: // double[] meanv: mean vector of multivariate normal distribution // double[] covm: covariance matrix of multivariate normal distribution // int p: dimension of the normal // double[] parm: array of parameters needed to generate // multivariate normal deviates // // return: none // // methods sets up the parameters needed to generate the multivariate // normal deviates form the inputs given // // param 1 : 1 - p // 2 : P + 1 - meanv // P+2 : P*(P+3)/2 + 1 - Cholesky decomposition of covm // needed dimension is (p*(p+3)/2 + 1) //d114 2a115 1 double[] parm) {d128 1a128 1 //System.out.println("P nonpositive in SETGMN");d145 1a145 1 //System.out.println(" COVM not positive definite in SETGMN");d166 18a183 16 // method: genmn // // arguments: // double[] x: vector deviate generated // double[] work: scratch array // double[] parm: array of parameters needed to generate // multivariate normal deviates // // return: none // // methods generates the multivariate normal deviates using the procedure: // 1) generate p independent standard normal deviates - ei ~ n(0,1) // 2) using cholesky decomposition find a s.t. trans(a)*a = covm // 3) trans(a)e + meanv ~ n(meanv,covm) // public void genmn(double[] parm,double[] x,double[] work) {d199 2a200 1 for(i=1; i<=p; i++) {d204 2a205 1 for(i=1, D3=1, D4=(p-i+D3)/D3; D4>0; D4--, i+=D3) {d228 12a239 10 // method: ranf // // arguments: none // returns : random floating point number from a uniform distribution // over 0 - 1 using the current generator // // generates a uniform distribution over 0 - 1 // public double ranf() {d242 11a252 9 // method: snorm40 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab //d254 2a255 1 if(ustar <= t[snormi-1]) {d263 12a274 9 // method: snorm50 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm50() {d280 12a291 9 // method: snorm60 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm60() {d298 12a309 9 // method: snorm70 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm70() {d315 14a328 10 // method: snorm80 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm80() { if(ustar > snormtt) {d333 2a334 1 if(ustar >= snormu) {d342 12a353 9 // method: snorm100 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm100() {d359 12a370 9 // method: snorm110 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm110() {d376 12a387 9 // method: snorm120 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm120() {d389 2a390 1 if(snormu < 1.0) {d397 13a409 10 // method: snorm140 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm140() {d415 12a426 9 // method: snorm150 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm150() {d431 12a442 9 // method: snorm160 // // arguments: none // returns : none // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void snorm160() {d444 2a445 1 if(ustar > snormtt) {d450 2a451 1 if(ustar >= snormu) {d458 15a472 12 // method: snorm // // arguments: none // returns : standard normal distribution // // ahrens, j.h. and dieter, u. // extensions of forsythe's method for random // sampling from the normal distribution. // math. comput., 27,124 (oct. 1973), 927 - 937. // public double snorm() {d477 2a478 1 if(snormu > 0.5) {d486 2a487 1 if(snormi == 32) {d490 2a491 1 if(snormi == 0) {d507 7a513 5 // method: sdot // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab //d515 2a516 1 double[] sy, int dy, int incy) {d529 3a531 2 if(incx != 1 && incy != 1) {d535 3a537 2 for(i=1; i<=n; i++) {d542 1a542 1d546 1a546 1d549 2a550 1 if(m == 0) {d552 2a553 1 for(i=mp1; i<=n; i+=5) {d562 6a567 3 } else { for(i=0; i<m; i++) {d570 2a571 1 if(n < 5) {d574 3a576 1 } else {d578 2a579 1 for(i=mp1; i<=n; i+=5) {d591 11a601 7 // method: spofa // // linpack. this version dated 08/14/78 // cleve moler, university of new mexico, argonne national lab // public void spofa(double[] a, int lda, int n) {d611 3a613 2 for(j=1; j<=n; j++) {d617 5a621 3 if(jm1 >= 1) { for(k=0; k<jm1; k++) {d629 1a629 1d632 2a633 1 if(s <= 0.0) {d640 1a640 1d643 19a661 18 // method: gaussian // // argument: // int max: number of deviates // double mx: mean, x-coordinate // double my: mean, y-coordinate // double c11: a11 element of the covariance matrix // double c12: a12 element of the covariance matrix // double c21: a21 element of the covariance matrix // double c22: a22 element of the covariance matrix // double[] xval: x-vector of the gaussian random deviates // double[] yval: y-vector of the gaussian random deviates // // return : none // // method generates binormal Gaussian random deviates //d663 3a665 2 double[] xval,double[] yval, double c11, double c12, double c21, double c22) {d701 2a702 1 for(int i = 0; i < max; i++) {a708 6//// end of file@1.1log@Initial revision@text@d122 1a122 1 System.out.println("P nonpositive in SETGMN");d139 1a139 1 System.out.println(" COVM not positive definite in SETGMN");@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -