com.kutsyy.util
Class Mvndstpack

java.lang.Object
  |
  +--com.kutsyy.util.Mvndstpack

public final class Mvndstpack
extends Object

This class implements multivariate normal integration.
Method is based on MCMC. class use its own random number generator,
and does not depends an any other classes
so no sinchronization is required for multithreading.

Description from original FORTRAN code:
A subroutine for computing multivariate normal probabilities.
This subroutine uses an algorithm given in the paper
"Numerical Computation of Multivariate Normal Probabilities", in
J. of Computational and Graphical Stat., 1(1992), pp. 141-149, by
Alan Genz
Department of Mathematics
Washington State University
Pullman, WA 99164-3113
Email : AlanGenz@wsu.edu
Parameters N INTEGER, the number of variables.
LOWER REAL, array of lower integration limits.
UPPER REAL, array of upper integration limits.
INFIN INTEGER, array of integration limits flags:
if INFIN(I) < 0, Ith limits are (-infinity, infinity);
if INFIN(I) = 0, Ith limits are (-infinity, UPPER(I)];
if INFIN(I) = 1, Ith limits are [LOWER(I), infinity);
if INFIN(I) = 2, Ith limits are [LOWER(I), UPPER(I)].
CORREL REAL, array of correlation coefficients; the correlation
coefficient in row I column J of the correlation matrix
should be stored in CORREL( J + ((I-2)*(I-1))/2 ), for J < I.
THe correlation matrix must be positive semidefinite.
MAXPTS INTEGER, maximum number of function values allowed. This
parameter can be used to limit the time. A sensible
strategy is to start with MAXPTS = 1000*N, and then
increase MAXPTS if ERROR is too large.
ABSEPS REAL absolute error tolerance.
RELEPS REAL relative error tolerance.
ERROR REAL estimated absolute error, with 99% confidence level.
VALUE REAL estimated value for the integral
INFORM INTEGER, termination status parameter:
if INFORM = 0, normal completion with ERROR < EPS;
if INFORM = 1, completion with ERROR >EPS and MAXPTS
function vaules used; increase MAXPTS to
decrease ERROR;
if INFORM = 2, N >100 or N < 1.

Author:
kutsyy

Field Summary
private  double[] a
          Used internaly, see original FORTRAN code for details
private  double abseps
          Used internaly, see original FORTRAN code for details
private  double[] b
          Used internaly, see original FORTRAN code for details
private  int[][] c
          Used internaly, see original FORTRAN code for details
private  double[] correl
          Used internaly, see original FORTRAN code for details
private  double[] cov
          Used internaly, see original FORTRAN code for details
private  double[] d
          Used internaly, see original FORTRAN code for details
private  double[] e
          Used internaly, see original FORTRAN code for details
 double error
          Output : error of the estimator
private  int hisum
          Used internaly, see original FORTRAN code for details
private  int[] infi
          Used internaly, see original FORTRAN code for details
private  int[] infin
          Used internaly, see original FORTRAN code for details
private  int[] infis
          Used internaly, see original FORTRAN code for details
 int inform
          Output: code of the computation (see description)
private  double[] lower
          Used internaly, see original FORTRAN code for details
 int maxpts
          Input: number of itteration
private  int n
          Used internaly, see original FORTRAN code for details
private  int[] N
          Used internaly, see original FORTRAN code for details
private  int nl
          Used internaly, see original FORTRAN code for details
private  int np
          Used internaly, see original FORTRAN code for details
private  double olds
          Used internaly, see original FORTRAN code for details
private  int[] p
          Used internaly, see original FORTRAN code for details
private  double[] prime
          Used internaly, see original FORTRAN code for details
private  double[] psqt
          Used internaly, see original FORTRAN code for details
 double releps
          Input: relative error
private  MersenneTwister rnd
          Random Number Generator (faster than Java's build in)
 boolean running
          Description of the Field
private  int sampls
          Used internaly, see original FORTRAN code for details
private  double[] sd
          Used internaly, see original FORTRAN code for details
private  double[] upper
          Used internaly, see original FORTRAN code for details
 double value
          Output: value of the integral
private  double varest
          Used internaly, see original FORTRAN code for details
 
Constructor Summary
Mvndstpack()
          Empty constructor
Mvndstpack(double[] Lower, double[] Upper, double[][] Cor, int Maxpts, double Abseps, double Releps)
          Constructor
Mvndstpack(double[] Lower, double[] Upper, double[] Correl, int Maxpts, double Abseps, double Releps)
          Constructor
Mvndstpack(double[] Lower, double[] Upper, int[] Infin, double[][] Cor, int Maxpts, double Abseps, double Releps)
          Constructor
Mvndstpack(double[] Lower, double[] Upper, int[] Infin, double[] Correl, int Maxpts, double Abseps, double Releps)
          Constructor
 
Method Summary
private  void compute()
          Same as run
private  void cor2to1(double[][] cor2)
          Insert the method's description here.
private  void covsrt(double[] y, int[] infis)
          Used internaly, see original FORTRAN code for details
private  void dkbvrc(int ndim, int minvls, int maxvls)
          Discription from FORTRAN code:
Automatic Multidimensional Integration Subroutine AUTHOR: Alan Genz Department of Mathematics Washington State University Pulman, WA 99164-3113 Email: AlanGenz@wsu.edu Last Change: 5/15/98 KRBVRC computes an approximation to the integral 1 1 1 I I ...
private  void dkrcht(int s, double[] quasi)
          This subroutine generates a new quasi-random Richtmeyer vector.
private  void dkrcht(int s, double[] quasi, int start)
          This subroutine generates a new quasi-random Richtmeyer vector.
private  void dksmrc(int ndim, int klim, int prime, double[] vk, double[] x)
          Used internaly, see original FORTRAN code for details
private  void dkswap(double[] x, int i, int j)
          Swap i and j element od x
private  void dkswap(int[] x, int i, int j)
          Swap i and j element od x
private  double functn(int ndim, double[] x)
          same as mvndfn(int, double[])
private  double mvndfn(int n, double[] w)
          Insert the method's description here.
private  double mvndnt(int[] infis, double[] d, double[] e)
          Used internaly, see original FORTRAN code for details
private  void mvndst()
          Used internaly, see original FORTRAN code for details
 void Mvndstpack(double[] Lower, double[] Upper, int[] Infin, double[][] Cov, int Maxpts, double Abseps, double Releps)
          main method
 void Mvndstpack(double[] Lower, double[] Upper, int[] Infin, double[] Correl, int Maxpts, double Abseps, double Releps)
          main method
private  void mvnlms(double a, double b, int infin, double[] lower, double[] upper)
          Used internaly, see original FORTRAN code for details
private  void rcswp(int p, int q)
          Swaps rows and columns P and Q in situ, with P <= Q.
 void run()
          To actualy re compute.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

running

public boolean running
Description of the Field

error

public double error
Output : error of the estimator

inform

public int inform
Output: code of the computation (see description)

value

public double value
Output: value of the integral

releps

public double releps
Input: relative error

maxpts

public int maxpts
Input: number of itteration

lower

private double[] lower
Used internaly, see original FORTRAN code for details

sd

private double[] sd
Used internaly, see original FORTRAN code for details

upper

private double[] upper
Used internaly, see original FORTRAN code for details

infin

private int[] infin
Used internaly, see original FORTRAN code for details

correl

private double[] correl
Used internaly, see original FORTRAN code for details

abseps

private double abseps
Used internaly, see original FORTRAN code for details

nl

private int nl
Used internaly, see original FORTRAN code for details

cov

private double[] cov
Used internaly, see original FORTRAN code for details

a

private double[] a
Used internaly, see original FORTRAN code for details

b

private double[] b
Used internaly, see original FORTRAN code for details

infi

private int[] infi
Used internaly, see original FORTRAN code for details

n

private int n
Used internaly, see original FORTRAN code for details

c

private final int[][] c
Used internaly, see original FORTRAN code for details

hisum

private int hisum
Used internaly, see original FORTRAN code for details

np

private int np
Used internaly, see original FORTRAN code for details

olds

private double olds
Used internaly, see original FORTRAN code for details

p

private final int[] p
Used internaly, see original FORTRAN code for details

prime

private final double[] prime
Used internaly, see original FORTRAN code for details

psqt

private double[] psqt
Used internaly, see original FORTRAN code for details

sampls

private int sampls
Used internaly, see original FORTRAN code for details

varest

private double varest
Used internaly, see original FORTRAN code for details

infis

private int[] infis
Used internaly, see original FORTRAN code for details

e

private double[] e
Used internaly, see original FORTRAN code for details

d

private double[] d
Used internaly, see original FORTRAN code for details

rnd

private MersenneTwister rnd
Random Number Generator (faster than Java's build in)

N

private int[] N
Used internaly, see original FORTRAN code for details
Constructor Detail

Mvndstpack

public Mvndstpack(double[] Lower,
                  double[] Upper,
                  double[][] Cor,
                  int Maxpts,
                  double Abseps,
                  double Releps)
Constructor
Parameters:
Lower - Lower limit of integration
Upper - Upper limit of integration
Cor - Covariance matrix
Maxpts - maximum number of itteration
Abseps - absolute error
Releps - relative arror

Mvndstpack

public Mvndstpack(double[] Lower,
                  double[] Upper,
                  double[] Correl,
                  int Maxpts,
                  double Abseps,
                  double Releps)
Constructor
Parameters:
Lower - Lower limit of integration
Upper - Upper limit of integration
Maxpts - maximum number of itteration
Abseps - absolute error
Releps - relative arror
Correl - Description of Parameter

Mvndstpack

public Mvndstpack(double[] Lower,
                  double[] Upper,
                  int[] Infin,
                  double[][] Cor,
                  int Maxpts,
                  double Abseps,
                  double Releps)
Constructor
Parameters:
Lower - Lower limit of integration
Upper - Upper limit of integration
Cor - Covariance matrix
Infin - as above
Maxpts - maximum number of itteration
Abseps - absolute error
Releps - relative arror

Mvndstpack

public Mvndstpack()
Empty constructor

Mvndstpack

public Mvndstpack(double[] Lower,
                  double[] Upper,
                  int[] Infin,
                  double[] Correl,
                  int Maxpts,
                  double Abseps,
                  double Releps)
Constructor
Parameters:
Lower - Lower limit of integration
Upper - Upper limit of integration
Correl - Covariance matrix
Infin - as above
Maxpts - maximum number of itteration
Abseps - absolute error
Releps - relative arror
Method Detail

Mvndstpack

public void Mvndstpack(double[] Lower,
                       double[] Upper,
                       int[] Infin,
                       double[][] Cov,
                       int Maxpts,
                       double Abseps,
                       double Releps)
main method
Parameters:
Lower - Lower limit of integration
Upper - Upper limit of integration
Infin - as above
Maxpts - maximum number of itteration
Abseps - absolute error
Releps - relative arror
Cov - Description of Parameter

Mvndstpack

public void Mvndstpack(double[] Lower,
                       double[] Upper,
                       int[] Infin,
                       double[] Correl,
                       int Maxpts,
                       double Abseps,
                       double Releps)
main method
Parameters:
Lower - Lower limit of integration
Upper - Upper limit of integration
Correl - Covariance matrix
Infin - as above
Maxpts - maximum number of itteration
Abseps - absolute error
Releps - relative arror

run

public void run()
To actualy re compute.

compute

private void compute()
Same as run
See Also:
run()

dkbvrc

private void dkbvrc(int ndim,
                    int minvls,
                    int maxvls)
Discription from FORTRAN code:
Automatic Multidimensional Integration Subroutine AUTHOR: Alan Genz Department of Mathematics Washington State University Pulman, WA 99164-3113 Email: AlanGenz@wsu.edu Last Change: 5/15/98 KRBVRC computes an approximation to the integral 1 1 1 I I ... I F(X) dx(NDIM)...dx(2)dx(1) 0 0 0 DKBVRC uses randomized Korobov rules for the first 20 variables. The primary references are "Randomization of Number Theoretic Methods for Multiple Integration" R. Cranley and T.N.L. Patterson, SIAM J Numer Anal, 13, pp. 904-14, and "Optimal Parameters for Multidimensional Integration", P. Keast, SIAM J Numer Anal, 10, pp.831-838. If there are more than 20 variables, the remaining variables are integrated using Richtmeyer rules. A reference is "Methods of Numerical Integration", P.J. Davis and P. Rabinowitz, Academic Press, 1984, pp. 482-483. Parameters Input parameters NDIM Number of variables, must exceed 1, but not exceed 40 MINVLS Integer minimum number of function evaluations allowed. MINVLS must not exceed MAXVLS. If MINVLS < 0 then the routine assumes a previous call has been made with the same integrand and continues that calculation. MAXVLS Integer maximum number of function evaluations allowed. FUNCTN EXTERNALly declared user defined function to be integrated. It must have parameters (NDIM,Z), where Z is a real array of dimension NDIM. ABSEPS Required absolute accuracy. RELEPS Required relative accuracy. Output parameters MINVLS Actual number of function evaluations used. ABSERR Estimated absolute accuracy of FINEST. FINEST Estimated value of integral. INFORM INFORM = 0 for normal exit, when ABSERR <= MAX(ABSEPS, RELEPS*ABS(FINEST)) and INTVLS <= MAXCLS. INFORM = 1 If MAXVLS was too small to obtain the required accuracy. In this case a value FINEST is returned with estimated absolute accuracy ABSERR. Creation date: (10/11/2000 2:43:21 AM)
Parameters:
ndim - int
minvls - int[]
maxvls - int

mvndst

private void mvndst()
Used internaly, see original FORTRAN code for details

covsrt

private void covsrt(double[] y,
                    int[] infis)
Used internaly, see original FORTRAN code for details
Parameters:
y - double[]
infis - int[]

dkrcht

private void dkrcht(int s,
                    double[] quasi)
This subroutine generates a new quasi-random Richtmeyer vector. A reference is "Methods of Numerical Integration", P.J. Davis and P. Rabinowitz, Academic Press, 1984, pp. 482-483. INPUTS: S - the number of dimensions; KRRCHT is initialized for each new S or S < 1. OUTPUTS: QUASI - a new quasi-random S-vector Creation date: (10/11/2000 11:20:54 AM)
Parameters:
s - double
quasi - double[]

dkrcht

private void dkrcht(int s,
                    double[] quasi,
                    int start)
This subroutine generates a new quasi-random Richtmeyer vector. A reference is "Methods of Numerical Integration", P.J. Davis and P. Rabinowitz, Academic Press, 1984, pp. 482-483. INPUTS: S - the number of dimensions; KRRCHT is initialized for each new S or S < 1. OUTPUTS: QUASI - a new quasi-random S-vector Creation date: (10/11/2000 11:20:54 AM)
Parameters:
s - double
quasi - double[]
start - Description of Parameter

dksmrc

private void dksmrc(int ndim,
                    int klim,
                    int prime,
                    double[] vk,
                    double[] x)
Used internaly, see original FORTRAN code for details
Parameters:
ndim - int
klim - int
prime - int
vk - double[]
x - double[]

dkswap

private void dkswap(double[] x,
                    int i,
                    int j)
Swap i and j element od x
Parameters:
x - double[]
i - int
j - int

dkswap

private void dkswap(int[] x,
                    int i,
                    int j)
Swap i and j element od x
Parameters:
x - int[]
i - int
j - int

functn

private double functn(int ndim,
                      double[] x)
same as mvndfn(int, double[])
Parameters:
ndim - int
x - double[]
Returns:
double
See Also:
mvndfn(int, double[])

mvndfn

private double mvndfn(int n,
                      double[] w)
Insert the method's description here. Creation date: (10/10/2000 10:50:14 PM)
Parameters:
n - int
w - double[]
Returns:
double

mvndnt

private double mvndnt(int[] infis,
                      double[] d,
                      double[] e)
Used internaly, see original FORTRAN code for details
Parameters:
infis - int[]
d - double[]
e - double[]
Returns:
double[]

mvnlms

private void mvnlms(double a,
                    double b,
                    int infin,
                    double[] lower,
                    double[] upper)
Used internaly, see original FORTRAN code for details
Parameters:
a - double
b - double
infin - int
lower - double[]
upper - double[]

rcswp

private void rcswp(int p,
                   int q)
Swaps rows and columns P and Q in situ, with P <= Q. Creation date: (10/12/2000 12:36:03 AM)
Parameters:
p - int
q - int

cor2to1

private void cor2to1(double[][] cor2)
Insert the method's description here. Creation date: (10/10/2000 6:47:53 PM) Transform 2 dimentional matric in to 1 dimentional
Parameters:
cor2 - Description of Parameter