SVD.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SVD.h
  2. *
  3. * Copyright (C) 1994-2018 David Weenink
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. djmw 20020423 GPL header
  20. djmw 20120808 Latest modification.
  21. */
  22. #ifndef _SVD_h_
  23. #define _SVD_h_
  24. #include "NUM2.h"
  25. #include "Data.h"
  26. #include "SVD_def.h"
  27. void SVD_init (SVD me, integer numberOfRows, integer numberOfColumns);
  28. autoSVD SVD_create (integer numberOfRows, integer numberOfColumns);
  29. /*
  30. my tolerance = eps * MAX (numberOfRows, numberOfColumns)
  31. where eps is the floating point precision, approximately 2.2e-16
  32. */
  33. autoSVD SVD_createFromGeneralMatrix (constMAT m);
  34. void SVD_svd_d (SVD me, constMAT m);
  35. /*
  36. Perform SVD analysis on matrix M, i.e., decompose M as M = UDV'.
  37. Watch out: dataType contains V, not V' !!
  38. */
  39. void SVD_compute (SVD me);
  40. autoVEC SVD_solve (SVD me, constVEC b);
  41. /* Solve Ax = b */
  42. void SVD_solve2 (SVD me, double b[], double x[], double fractionOfSumOfSingularValues);
  43. void SVD_sort (SVD me);
  44. /*
  45. Sort singular values (and corresponding column vectors of U and V) in decreasing order.
  46. */
  47. void SVD_setTolerance (SVD me, double tolerance);
  48. double SVD_getTolerance (SVD me);
  49. double SVD_getConditionNumber (SVD me);
  50. double SVD_getSumOfSingularValuesAsFractionOfTotal (SVD me, integer from, integer to);
  51. integer SVD_getMinimumNumberOfSingularValues (SVD me, double fractionOfSumOfSingularValues);
  52. double SVD_getSumOfSingularValues (SVD me, integer from, integer to);
  53. integer SVD_zeroSmallSingularValues (SVD me, double tolerance);
  54. /*
  55. Zero singular values smaller than maximum_singular_value * tolerance
  56. If tolerance == 0 then then my tolerance will be used.
  57. Return the number of s.v.'s zeroed.
  58. */
  59. void SVD_synthesize (SVD me, integer sv_from, integer sv_to, double **m);
  60. /*
  61. Synthesize matrix as U D(sv_from:sv_to) V'.
  62. (The synthesized matrix is an approximation of the svd'ed matrix with
  63. only a selected number of sv's).
  64. Matrix m is [numberOfRows x numberOfColumns] and must be allocated
  65. by caller!
  66. */
  67. void SVD_getSquared (SVD me, double **m, bool inverse);
  68. // compute V D^2 V' or V D^-2 V'
  69. integer SVD_getRank (SVD me);
  70. autoGSVD GSVD_create (integer numberOfColumns);
  71. autoGSVD GSVD_create_d (constMAT m1, constMAT m2);
  72. void GSVD_setTolerance (GSVD me, double tolerance);
  73. double GSVD_getTolerance (GSVD me);
  74. #endif /* _SVD_h_ */