org.jmat.data
Class RandomMatrix

java.lang.Object
  |
  +--org.jmat.data.Matrix
        |
        +--org.jmat.data.RandomMatrix
All Implemented Interfaces:
ClipBoardPrintable, java.lang.Cloneable, CommandLinePrintable, FilePrintable, java.io.Serializable, StringPrintable, XMLPrintable

public class RandomMatrix
extends Matrix

The RandomMatrix Class provides tools for statistical simulations,it extends the Matrix Class and adds many methods.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jmat.data.Matrix
A, m, n
 
Constructor Summary
RandomMatrix(double[] vals, int m)
          Construct a matrix from a one-dimensional packed array
RandomMatrix(int m, int n)
          Construct an m-by-n matrix of 0.
RandomMatrix(Matrix M)
          Construct an m-by-n matrix of 0.
 
Method Summary
static RandomMatrix beta(int m, int n, double a, double b)
          Construct an m-by-n matrix of random numbers from a Beta random variable.
static RandomMatrix cauchy(int m, int n, double mu, double sigma)
          Construct an m-by-n matrix of random numbers from a Cauchy random variable.
 Matrix correlation()
          Generate a correlation matrix, each column contains values of a pulling.
 Matrix covariance()
          Generate a covariance matrix, each column contains values of a pulling.
static RandomMatrix dirac(int m, int n, Matrix val_prob)
          Construct an m-by-n matrix of random numbers from a discrete random variable.
static RandomMatrix exponential(int m, int n, double lambda)
          Construct an m-by-n matrix of random numbers from an exponantial random variable.
 boolean getIsSample()
          Specify if the RandomMatrix is a sample of an overall population, or if it's an overall population.
static RandomMatrix logNormal(int m, int n, double mu, double sigma)
          Construct an m-by-n matrix of random numbers from a LogNormal random variable.
 Matrix mean()
          Generate a row matrix, each column contents the mean value of the columns.
static RandomMatrix normal(int m, int n, double mu, double sigma)
          Construct an m-by-n matrix of random numbers from a Gaussian (Normal) random variable.
static RandomMatrix rejection(int m, int n, DoubleFunction fun, double min, double max)
          Construct an m-by-n matrix of random numbers from a random variable definied by its density function, using the rejection technic. !
static RandomMatrix sampleWithoutReplacement(int m, int n, Matrix B)
          Construct a sample without replacement of a matrix.
static RandomMatrix sampleWithReplacement(int m, int n, Matrix B)
          Construct a sample with replacement of a matrix.
 void setIsSample(boolean is)
          Specify if the RandomMatrix is a sample of an overall population, or if it's an overall population.
 void toHist2DPanel(Plot2DPanel panel, java.lang.String name, int num)
          Print the Matrix in a JPanel.
 Plot2DPanel toHist2DPanel(java.lang.String name, int num)
          Print the Matrix in an histogram in a JPanel.
 void toHist3DPanel(Plot3DPanel panel, java.lang.String name, int num)
          Print the Matrix in a JPanel.
 Plot3DPanel toHist3DPanel(java.lang.String name, int num)
          Print the Matrix in a JPanel.
static RandomMatrix triangular(int m, int n, double min, double max)
          Construct an m-by-n matrix of random numbers from a symetric triangular random variable.
static RandomMatrix triangular(int m, int n, double min, double med, double max)
          Construct an m-by-n matrix of random numbers from a non-symetric triangular random variable.
static RandomMatrix uniform(int m, int n, double min, double max)
          Construct an m-by-n matrix of random numbers from a uniform random variable.
 Matrix variance()
          Generate a variance matrix, each column contains values of a pulling.
static RandomMatrix weibull(int m, int n, double lambda, double c)
          Construct an m-by-n matrix of random numbers from a Weibull random variable.
 
Methods inherited from class org.jmat.data.Matrix
abs, checkColumnDimension, checkColumnDimension, checkDiagonal, checkDimensions, checkDimensions, checkRowDimension, checkRowDimension, checkSymetric, cholesky, clone, condition, copy, cumsum, deleteColumn, deleteColumns, deleteColumns, deleteRow, deleteRows, deleteRows, determinant, diagonal, distance, divide, divide, ebeCos, ebeDivide, ebeDivideEquals, ebeExp, ebeFunction, ebeIndicesFunction, ebeInverse, ebeLog, ebePower, ebePower, ebeSin, ebeSqrt, ebeTimes, ebeTimesEquals, eig, find, find, fromASCIIFile, fromClipBoard, fromString, fromXMLElement, get, getArrayCopy, getColumn, getColumnArrayCopy, getColumnDimension, getColumns, getColumns, getDiagonal, getDiagonal, getRow, getRowArrayCopy, getRowDimension, getRows, getRows, getSubMatrix, identity, incrementColumns, incrementRows, insertColumns, insertRows, inverse, isDiagonal, isEqual, isSymetric, lu, max, mergeColumns, mergeColumns, mergeRows, mergeRows, min, minus, minus, minusEquals, minusEquals, norm1, norm2, normFrobenius, normInfinity, plus, plus, plusEquals, plusEquals, product, qr, random, rank, reshapeColumns, reshapeRows, resize, set, setColumn, setColumn, setColumns, setColumns, setRow, setRow, setRows, setRows, setSubMatrix, setSubMatrix, slice, slice, solve, sort, sum, svd, times, times, timesEquals, toASCIIFile, toClipBoard, toCommandLine, toDouble, toDoubleArray, toPlot2DPanel, toPlot2DPanel, toPlot3DPanel, toPlot3DPanel, toString, toTablePanel, toXMLElement, trace, transpose, transposeEquals, uminus, uminusEquals
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RandomMatrix

public RandomMatrix(int m,
                    int n)
Construct an m-by-n matrix of 0.

Parameters:
m - Number of rows.
n - Number of columns.

RandomMatrix

public RandomMatrix(Matrix M)
Construct an m-by-n matrix of 0.

Parameters:
M - Matrix to construct.

RandomMatrix

public RandomMatrix(double[] vals,
                    int m)
Construct a matrix from a one-dimensional packed array

Parameters:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).
m - Number of rows.
Throws:
java.lang.IllegalArgumentException - Array length must be a multiple of m.
Method Detail

uniform

public static RandomMatrix uniform(int m,
                                   int n,
                                   double min,
                                   double max)
Construct an m-by-n matrix of random numbers from a uniform random variable.

Parameters:
m - Number of rows.
n - Number of columns.
min - Min of the random variable.
max - Max of the random variable.
Returns:
A RandomMatrix.

dirac

public static RandomMatrix dirac(int m,
                                 int n,
                                 Matrix val_prob)
Construct an m-by-n matrix of random numbers from a discrete random variable.

Parameters:
m - Number of rows.
n - Number of columns.
val_prob - Matrix of the discrete value and their probabilities.
Returns:
A RandomMatrix.

normal

public static RandomMatrix normal(int m,
                                  int n,
                                  double mu,
                                  double sigma)
Construct an m-by-n matrix of random numbers from a Gaussian (Normal) random variable.

Parameters:
m - Number of rows.
n - Number of columns.
mu - Mean of the random variable.
sigma - Standard deviation of the random variable.
Returns:
A RandomMatrix.

logNormal

public static RandomMatrix logNormal(int m,
                                     int n,
                                     double mu,
                                     double sigma)
Construct an m-by-n matrix of random numbers from a LogNormal random variable.

Parameters:
m - Number of rows.
n - Number of columns.
mu - Mean of the Normal random variable.
sigma - Standard deviation of the Normal random variable.
Returns:
A RandomMatrix.

exponential

public static RandomMatrix exponential(int m,
                                       int n,
                                       double lambda)
Construct an m-by-n matrix of random numbers from an exponantial random variable.

Parameters:
m - Number of rows.
n - Number of columns.
lambda - Parmaeter of the exponential random variable.
Returns:
A RandomMatrix.

triangular

public static RandomMatrix triangular(int m,
                                      int n,
                                      double min,
                                      double max)
Construct an m-by-n matrix of random numbers from a symetric triangular random variable.

Parameters:
m - Number of rows.
n - Number of columns.
min - Min of the random variable.
max - Max of the random variable.
Returns:
A RandomMatrix.

triangular

public static RandomMatrix triangular(int m,
                                      int n,
                                      double min,
                                      double med,
                                      double max)
Construct an m-by-n matrix of random numbers from a non-symetric triangular random variable.

Parameters:
m - Number of rows.
n - Number of columns.
min - Min of the random variable.
med - Value of the random variable with max density.
max - Max of the random variable.
Returns:
A RandomMatrix.

beta

public static RandomMatrix beta(int m,
                                int n,
                                double a,
                                double b)
Construct an m-by-n matrix of random numbers from a Beta random variable.

Parameters:
m - Number of rows.
n - Number of columns.
a - First parameter of the Beta random variable < 1.
b - Second parameter of the Beta random variable < 1.
Returns:
A RandomMatrix.

cauchy

public static RandomMatrix cauchy(int m,
                                  int n,
                                  double mu,
                                  double sigma)
Construct an m-by-n matrix of random numbers from a Cauchy random variable.

Parameters:
m - Number of rows.
n - Number of columns.
mu - Median of the Weibull random variable
sigma - Second parameter of the Cauchy random variable.
Returns:
A RandomMatrix.

weibull

public static RandomMatrix weibull(int m,
                                   int n,
                                   double lambda,
                                   double c)
Construct an m-by-n matrix of random numbers from a Weibull random variable.

Parameters:
m - Number of rows.
n - Number of columns.
lambda - First parameter of the Weibull random variable.
c - Second parameter of the Weibull random variable.
Returns:
A RandomMatrix.

rejection

public static RandomMatrix rejection(int m,
                                     int n,
                                     DoubleFunction fun,
                                     double min,
                                     double max)
Construct an m-by-n matrix of random numbers from a random variable definied by its density function, using the rejection technic. ! WARNING : this simulation technic can take a very long time !

Parameters:
m - Number of rows.
n - Number of columns.
fun - Density function of the random variable.
min - Min of the random variable.
max - Max of the random variable.
Returns:
A RandomMatrix.

sampleWithReplacement

public static RandomMatrix sampleWithReplacement(int m,
                                                 int n,
                                                 Matrix B)
Construct a sample with replacement of a matrix.

Parameters:
m - Number of rows.
n - Number of columns.
B - Matrix to sample.
Returns:
A RandomMatrix.

sampleWithoutReplacement

public static RandomMatrix sampleWithoutReplacement(int m,
                                                    int n,
                                                    Matrix B)
Construct a sample without replacement of a matrix.

Parameters:
m - Number of rows.
n - Number of columns.
B - Matrix to sample.
Returns:
A RandomMatrix.

setIsSample

public void setIsSample(boolean is)
Specify if the RandomMatrix is a sample of an overall population, or if it's an overall population. This information is needed to calculate unbiaised estimtors of variance for instance.

Parameters:
is - Is sample?.

getIsSample

public boolean getIsSample()
Specify if the RandomMatrix is a sample of an overall population, or if it's an overall population. This information is needed to calculate unbiaised estimtors of variance for instance.

Returns:
is Sample?

mean

public Matrix mean()
Generate a row matrix, each column contents the mean value of the columns.

Overrides:
mean in class Matrix
Returns:
An 1-by-n matrix.

covariance

public Matrix covariance()
Generate a covariance matrix, each column contains values of a pulling.

Overrides:
covariance in class Matrix
Returns:
An n-by-n matrix.

correlation

public Matrix correlation()
Generate a correlation matrix, each column contains values of a pulling.

Overrides:
correlation in class Matrix
Returns:
An n-by-n matrix.

variance

public Matrix variance()
Generate a variance matrix, each column contains values of a pulling.

Overrides:
variance in class Matrix
Returns:
An 1-by-n matrix.

toHist2DPanel

public Plot2DPanel toHist2DPanel(java.lang.String name,
                                 int num)
Print the Matrix in an histogram in a JPanel.

Parameters:
name - name of the plot.
num - number of slices.
Returns:
A JPanel.

toHist3DPanel

public Plot3DPanel toHist3DPanel(java.lang.String name,
                                 int num)
Print the Matrix in a JPanel.

Parameters:
num - number of slices.
name - name of the plot.
Returns:
A JPanel.

toHist2DPanel

public void toHist2DPanel(Plot2DPanel panel,
                          java.lang.String name,
                          int num)
Print the Matrix in a JPanel.

Parameters:
panel - Panel to modify.
name - name of the plot.
num - number of slices.

toHist3DPanel

public void toHist3DPanel(Plot3DPanel panel,
                          java.lang.String name,
                          int num)
Print the Matrix in a JPanel.

Parameters:
panel - Panel to modify.
name - name of the plot.
num - number of slices.