简体   繁体   English

Java中的矩阵乘法

[英]Matrix multiplication in java

I wanted to do matrix multiplication in Java, and the speed needs to be very good. 我想用Java进行矩阵乘法,并且速度必须非常好。

I was thinking of calling R through java to achieve this. 我当时想通过Java调用R来实现这一点。

I had a couple of Qs though: 我有几个问题:

  1. Is calling R using Java a good idea? 使用Java调用R是个好主意吗? 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? 在Java中可以考虑采用其他哪些方法进行矩阵乘法?

Update: 更新:

My colleague who quit the firm was a C# programmer, who was forced to write Java code that involved matrix multiplication. 我辞职的同事是C#程序员,他被迫编写涉及矩阵乘法的Java代码。

-- He has written his own DataTable class in Java, in order to be able to -他已经用Java编写了自己的DataTable类,以便能够

a) create indexes to sort and join with other DataTables a)创建索引以对其他DataTable进行排序和联接

b) matrix multiplication. b)矩阵乘法。

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. 因此,我想从本质上清理代码,并认为在Java中使用类似R的东西将帮助我专注于业务逻辑,而不是排序,联接,矩阵乘法等。

您可以使用矩阵包,例如JAMA

There are several stackoverflow questions on using R with Java. 关于将R与Java结合使用,有一些stackoverflow问题。 This is simple with JRI . 使用JRI很简单。 See this question for an example: R from within Java . 参见以下示例示例: Java中的R。 Once you have integrated your code, doing the matrix multiplication in R is trivial. 集成代码后,在R中执行矩阵乘法就很简单了。 If you have two matrices, a and b , you would simply call: a %*% b . 如果您有两个矩阵ab ,则只需调用: 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 . 如果您希望使用纯Java并使用数学库,也可以考虑使用Colt (从JAMA改编而成),尽管直接使用JAMA可能会更好。

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. 另一个选择是使用Clojure的Incanter (除其他功能外,它提供了Parallel Colt的包装),然后从Java称为Jar。 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. 将Clojure集成到Java中很简单,如果只需要矩阵乘法,那将比使用R更容易。

Another vote for jblas . jblas再次投票。 all the methods are like you'd expect them to be. 所有方法都像您期望的那样。

EJML seems to be a promising new one for fast multiplication. EJML似乎是一种有前途的快速乘法新方法。 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 . 并行colt是执行矩阵运算的有效库。

Other good matrix libraries would include jblas and ujmp 其他好的矩阵库将包括jblasujmp

All of these packages are effective. 所有这些软件包都是有效的。 jblas is my personal favourite . jblas是我个人的最爱。 It has good documentation and straight forward unlike ujmp 与ujmp不同,它具有良好的文档和直接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM