00001
00002 #ifndef vnl_svd_fixed_h_
00003 #define vnl_svd_fixed_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014 #include <vnl/vnl_numeric_traits.h>
00015 #include <vnl/vnl_vector_fixed.h>
00016 #include <vnl/vnl_matrix_fixed.h>
00017 #include <vnl/vnl_diag_matrix_fixed.h>
00018 #include <vcl_iosfwd.h>
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 export template <class T, unsigned int R, unsigned int C>
00035 class vnl_svd_fixed
00036 {
00037 public:
00038
00039 typedef typename vnl_numeric_traits<T>::abs_t singval_t;
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 vnl_svd_fixed(vnl_matrix_fixed<T,R,C> const &M, double zero_out_tol = 0.0);
00057 ~vnl_svd_fixed() {}
00058
00059
00060
00061
00062 void zero_out_absolute(double tol = 1e-8);
00063
00064
00065 void zero_out_relative(double tol = 1e-8);
00066 int singularities () const { return W_.rows() - rank(); }
00067 unsigned int rank () const { return rank_; }
00068 singval_t well_condition () const { return sigma_min()/sigma_max(); }
00069
00070
00071 singval_t determinant_magnitude () const;
00072 singval_t norm() const;
00073
00074
00075 vnl_matrix_fixed<T,R,C> & U() { return U_; }
00076
00077
00078 vnl_matrix_fixed<T,R,C> const& U() const { return U_; }
00079
00080
00081 T U(int i, int j) const { return U_(i,j); }
00082
00083
00084 vnl_diag_matrix_fixed<singval_t, C> & W() { return W_; }
00085
00086
00087 vnl_diag_matrix_fixed<singval_t, C> const & W() const { return W_; }
00088 vnl_diag_matrix_fixed<singval_t, C> & Winverse() { return Winverse_; }
00089 vnl_diag_matrix_fixed<singval_t, C> const & Winverse() const { return Winverse_; }
00090 singval_t & W(int i, int j) { return W_(i,j); }
00091 singval_t & W(int i) { return W_(i,i); }
00092 singval_t sigma_max() const { return W_(0,0); }
00093 singval_t sigma_min() const { return W_(C-1,C-1); }
00094
00095
00096 vnl_matrix_fixed<T,C,C> & V() { return V_; }
00097
00098
00099 vnl_matrix_fixed<T,C,C> const& V() const { return V_; }
00100
00101
00102 T V(int i, int j) const { return V_(i,j); }
00103
00104
00105 inline vnl_matrix_fixed<T,C,R> inverse () const { return pinverse(); }
00106
00107
00108 vnl_matrix_fixed<T,C,R> pinverse (unsigned int rank = ~0u) const;
00109
00110
00111 vnl_matrix_fixed<T,R,C> tinverse (unsigned int rank = ~0u) const;
00112
00113
00114 vnl_matrix_fixed<T,R,C> recompose (unsigned int rank = ~0u) const;
00115
00116
00117 vnl_matrix<T> solve (vnl_matrix<T> const& B) const;
00118
00119
00120 vnl_vector_fixed<T, C> solve (vnl_vector_fixed<T, R> const& y) const;
00121 void solve (T const *rhs, T *lhs) const;
00122
00123
00124
00125 void solve_preinverted(vnl_vector_fixed<T,R> const& rhs, vnl_vector_fixed<T,C>* out) const;
00126
00127
00128 vnl_matrix<T> nullspace() const;
00129
00130
00131 vnl_matrix<T> left_nullspace() const;
00132
00133
00134 vnl_matrix<T> nullspace(int required_nullspace_dimension) const;
00135
00136
00137 vnl_matrix<T> left_nullspace(int required_nullspace_dimension) const;
00138
00139
00140
00141
00142 vnl_vector_fixed<T,C> nullvector() const;
00143
00144
00145
00146 vnl_vector_fixed<T,R> left_nullvector() const;
00147
00148 bool valid() const { return valid_; }
00149
00150 private:
00151
00152 vnl_matrix_fixed<T, R, C> U_;
00153 vnl_diag_matrix_fixed<singval_t, C> W_;
00154 vnl_diag_matrix_fixed<singval_t, C> Winverse_;
00155 vnl_matrix_fixed<T, C, C> V_;
00156 unsigned rank_;
00157 bool have_max_;
00158 singval_t max_;
00159 bool have_min_;
00160 singval_t min_;
00161 double last_tol_;
00162 bool valid_;
00163
00164
00165 vnl_svd_fixed<T,R,C>(vnl_svd_fixed<T,R,C> const &) { }
00166 vnl_svd_fixed<T,R,C>& operator=(vnl_svd_fixed<T,R,C> const &) { return *this; }
00167 };
00168
00169 template <class T, unsigned int R, unsigned int C>
00170 inline
00171 vnl_matrix_fixed<T,C,R> vnl_svd_fixed_inverse(vnl_matrix_fixed<T,R,C> const& m)
00172 {
00173 return vnl_svd_fixed<T,R,C>(m).inverse();
00174 }
00175
00176 export template <class T, unsigned int R, unsigned int C>
00177 vcl_ostream& operator<<(vcl_ostream&, vnl_svd_fixed<T,R,C> const& svd);
00178
00179 #endif // vnl_svd_fixed_h_