Alex Rivera | Logout

Singular Value Decomposition (SVD) in PHP

Asked 2009-06-06T16:25:02.000
9

I would like to implement Singular Value Decomposition (SVD) in PHP. I know that there are several external libraries which could do this for me. But I have two questions concerning PHP, though: 1) Do you think it's possible and/or reasonable to code the SVD in PHP? 2) If (1) is yes: Can you help me to code it in PHP?

I've already coded some parts of SVD by myself. Here's the code which I made comments to the course of action in. Some parts of this code aren't completely correct.

It would be great if you could help me. Thank you very much in advance!

Edit
Report

3 Answers

5

Be careful when you say "I don't care what the time limits are". SVD is an O(N^3) operation (or O(MN^2) if it's a rectangular m*n matrix) which means that you could very easily be in a situation where your problem can take a very long time. If the 100*100 case takes one minute, the 1000*1000 case would 10^3 minutes, or nearly 17 hours (and probably worse, realistically, as you're likely to be out of cache). With something like PHP, the prefactor -- the number multiplying the N^3 in order to calculate the required FLOP count, could be very, very large.

Having said that, of course it's possible to code it in PHP -- the language has the required data structures and operations.

answered 2009-06-14T11:43:48.887
2

Regarding question 1: It definitely is possible. Whether it's reasonable depends on your scenario: How big are your matrices? How often do you intend to run the code? Is it run in a web site or from the command line? If you do care about speed, I would suggest writing a simple extension that wraps calls to the GNU Scientific Library.

answered 2009-06-06T17:52:43.740
0
  1. Yes. this is perfectly possible to be implemented in PHP. I don't know what the reasonable time frame for execution and how large it can compute. I would probably have to implement the algorithm to get a rought idea.

  2. Yes I can help you code it. But why do you need help? Doesn't the code you wrote work?

Just as an aside question. What version of PHP do you use?

answered 2009-06-12T12:23:15.207

Your Answer