Statistical computing with Breeze

Generating vectors and matrices of random values from a specified distribution is a very common task in most kinds of simulation software. The statistics-related stuff in Breeze is kept in the breeze.stats.distributions package. Before doing anything, we will need to import it:

scala> import breeze.stats.distributions._
import breeze.stats.distributions._

Now, to fill a vector with uniformly distributed values in the interval [0, 1], you can use the Uniform distribution:

scala> val u = Uniform(0.0, 1.0)
u: breeze.stats.distributions.Uniform = Uniform(0.0,1.0)

To draw a sample from a distribution, you use the sample method. You can specify the number of samples to draw. In which case, a vector will be returned: ...

Get Scientific Computing with Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.