Normal multivariate distributions defined by a covariance
Code: "random_norma1.py". Programming language: Python
DMelt Version 1.4. Last modified: 01/17/2019. License: Pro
https://datamelt.org/code/cache/random_norma1_2127.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# Generate 10 vectors using two normal (multivariate) distributions.
# Correlations are defined by a covariance matrix.
from org.apache.commons.math3.random import JDKRandomGenerator,GaussianRandomGenerator,CorrelatedRandomVectorGenerator
from org.apache.commons.math3.linear import RealMatrix,MatrixUtils
mean = [1, 2] # Mean of 2 normal distributions
matrix = MatrixUtils.createRealMatrix( [ [9, 3], [3, 16]] ) # covariant matrix
rg =JDKRandomGenerator();
rg.setSeed(2l) # fixed seed (same results)
rawGen= GaussianRandomGenerator(rg)
gen = CorrelatedRandomVectorGenerator(mean, matrix, 1.0e-12 * matrix.getNorm(), rawGen)
for i in range(10):
vec = gen.nextVector()
print vec
You see the box below because you did not login.