/usr/include/libphylo/matrixUtils.h is in rate4site 3.0.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | #ifndef ___MATRIX_UTIL_H
#define ___MATRIX_UTIL_H
#include "definitions.h"
#include "logFile.h"
#include "errorMsg.h"
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
class sequenceContainer;
using namespace std;
void printMatrix(const VVdouble &mat, ostream &out);
void printMatrix(const VVint &mat, ostream &out) ;
void readMatrixFromFile(VVdouble &mat,string fileName);
Vdouble getDiagonalFromMatrix(VVdouble &mat);
Vdouble getSubDiagonalFromMatrix(VVdouble &mat);
//get the first norm sum{abs(Mij)}
MDOUBLE getMatrixNorm(const VVdouble &mat);
// Same for vector of Matrices
MDOUBLE getVMatrixNorm(const VVVdouble &mat);
//get the specific coordinates sum from vector of Matrices
MDOUBLE getVMatrixJK(const VVVdouble &mat, const int j, const int k);
template<typename _T>
void resizeMatrix(vector<vector< _T> > &mat, int rows, int columns){
mat.resize(rows);
for (int i=0; i<rows;i++){
mat[i].resize(columns);
for (int j=0;j<columns;j++){ // initializing all values as zero
mat[i][j] = 0;
}
}
}
template<typename _T>
void unitMatrix(vector<vector< _T> > &m, int n){
resizeMatrix(m,n,n);
for (int i=0; i<n; i++){
for (int j=0; j<n;j++){
if (i==j) m[i][j]=1;
else m[i][j]=0;
}
}
}
template<typename _T>
void zeroMatrix(vector<vector< _T> > &m){
for (int i=0; i < m.size(); i++)
for (int j=0; j<m[i].size();j++)
m[i][j]=0;
}
template<typename _T>
void oneMatrix(vector<vector< _T> > &m){
for (int i=0; i < m.size(); i++)
for (int j=0; j<m[i].size();j++)
m[i][j]=1;
}
//assumes that #columns in mat1=#rows in mat2
template<typename _T>
vector<vector< _T> > multiplyMatrixes(vector<vector< _T> > &mat1, vector<vector< _T> > &mat2){
vector<vector< _T> > mat;
if ((mat1.size()==0) || (mat2.size() ==0))
errorMsg::reportError("Error in multiplyMatrixes, one of the matrices inputted is of size 0");;
int numColumns=mat1[0].size();
int numRows = mat2.size();
resizeMatrix(mat,numColumns,numRows);
for (int i=0; i<numColumns; i++){
for (int j=0; j<numRows;j++){
for (int k=0;k<numColumns;k++){
mat[i][j]+=mat1[i][k]*mat2[k][j];
}
}
}
return mat;
}
template<typename _T>
vector<vector< _T> > multiplyMatrixByScalar(const vector<vector< _T> > &mat, MDOUBLE scalar) {
vector<vector< _T> > mat_copy = mat;
for (int i=0; i<mat.size(); i++){
for (int j=0; j<mat[i].size();j++){
mat_copy[i][j]*=scalar;
}
}
return mat_copy;
}
template<typename _T>
vector<vector< _T> > add(const vector<vector< _T> > &mat1,const vector<vector< _T> > &mat2){
if (mat1.size()!=mat2.size()) errorMsg::reportError("different sized matrices in matrixUtils::add");
vector<vector< _T> > newMat(mat1.size());
for (int i=0;i<mat1.size();i++){
if (mat1[i].size()!=mat2[i].size()) errorMsg::reportError("different sized matrices in matrixUtils::add");
newMat[i].resize(mat1[i].size());
for (int j=0;j<mat1.size();j++){
newMat[i][j]=mat1[i][j]+mat2[i][j];
}
}
return newMat;
}
template<typename _T>
void printVec(vector< _T> &vec,ostream &out=cout,bool printVertical=true) {
for (int i=0; i<vec.size();i++){
out<< vec[i];
out<<(printVertical?"\n":" ");
}
out<<endl;
}
VVdouble transpose(const VVdouble &mat);
VVdouble subtract(const VVdouble &mat1,const VVdouble &mat2);
VVdouble reverseSign(const VVdouble &mat1);
void findMaxInVector(const Vdouble &vec, MDOUBLE &maxValue, int &argmax) ;
void findMinInVector(const Vdouble &vec, MDOUBLE &minValue, int &argmin) ;
bool isMinEQMaxInVector(const Vdouble &vec);
MDOUBLE averageElementInVector(const Vdouble &vec) ;
void appendBinaryVectors(vector <int> &vec1, const vector <int> &vec2);
void appendVectors(Vint &vec1, const Vint &vec2);
void appendVectors(VVdouble &vec1, const VVdouble &vec2);
Vint complementBinaryVec(vector <int>&bufferVec) ; // returns complementary binary vector
void readDoubleVecFromFile(Vdouble &vec,string fileName); //reads a vertical vector (separated by \n)
void normalize(Vdouble &vec);
void scaleByAverage(Vdouble &vec);
//solve nxn linear equations of the form Ax=b; return x;
Vdouble solveLinearEquations(VVdouble A,Vdouble b);
// functions from numerical recipes that solve nxn linear equations
void lubksb(VVdouble &a, Vdouble &indx, Vdouble &b);
void ludcmp(VVdouble &a, Vdouble &indx, MDOUBLE &d);
void resize_VVVV(int dim1, int dim2, int dim3, int dim4, VVVVdouble& vetor);
void resize_VVV(int dim1, int dim2, int dim3, VVVdouble& vetor);
#endif
|