java.lang.Object
org.bzdev.math.rv.GaussianRVs
Create a correlated set of Gaussian random variables.
This class provides a method
next(double[])
that sets n elements of an array to correlated random values
with specified means.
The covariance matrix's rows and columns use the same order as
used in the array that is set.
Given a covariance matrix cov and a vector means containing the
mean values, calling next(double[])
will
create a sequence of vectors, all with the same length, such
that (after a very large number of iterations)
- the mean value of the ith element of each vector will be the ith element in the factor passed to the constructor.
- the covariance matrix for the vectors produced will be equal to the covariance matrix used by the constructor.
This class is useful for Monte Carlo models or simulations when random numbers are not mutually independent.
-
Constructor Summary
ConstructorsConstructorDescriptionGaussianRVs
(double[][] cov, double[] means) Constructor, specifying the covariance matrix by a two-dimensional array.GaussianRVs
(double[][] cov, double[] means, int n) Constructor specifying the matrix size.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Spliterator characteristics.int
length()
Get the number of values that will be provided when the methodnext(double[])
is called.double[]
next()
Get the next array of values.double[]
next
(double[] values) Get the next array of values, storing them in an arrayStream<double[]>
Get an infinie parallel stream of double-valued arrays.Stream<double[]>
parallelStream
(long size) Get a fixed-length parallel stream of double-valued arrays.Spliterator<double[]>
Get a spliterator for an infinite number of values.Spliterator<double[]>
spliterator
(long size) Get a spliterator for a specified number of values.Stream<double[]>
stream()
Get an infinie stream of double-valued arrays.Stream<double[]>
stream
(long size) Get a fixed-length stream of double-valued arrays.
-
Constructor Details
-
GaussianRVs
Constructor. The random variables will have the the specified covariance matrix with mean values equal to 0.- Parameters:
cov
- the covariance matrix.
-
GaussianRVs
public GaussianRVs(double[][] cov, double[] means) Constructor, specifying the covariance matrix by a two-dimensional array.- Parameters:
cov
- the covariance matrix for the set of random variables to be createdmeans
- the mean values for each of the set of random variables
-
GaussianRVs
public GaussianRVs(double[][] cov, double[] means, int n) Constructor specifying the matrix size. The first n rows and columns of the covariance matrix, and the first n elements of the means array will be used.- Parameters:
cov
- the covariance matrix for the set of random variables to be created.means
- the mean values for each of the set of random variablesn
- the number of rows and columns of cov and mean that are used
-
-
Method Details
-
length
public int length()Get the number of values that will be provided when the methodnext(double[])
is called.- Returns:
- the number of values that will be provided when
next(double[])
is called
-
next
public double[] next(double[] values) Get the next array of values, storing them in an array- Parameters:
values
- an array to hold the results- Returns:
- the argument array
-
next
public double[] next()Get the next array of values.- Returns:
- an array holding the next values
-
getCharacteristics
protected int getCharacteristics()Spliterator characteristics. The characteristics returned should not includeSpliterator.SIZED
orSpliterator.SUBSIZED
. The default value isSpliterator.IMMUTABLE
|Spliterator.NONNULL
. If the characteristics includeSpliterator.ORDERED
,Spliterator.trySplit()
will return null.- Returns:
- the characteristics
-
spliterator
Get a spliterator for a specified number of values.- Parameters:
size
- the number of random values to provide- Returns:
- the spliterator
-
spliterator
Get a spliterator for an infinite number of values.- Returns:
- the spliterator
-
stream
Get a fixed-length stream of double-valued arrays.- Parameters:
size
- the number of random values to provide- Returns:
- the stream
-
parallelStream
Get a fixed-length parallel stream of double-valued arrays.- Parameters:
size
- the number of random values to provide- Returns:
- the stream
-
stream
Get an infinie stream of double-valued arrays.- Returns:
- the stream
-
parallelStream
Get an infinie parallel stream of double-valued arrays.- Returns:
- the stream
-