java中的矩阵乘法

发布于 2024-08-29 09:49:06 字数 418 浏览 11 评论 0原文

我想用Java进行矩阵乘法,并且速度需要非常好。

我正在考虑通过java调用R来实现这一点。

不过我有几个问题:

  1. 使用 Java 调用 R 是一个好主意吗?如果有的话,有没有可以分享的代码示例?

  2. 在 Java 中还有哪些其他方法可以考虑进行矩阵乘法?

更新:

我退出公司的同事是一名 C# 程序员,他被迫编写涉及矩阵乘法的 Java 代码。

-- 他用 Java 编写了自己的 DataTable 类,以便能够

a) 创建索引以排序并与其他 DataTable 联接

b) 矩阵乘法。

因此,我想从本质上清理代码,并认为在 Java 中使用 R 之类的东西将帮助我专注于业务逻辑,而不是排序、连接、矩阵乘法等。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风透绣罗衣 2024-09-05 09:49:06

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

You could use a matrix package such as JAMA.

小清晰的声音 2024-09-05 09:49:06

stackoverflow 上有几个关于将 R 与 Java 结合使用的问题。使用 JRI 就可以做到这一点。请参阅此问题的示例:R from inside Java。一旦集成了代码,在 R 中进行矩阵乘法就很简单了。如果您有两个矩阵,ab,您只需调用:a %*% b

如果您想继续使用纯 Java 并使用数学库,您还可以考虑使用 Colt(改编自JAMA),尽管您可能会更好 直接使用JAMA

另一种选择是使用 Clojure 中的 Incanter (它提供了 Parallel Colt 等),然后从 Java 中将其称为 Jar。将 Clojure 集成到 Java 中很简单,如果您想要的只是矩阵乘法,那么这对您来说比使用 R 更容易。

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.

染火枫林 2024-09-05 09:49:06

EJML 似乎是一种很有前途的快速乘法新方法。他们的网站上有基准测试,以显示他们声称的矩阵乘法的快速时间。

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.

也只是曾经 2024-09-05 09:49:06

Parallel colt 是一个执行矩阵运算的有效库。

其他好的矩阵库包括 jblasujmp

所有这些包都是有效的。 jblas 是我个人的最爱。与 ujmp 不同,它有很好的文档并且直接

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

旧人九事 2024-09-05 09:49:06

另一次投票给jblas。所有的方法都如您所期望的那样。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文