开发者

Matrix multiplication in java

I wanted to do matrix multiplication in Java, and the speed needs to be very good.

I was thinking of calling R through java to achieve this.

I had a couple of Qs though:

  1. Is calling R using Java 开发者_运维知识库a good idea? If yes, are there any code samples that can be shared?

  2. What are the other ways that can be considered to do matrix multiplication in Java?

Update:

My colleague who quit the firm was a C# programmer, who was forced to write Java code that involved matrix multiplication.

-- He has written his own DataTable class in Java, in order to be able to

a) create indexes to sort and join with other DataTables

b) matrix multiplication.

So, I want to essentially clean up the code, and thought using something like R within Java will help me focus on business logic rather than sorting, joining, matrix multiplication, etc.


You could use a matrix package such as JAMA.


There are several stackoverflow questions on using R with Java. This is simple with JRI. See this question for an example: R from within Java. Once you have integrated your code, doing the matrix multiplication in R is trivial. If you have two matrices, a and b, you would simply call: a %*% b.

If you want to stay in pure Java and work with a mathematics library, you can also look into using Colt (which is adapted from JAMA), although you could be better off just using JAMA directly.

Another option would be to use Incanter from Clojure (which provides a wrapper around Parallel Colt, amongst other things), and then call it as a Jar from Java. It's trivial to integrate Clojure into Java, and if all you want is matrix multiplication, that will be easier for you than using R.


EJML seems to be a promising new one for fast multiplication. They have benchmarks on their site to show what they claim to be fast times for matrix multiplication.


Parallel colt is an effective library to perform matrix operations .

Other good matrix libraries would include jblas and ujmp

All of these packages are effective. jblas is my personal favourite . It has good documentation and straight forward unlike ujmp


Another vote for jblas. all the methods are like you'd expect them to be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜