Matrix multiplication in java - 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:
Is calling R using Java a good idea? If yes, are there any code samples that can be shared?
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.

Related

Function Point Estimation

Since we have so many languages to use for programming to create a software product, and every language has its own pros and cons. While thinking on how to choose a language, a friend suggested to loop for the cheapest cost a language creates as judged by the lines of code method used for estimation. I was wondering how many lines of Java code and how many lines of Python code each FP incurs ?
You should assume a probability model. This might be helpful: https://www.cs.uoregon.edu/Classes/13W/cis472/slides/estimation-2pp.pdf
In terms of implementation, you can use scikit-learn and scikit-stats libraries in Python, where you are able to implement most statistical methods in a few lines of code.
I found the answer to my question in this pdf. http://namcookanalytics.com/wp-content/uploads/2013/07/Function-Points-as-a-Universal-Software-Metric2013.pdf

How to calculate eigenvalues without using external packages

I'm trying to create an application in java which does several matrix modifications like calculating the invereses and determinants.
Now I would also like to include the option for the application to calculate the eigenvalues and the eigenvectors for matrices.
Since the only 'solid' way to calculate eigenvalues, by my knowledge, is by using the characteristic formula given by:
det(A-λI) = 0
Where A is an nxn matrix and λ a real number.
To my knowledge, there is no simple, maybe none at all, way to use algebra in Java. Also I would like to program this myself, so I would like not to use external packages like Jama or others.
Can someone explain me how I can program this equation in Java or maybe tell me another way of doing it?
One way you could do it is have a look at Jama and see how it is calculated in there and interpret that. And don't just Copy and Paste :P we all know who tempting that can be.
Finding eigenvalues and eigenvectors is a bit tricky, and there are many algorithms with varying positives and negatives. I'll suggest a few that are quite good and that are not that difficult to implement.
First, compute the characteristic polynomial and then find the roots using. Then you have the eigenvalues. Then you can solve a set of equations to find the eigenvectors given the eigenvalues.

Is there a library for quaternions and matrices with all the standard operations?

is there a java library which can handle quaternions and matrices (quaternion matrix multiplication) with all the standard operations?
(i searched google and here before - but didnt find any adequate solution)
The Jave3D javax.vecmath package has quaternions support (Quat4D) and quite a lot of the most common operations are supported. It also has matrix operations that can be applied to quaternions.
You will probably find that it fits most of your needs - and it should not be too hard to add any additional operations if you need them.
There is also JME3's Quaternion. JME3 classes' interface and javadoc is substandard. Also it uses float precision everywhere. I would only use it if performance is an issue, for example in a game.
Apache has Quaternion support in org.apache.commons.math3.complex.
It seems to have the usual required operations.

I need a Java solver Library work as optimization with the Excel Solver tool

I just started using Java for building models doing some analysis on PV modules.
I am currently writing a class for a PV module, single diode model. I need to use a few points of data such as 'f(current)=voltage' to be able to find all the factors in the equation.
Excel does have this function, called 'optimization with the Excel Solver tool'.
Is there any good library highly recommended for this function? I have tried 'Choco solver' however it does not support many mathematics function for the constraint. e.g it does not allow you to use a/b, when a or b is a double.
I would be really grateful if anyone could give me a hand on this.
Try free JSR-331"Java Constraint Programming API" http://openrules.com/jsr331. You may also want to check out http://openrules.com/rulesolver.htm
You can use the one from Solver (but its not free)
http://www.solver.com/solver-tools-for-developers.htm

java jama array problem

I asked a question before but duffymo said it is not clear so i am going to post it again here.
I am using Jama api for SVD calculation. I know very well about jama and SVD.
Jama does not work if your column are more than rows. I have this situation. What should I do?? any help?
I can't transpose the matrix too as it can produce wrong results.
Thanks.
P.S: I am calculating LSI with the help of jama. I am going like column(docs) and rows ( terms )
Why not use transpose? If X = USV', then X' = VS'U'. Right?
Transpose your matrix. Get U, S and V. Transpose everything back.
If I understand correctly you are trying to compute the SVD of a matrix which is not square, and you have the library JAMA which only works on square matrices? If I have understood you correctly then the answer to your question is obvious: Get a library which does compute SVD for non-square matrices. If I remember correctly Numerical Recipes contains such an algorithm, I expect you can find many other sources with Google.
Since you're doing LSI, you could use SVDLIBJ, which is the Java equivalent of SVDLIBC, which is one of the most scalable SVD implementations that is freely available. The S-Space package has a command-line tool for SVDLIBJ set up already. Also, you can use their Matrix libraries and avoid the command-line if that fits your needs better.
I now it is a really late reply . But i thought it is better late than never
But i am aware that jblas performs svd in a effective manner.

Categories

Resources