00001 #ifndef __RealSMatrix_H__
00002 #define __RealSMatrix_H__
00003
00004
00005
00040 #include <stdio.h>
00041 #include "RealVector.hpp"
00042 #include "H.hpp"
00043
00044 class I;
00045 class RTriDiagonalMatrix;
00046
00047 class RealSMatrix
00048 {
00049 private:
00050
00051 int width;
00052 double** data;
00053
00054 public:
00055
00056 RealSMatrix(int n, double value=0.0);
00057 RealSMatrix(I& ident);
00058 RealSMatrix(H& h);
00059 RealSMatrix(const RealSMatrix& m);
00060 RealSMatrix operator=(const RealSMatrix& m);
00061
00062 ~RealSMatrix();
00063
00064 RealSMatrix* copy();
00065 RealSMatrix* identity();
00066
00067 RealSMatrix* AtA(RealSMatrix* dest=0);
00068
00069 RealSMatrix t();
00070
00071 int size(){ return width*width; }
00072
00073 int getWidth()const { return width; }
00074 int getHeight()const { return width; }
00075
00076
00077 void set0(int i, int j, double value){ data[i][j]= value; }
00078 double get0(int i, int j)const { return data[i][j]; }
00079
00080
00081 void set(int i, int j, double value){ data[i-1][j-1]= value; }
00082 double get(int i, int j)const { return data[i-1][j-1]; }
00083
00084
00085 void setAll(double value=0.0);
00086 void set(RealSMatrix* from);
00087 void setIdentity();
00088
00089
00090 RealSMatrix* multA_X(RealSMatrix* dest);
00091
00092 void addA_kX(RealSMatrix& dest, double k=1.0);
00093 void addA_k_vvT(RealVector& v, double k=1.0);
00094 double vTAv(RealVector& v);
00095 double rayleighQuotient(RealVector& v){return vTAv(v)/v.vT_v();}
00096
00097 double det();
00098 double trace();
00099 double cond();
00100
00101
00102 double normeMin();
00103 double normeInfinite();
00104 double norme2();
00105 double normeF();
00106
00107 double sum();
00108
00109 double minimum();
00110 double maximum();
00111 double mean(){ return sum()/size(); }
00112 double sigma();
00113
00114
00115 RealSMatrix* jacobiEV(RealVector* dEigenValue, RealSMatrix* vEigenVector);
00116
00117
00118 RealSMatrix sqrt();
00119 RealSMatrix pow(double pow);
00120 RealSMatrix sqr();
00121 RealSMatrix exp();
00122 RealSMatrix log();
00123 RealSMatrix log(double base);
00124
00125 RealSMatrix sin();
00126 RealSMatrix cos();
00127 RealSMatrix tan();
00128
00129
00130
00131
00132 void HA_inplace(H& h);
00133 void HA_inplace(H& h, int nI);
00134
00135 void AH_inplace(H& h);
00136 void AH_inplace(H& h, int nI);
00137 void AH_inplace(H& h, int nI, int ny);
00138
00139 RealSMatrix* qrHouseholderR(RealSMatrix* r=0);
00140
00141 void qrHouseholder(RealSMatrix* q, RealSMatrix* r);
00142 void qrGivens(RealSMatrix* q, RealSMatrix* r);
00143 void qrCGS(RealSMatrix* q, RealSMatrix* r);
00144 void qrMGS(RealSMatrix* q, RealSMatrix* r);
00145 RealSMatrix* upperHessenberg(RealSMatrix* uH=0);
00146
00147
00148 RealSMatrix* pseudoInverse(RealSMatrix* x=0);
00149 RealSMatrix* varianceCovariance(RealSMatrix* aT_aInverse=0);
00150
00151
00152 RealVector* oja(int nmax=100, double beta=0.1, RealVector* oldFirstPCA=0);
00153 RealSMatrix* mOja(double nmax=100, double beta=0.1, RealSMatrix* oldPCA=0);
00154 RealSMatrix* apex(double nmax=100, double beta=0.1, RealSMatrix* oldPCA=0);
00155
00156
00157 double ojaEigenvalue(int nmax=100, int ns=10, double beta=0.1, RealVector* oldFirstPCA=0);
00158 RealVector* apexEigenvalues(int nmax=100, int ns=10, double beta=0.1, RealSMatrix* oldPCA=0);
00159
00160
00161 RealVector* firstPcSPCA(int type=2, bool batch=false, int nmax=100, RealVector* oldFirstPCA=0);
00162 double firstEigenvalueSPCA(int type=2, bool batch=false, int nmax=100, RealVector* oldFirstPCA=0);
00163
00164 RealVector* kiemePcSPCA(int type=2, int k=0, bool batch=false, int nmax=100, RealVector* oldFirstPCA=0);
00165 double kiemeEigenvalueSPCA(int type=2, int k=0, bool batch=false, int nmax=100, RealVector* oldFirstPCA=0);
00166
00167 RealSMatrix* fullSPCA(int type=2, bool batch=false, double nmax=100, RealSMatrix* oldPCA=0);
00168 RealVector* eigenvaluesSPCA(int type=2, bool batch=false, double nmax=100, RealSMatrix* oldPCA=0);
00169
00170
00171 RealVector* inverseIteration(double eigenvalue, int nmax=3, RealVector* ev=0);
00172
00173
00174 RealSMatrix* bidiagonalisation(RealSMatrix* biDiag=0);
00175 RealSMatrix* svdGolubKahan(RealSMatrix* biDiag=0);
00176
00177 RealSMatrix* qrIteration(int iterMax=3, RealSMatrix* Ak=0);
00178 RealSMatrix* qrHessenbergIteration(int iterMax=3, RealSMatrix* r=0);
00179 RealSMatrix* qrShift(int iterMax=3, RealSMatrix* r=0);
00180 RealSMatrix* qrDoubleShift(int iterMax=3, RealSMatrix* r=0);
00181
00182
00183 RealSMatrix* qrSymmetric(int iterMax=3, RealSMatrix* r=0);
00184 RTriDiagonalMatrix* lanczosSymmetric(RTriDiagonalMatrix* t=0);
00185 RTriDiagonalMatrix* lanczosMGS(RTriDiagonalMatrix* t=0);
00186
00187
00188 void luDoolittle(RealSMatrix* l1, RealSMatrix* u);
00189 void luCrout(RealSMatrix* l, RealSMatrix* u1){}
00190
00191
00192 RealSMatrix* ilu0();
00193 RealSMatrix* iluth(double threshold=0.001);
00194
00195
00196
00197 RealVector* backwardSubstitution(RealVector& b, RealVector* x=0);
00198 RealVector* backwardSubstitutionU1(RealVector& b, RealVector* x=0);
00199 RealVector* forwardElimination(RealVector& b, RealVector* x=0);
00200 RealVector* forwardEliminationL1(RealVector& b, RealVector* x=0);
00201
00202 RealVector* linearSolverU(RealVector& b, RealVector* x=0);
00203 RealVector* linearSolverU1(RealVector& b, RealVector* x=0);
00204 RealVector* linearSolverL(RealVector& b, RealVector* x=0);
00205 RealVector* linearSolverL1(RealVector& b, RealVector* x=0);
00206
00207
00208 RealSMatrix* inverseOfU(RealSMatrix* uinv=0);
00209 RealSMatrix* inverseOfU1(RealSMatrix* uinv=0);
00210
00211
00212 void operator+=(double value);
00213 void operator-=(double value);
00214 void operator*=(double value);
00215 void operator/=(double value);
00216
00217
00218 void operator+=(const RealSMatrix& m);
00219 void operator-=(const RealSMatrix& m);
00220 void operator*=(const RealSMatrix& m);
00221
00222
00223 friend RealVectorT operator*(const RealVectorT& vt, const RealSMatrix& m);
00224 friend RealVector operator*(const RealSMatrix& m, const RealVector& v);
00225
00226 void output();
00227 void output(FILE* file);
00228 };
00229
00230 #endif
00231
00232
00233