Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java matrix libraries [closed]

Tags:

java

matrix

colt

I was wondering whether any of the well-known matrix libraries for Java, such as Colt or EJML, actually provide similar functionality as MatLab? For instance, I can't seem to find anywhere in the definition of their API simple method to add or subtract two matrices/vectors by each other, which seems to be the most common operation used. Am I missing something?

like image 855
Bober02 Avatar asked May 30 '12 11:05

Bober02


People also ask

How do you represent a matrix in Java?

Fig 1: A simple 4x4 matrix In order to represent this matrix in Java, we can use a 2 Dimensional Array. A 2D Array takes 2 dimensions, one for the row and one for the column. For example, if you specify an integer array int arr[4][4] then it means the matrix will have 4 rows and 4 columns.

How do you do scalar multiplication in Java?

EDIT The question is this: Scalar multiplication is defined as B = A * s, where B and A are equally sized matrices (2D array of numbers, in this example let's use integers) and s is a scalar value. Each element of A is multiplied to s, which is then stored in the corresponding element in matrix B.


3 Answers

Some Java libraries for linear algebra are:

  • Apache Commons Math: http://commons.apache.org/proper/commons-math/
  • jeigen - a wrapper for eigen - https://github.com/hughperkins/jeigen (includes complex and rarely found feature like matrix exponential and matrix logarithm)
  • jblas http://mikiobraun.github.io/jblas/ (also features more complex functions like matrix exponential, also very fast).
  • Colt http://acs.lbl.gov/software/colt/
  • JAMA http://math.nist.gov/javanumerics/jama/
  • UJMP - http://sourceforge.net/projects/ujmp/

EDIT maybe we can extend this list whenever one comes across and you know - the world keeps moving:

  • ojAlgo - http://ojalgo.org/ has promising benchmarks
  • Efficient Java Matrix Library (EJML) - http://ejml.org
  • ParallelColt - https://sites.google.com/site/piotrwendykier/software/parallelcolt
  • la4j - http://la4j.org/
  • MTJ - https://github.com/fommil/matrix-toolkits-java
  • nd4j - https://nd4j.org/ lets you choose underlying native implementations like cuda or openBlas

Note: Personally: I use Apache Commons Math and Colt in my own project (http://www.finmath.net). While commons math is actively developed, I found that Colt is still faster in some tasks (like Eigenvalue decomposition). For that reason I use some kind of wrapper which allows me to quickly switch the underlying library (I only need a few things like solving systems of equations and Eigenvalue decomposition).

like image 150
Christian Fries Avatar answered Oct 15 '22 02:10

Christian Fries


Try Apache Commons Math library. org.apache.commons.math3.linear package contains the functions that you want. Home page

like image 32
Thinesh Ganeshalingam Avatar answered Oct 15 '22 01:10

Thinesh Ganeshalingam


The interface for COLT gives you a generic OP: assign(matrix, function), which you can use to add or subtract matrices and vectors.

As the javadocs for assign() says:

Assigns the result of a function to each cell; x[row,col] =function(x[row,col],y[row,col]).

So by using using an addition function as function - you can add matrices.

like image 2
amit Avatar answered Oct 15 '22 02:10

amit