Matrix multiplication in java

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 08:28:19

问题


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.


回答1:


You could use a matrix package such as JAMA.




回答2:


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.




回答3:


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.




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/2658752/matrix-multiplication-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!