2

I am looking for Singular Value Decomposition (SVD) code in C, would you please help me?

I found many sources but I cannot run them, I am looking for a version of SVD code that provide all 3 matrix of S, V and U for me.

Danijel
  • 8,198
  • 18
  • 69
  • 133
Amir
  • 1,919
  • 8
  • 53
  • 105

3 Answers3

2

You can use the Numerical recipies code for that svdcmp.c reference. Actually in my case I found more accurate the openCV one, but both work fine.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Could you be more specific about term "accurate" ? – truthseeker Sep 04 '15 at 18:56
  • @truthseeker To be honest I have no idea, I am no help for you to seek the truth, as this was 3 years ago! At the time I was doing some computer vision application which required a really fine accuracy and numeric stability in all the steps. I remember testing this thoughtfully, and deciding that the openCV results were "better", but I dont recall how/why. My current guess: the algorithm is better/more stable – Ander Biguri Sep 04 '15 at 19:52
  • @truthseeker However nowadays, older and (hopefully) wiser, I would recommend to use LAPACK for this purpose. – Ander Biguri Sep 04 '15 at 19:54
  • Why LAPACK ? In what parameters is it better choice ? – truthseeker Sep 06 '15 at 08:36
  • @truthseeker Because it is the linear algebra pack that is used by practically everyone. It is just the best, most taken care one. The SVD there has to be as good as it gets. Even Matlab or some other algebra comertial software uses LAPACK under de hood. – Ander Biguri Sep 06 '15 at 22:21
1

Use one of the libraries listed at the Wiki page: comparison of linear algebra libraries. Look under the "SVD" column to make sure algorithm is supported (even vast majority of the libraries do support SVD).

Danijel
  • 8,198
  • 18
  • 69
  • 133
0

Don't write it yourself, don't deal with trying to build someone else's source. Use a library that provides this function for you. There's probably already one available on your target platform.

Specifically, use the industry-standard LAPACK library or use the GSL or whatever other linear algebra library you want. They all have an SVD implementation.

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
  • Problem is my teacher asked me to convert my code from C to special ASSEMBLY :(( so do you have any idea now? I am looking for an open source SVD – Amir Feb 17 '11 at 22:49
  • Your teacher asked you to write a general-purpose SVD in assembly? That's way over the line for a reasonable assignment. Are you sure you're interpreting it properly? The SVD is generally the most complex algorithm in a linear algebra library, and highly nontrivial to implement, even with a reference implementation available. – Stephen Canon Feb 17 '11 at 22:51
  • He advice me first write ur noise reducer in matlab, than C and at the end convert your C code to assembly! – Amir Feb 17 '11 at 22:53
  • @rima: what are the dimensions of the matrix whose SVD you want to compute? – Stephen Canon Feb 17 '11 at 22:56
  • @ stephen : I want pass a 2-dim array to it and it compute U S V for me – Amir Feb 17 '11 at 22:57
  • 1
    @rima: yes, but how big is the array? Are we talking about a 3x3 matrix or a 4000 x 187 matrix or do you need to be able to handle any size at all? – Stephen Canon Feb 17 '11 at 23:00
  • Good question, I am looking for SVD that handle big matrix like 600*600 but as much as it's an assignment & I dont have enough time 3*3 or 20*20 is also okay for me now.... – Amir Feb 17 '11 at 23:03
  • @stephen : would you please give me a link of a SVD that calculate U S and V for me? – Amir Feb 19 '11 at 00:58