Class GaussianRVs

java.lang.Object
org.bzdev.math.rv.GaussianRVs

public class GaussianRVs extends Object
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 Details

    • GaussianRVs

      public GaussianRVs(CovarianceMatrix cov)
      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 created
      means - 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 variables
      n - 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 method next(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 include Spliterator.SIZED or Spliterator.SUBSIZED. The default value is Spliterator.IMMUTABLE | Spliterator.NONNULL. If the characteristics include Spliterator.ORDERED, Spliterator.trySplit() will return null.
      Returns:
      the characteristics
    • spliterator

      public Spliterator<double[]> spliterator(long size)
      Get a spliterator for a specified number of values.
      Parameters:
      size - the number of random values to provide
      Returns:
      the spliterator
    • spliterator

      public Spliterator<double[]> spliterator()
      Get a spliterator for an infinite number of values.
      Returns:
      the spliterator
    • stream

      public Stream<double[]> stream(long size)
      Get a fixed-length stream of double-valued arrays.
      Parameters:
      size - the number of random values to provide
      Returns:
      the stream
    • parallelStream

      public Stream<double[]> parallelStream(long size)
      Get a fixed-length parallel stream of double-valued arrays.
      Parameters:
      size - the number of random values to provide
      Returns:
      the stream
    • stream

      public Stream<double[]> stream()
      Get an infinie stream of double-valued arrays.
      Returns:
      the stream
    • parallelStream

      public Stream<double[]> parallelStream()
      Get an infinie parallel stream of double-valued arrays.
      Returns:
      the stream