Using Breeze from Java on Spark MLlib

1.7k Views Asked by At

While trying to use MLlib from Java, what is the correct way to use breeze Matrix operations? For e.g. multiplication in scala it ist simply "matrix * vector". How is the corresponding functionality expressed in Java?

There are methods like "$colon$times" which might be invoked by the correct way

breeze.linalg.DenseMatrix<Double> matrix= ...
breeze.linalg.DenseVector<Double> vector = ...  

matrix.$colon$times( ...

one might need an operator instance ... breeze.linalg.operators.OpMulMatrix.Impl2 But which exact typed Operation instance and parameters are to be used?

2

There are 2 best solutions below

1
On

It's honestly very hard. Breeze makes very very heavy use of implicits, and they just don't translate well into Java. We have some Java friendly wrappers for signal processing, but nothing for linear algebra. (I'd happily take a pull request that provided some support for wrapping things.)

0
On

Have a look at https://spark.apache.org/docs/2.2.0/api/java/org/apache/spark/mllib/linalg/BLAS.html, which contains many of the BLAS linear algebra operations. These can be used by both Scala and Java.