scalanlp / breeze

Breeze is a numerical processing library for Scala.
www.scalanlp.org
Apache License 2.0
3.44k stars 691 forks source link

how to generate an n dim Gassian Distribution? #827

Closed zsk66 closed 2 years ago

SheperoMah commented 2 years ago

` import breeze.linalg.{DenseVector, DenseMatrix} import breeze.stats.distributions.RandBasis import breeze.stats.distributions.MultivariateGaussian

// Choose the random number generator. Check RandBasis' documentation if you want to know more. implicit val rand: RandBasis = RandBasis.systemSeed

// Define the parameters of the multivariate Gaussian distribution val mean = DenseVector(0.1, 2.0) val covariance = DenseMatrix(Array(0.3, 0.1), Array(0.1, 0.8))

// Create a distribution with these parameters. val myDist = MultivariateGaussian(mean, covariance)

// Sample from the distribution. val rndSamples = myDist.sample(n=1000) `

dlwh commented 2 years ago

Thanks @SheperoMah

zsk66 commented 2 years ago

Wow!!, I am so glad to see this code, this problem made me very crazy in these days. Finallu, I used spark.Mllib to generate the random numbers, but it is so difficult and troublesome. Thank you so much !!!!!