[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN GR_SVD.h
From: |
Georg Klein |
Subject: |
[Toon-members] TooN GR_SVD.h |
Date: |
Tue, 25 Aug 2009 19:21:44 +0000 |
CVSROOT: /sources/toon
Module name: TooN
Changes by: Georg Klein <georgklein> 09/08/25 19:21:44
Modified files:
. : GR_SVD.h
Log message:
Added reorder() method which re-arranges components so that singular
values
are in descending order.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/GR_SVD.h?cvsroot=toon&r1=1.2&r2=1.3
Patches:
Index: GR_SVD.h
===================================================================
RCS file: /sources/toon/TooN/GR_SVD.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- GR_SVD.h 25 Aug 2009 16:09:53 -0000 1.2
+++ GR_SVD.h 25 Aug 2009 19:21:43 -0000 1.3
@@ -32,6 +32,8 @@
#include <TooN/TooN.h>
#include <cmath>
+#include <vector>
+#include <algorithm>
namespace TooN
{
@@ -117,6 +119,8 @@
return diagmult(get_V(),inv_diag) * get_U().T();
}
+ // Reorder the components so the singular values are in descending order
+ void reorder();
protected:
void Bidiagonalize();
@@ -484,5 +488,30 @@
return nMin;
}
+ template<int M, int N, class Precision, bool WANT_U, bool WANT_V>
+ void GR_SVD<M,N,Precision,WANT_U,WANT_V>::reorder()
+ {
+ Matrix<M, N, Precision> mU_copy = mU;
+ Matrix<N, N, Precision> mV_copy = mV;
+
+ std::vector<std::pair<Precision, unsigned int> > vSort;
+ vSort.reserve(N);
+ for(unsigned int i=0; i<N; ++i)
+ vSort.push_back(std::make_pair(-vDiagonal[i], i));
+ std::sort(vSort.begin(), vSort.end());
+ for(unsigned int i=0; i<N; ++i)
+ mU.T()[i] = mU_copy.T()[vSort[i].second];
+ for(unsigned int i=0; i<N; ++i)
+ mV.T()[i] = mV_copy.T()[vSort[i].second];
+ for(unsigned int i=0; i<N; ++i)
+ vDiagonal[i] = -vSort[i].first;
+ }
+
}
#endif
+
+
+
+
+
+