java jama array problem - java

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.

Related

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.

How exactly do I use OpenCV and homographies to undo perspective warp?

I need to use Java and OpenCV to do the process shown on http://en.wikipedia.org/wiki/Perspective_control
I know exactly where the 4 points of my trapezoid are, and I just need them to square up. I've heard I need to use a homography and a warpPerspective command, but I don't know what parameters these use. I don't know HOW to employ them, only that I do need to use them. Can anyone fully explain this? I've never done anything like this, so starting from a bare minimum would be awesome. I'd really like to get into the world of computer vision so having someone to help me out is greatly appreciated.
Their are two methods for doing this:
1) Geometric warping where you use perspective geometry to create the H matrix. OR
2) Using feature matches to create that same H matrix.
Opencv has a nice function called findHomography (which is the second method) that takes in 2 arrays. Both arrays should be matching features from the 2 different images.
Once you have the H matrix creating the warped image is also easy and you can just call warpPerspective which you store in a matrix which you then imshow to see.

Java library for creating straight skeleton?

I have as an input a 2D polygon with holes, and I need to find it's straight skeleton, like in the picture:
(source: cgal.org)
Maybe there is a good Java library for it?
And if not, can you point me to the good explanation of the algorithm, so I could implement it myself? (I haven't found good resources on Google)
I wrote this a little while back. Not sure if it's robust enough.
https://github.com/twak/campskeleton
(edited for 2018...)
See http://www.sable.mcgill.ca/~dbelan2/roofs/roofs.html which contains an applet.
You may be able to use the JTS Topology Suite. It is a very capable library that I've used on a number of projects - never for straight skeleton, but it may be possible.
Edit:
Ah. I see that "Straight Skeleton" is a technical term. The wikipedia article references several algorithms. Have you looked at those?
As I understand it, you have a (convex?) polygon. From it, you subtract 1 or more (potentially non-convex) polygons. You want to turn the result into a set of polygons without holes. Are there extra rules that you're trying to apply?
I have a hard time coming up with a set of rules from the example that you provided. The outer polygons are non-convex; so it doesn't seem like you're trying to find a convex set to represent the result (which is a relatively common task).
If you could use the breakdown shown below, the algorithm is pretty simple. Can you clarify?
Can I ask u what is your purpose for finding Straight skeleton? Is it personal or commercial? I would be interested in knowing how you r using it to solve real time problems? I do have a java library that does that. My algorithm is listed here http://web.stcloudstate.edu/rsarnath/skeleton/definition.htm

Plotting data and doing a least squares regression with cosines in java

I have data I would like to plot, and more importantly, do a least squares regression on using cosines (instead of using polynomials):
Any recommendations? Thanks.
Probably the following page solves the regression part of your aim:
http://www.teneighty.org/software/index.html?f=fft&c=e98b8
You might find this demo Least Squares & Data Fitting helpful since it solves a few of your problems.
Just a bit of cautionary advice. Using a Fourier series makes sense if you think your underlying function has a cosine series as a basis; however, if you are using it as a basis for an arbitrary function (with unknown shape), you may do better trying to guess at a more specific underlying function type (polynomial, exponential, etc).
I did some constrained optimization on such a series, and the function wiggled around so much it was hard to say if my fit was meaningfull; my fit function had great number of local maxima.
MathGL can plot, fit (by help of GSL) and show fitting result - see this sample

Matrix multiplication in 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.

Categories

Resources