Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 2.41 KB

Breeze.md

File metadata and controls

33 lines (22 loc) · 2.41 KB

Breeze

Practical exercises

Useful links:

1. Review the on-line documentation

Begin by reading through the quickstart guide and then read through the linear algebra cheat sheet. Then quickly check a few other pages on the Breeze wiki. Finally, have a quick look at the API docs - for example, search the docs for Gamma and see how Breeze parameterises the gamma distribution. Note that the docs are often very terse, so sometimes there's no alternative than to browse the source code. Also, the test code can sometimes be useful for figuring out how to use a Breeze function.

2. Multivariate normal

  • Write a function with type signature
rmvn(n: Int, mean: DenseVector[Double], cov: DenseMatrix[Double]): DenseMatrix[Double]

which returns a matrix with n rows, each row representing an iid draw from a multivariate normal with the given mean and variance matrix. Note that this can be accomplished by post-multiplying a matrix of iid N(0,1) random quantities by the upper Cholesky factor of the variance matrix (on the right), and then adding the mean to each row of the result (don't use the built-in Breeze function for simulating multivariate Gaussians unless you're stuck). Study my PCA example for ideas.

  • How can you test your code to ensure that you have implemented it correctly? See the gamma testing example for clues. Also, breeze.stats.covmat may be of use.

3. Scatter-plot

Write a function with type signature

pairs(mat: DenseMatrix[Double]): Figure

which produces a scatterplot matrix similar to that produced by the pairs() function in R. eg. for a matrix with k columns, the function should plot a k * k array of scatter plots showing each variable against each other. Test your code on some simulated data generated using your rmvn function.

eof