DIAlign
chromSimMatrix.h
1 #ifndef CHROMSIMMATRIX_H
2 #define CHROMSIMMATRIX_H
3 
4 #include <vector>
5 #include <numeric>
6 #include "utils.h"
7 #include "similarityMatrix.h"
8 
13 namespace DIAlign
14 {
15 
17 namespace SimilarityMatrix
18 {
20  template<typename T>
21  struct square
22  {
23  T operator()(const T& Left, const T& Right) const
24  {
25  // We use this struct as binary operation function object. It should take current accumulation value (Left) and value of current element (Right).
26  return (Left + Right*Right);
27  }
28  };
29 
31  double meanVecOfVec(const std::vector<std::vector<double>>& vov);
32 
34  double eucLenVecOfVec(const std::vector<std::vector<double>>& vov);
35 
39  std::vector<double> perSampleEucLenVecOfVec(const std::vector<std::vector<double>>& vec);
40 
42  std::vector<double> perSampleSqrSumVecOfVec(const std::vector<std::vector<double>>& vec);
43 
45  std::vector<double> perSampleMeanVecOfVec(const std::vector<std::vector<double>>& vec);
46 
48  std::vector<double> perSampleSumVecOfVec(const std::vector<std::vector<double>>& vec);
49 
51  void distToSim(SimMatrix& s, double offset, double Numerator);
52 
54  void clamp(std::vector<double>& vec, double minValue, double maxValue);
55 
57  std::vector<std::vector<double>> meanNormalizeVecOfVec(const std::vector<std::vector<double>>& d);
58 
60  std::vector<std::vector<double>> L2NormalizeVecOfVec(const std::vector<std::vector<double>>& d);
61 
63  std::vector<std::vector<double>> divideVecOfVec(const std::vector<std::vector<double>>& vov, double num);
64 
66  void ElemWiseSumOuterProd(const std::vector<double>& d1, const std::vector<double>& d2, SimMatrix& s);
67 
69  void ElemWiseSumOuterProdMeanSub(const std::vector<double>& d1, const std::vector<double>& d2, SimMatrix& s, const std::vector<double>& mean1, const std::vector<double>& mean2);
70 
72  void ElemWiseSumOuterEucl(const std::vector<double>& d1, const std::vector<double>& d2, SimMatrix& s);
73 
75  void ElemWiseOuterCosine(const std::vector<double>& d1, const std::vector<double>& d2, const std::vector<double>& d1_mag, const std::vector<double>& d2_mag, SimMatrix& s);
76 
78  void SumOuterProd(const std::vector<std::vector<double>>& d1, const std::vector<std::vector<double>>& d2, const std::string Normalization, SimMatrix& s);
79 
81  void SumOuterCov(const std::vector<std::vector<double>>& d1, const std::vector<std::vector<double>>& d2, const std::string Normalization, SimMatrix& s);
82 
84  void SumOuterCorr(const std::vector<std::vector<double>>& d1, const std::vector<std::vector<double>>& d2, const std::string Normalization, SimMatrix& s);
85 
87  void SumOuterEucl(const std::vector<std::vector<double>>& d1, const std::vector<std::vector<double>>& d2, const std::string Normalization, SimMatrix& s);
88 
90  void SumOuterCosine(const std::vector<std::vector<double>>& d1, const std::vector<std::vector<double>>& d2, const std::string Normalization, SimMatrix& s);
91 
101  SimMatrix getSimilarityMatrix(const std::vector<std::vector<double>>& d1, const std::vector<std::vector<double>>& d2,
102  const std::string Normalization, const std::string SimType, double cosAngleThresh,
103  double dotProdThresh);
104 
105 } // namespace SimilarityMatrix
106 } // namespace DIAlign
107 
108 #endif // CHROMSIMMATRIX_H
void ElemWiseSumOuterEucl(const std::vector< double > &d1, const std::vector< double > &d2, SimMatrix &s)
Adds outer prodict of (d1-d2)*(d1-d2) in similarity matrix s.
Definition: chromSimMatrix.cpp:137
std::vector< std::vector< double > > meanNormalizeVecOfVec(const std::vector< std::vector< double >> &vov)
Returns a vector of vector with values divided by the output of meanVecOfVec().
Definition: chromSimMatrix.cpp:90
void clamp(std::vector< double > &vec, double minValue, double maxValue)
Limits values between minValue and maxValue.
Definition: chromSimMatrix.cpp:85
void ElemWiseSumOuterProd(const std::vector< double > &d1, const std::vector< double > &d2, SimMatrix &s)
Adds outer prodict of d1 and d2 in similarity matrix s.
Definition: chromSimMatrix.cpp:113
std::vector< std::vector< double > > L2NormalizeVecOfVec(const std::vector< std::vector< double >> &vov)
Returns a vector of vector with values divided by the output of eucLenVecOfVec(). ...
Definition: chromSimMatrix.cpp:97
Generic namespace for all classes and functions of DIAlign.
Definition: affinealignment.cpp:29
void distToSim(SimMatrix &s, double offset, double Numerator)
Calculates distance as Distance = Numerator/(Similarity score + offset).
Definition: chromSimMatrix.cpp:79
void SumOuterCosine(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string Normalization, SimMatrix &s)
Given Normalization modifies d1 and d2, and subsequently sums ElemWiseOuterCosine() of d1 vectors wit...
Definition: chromSimMatrix.cpp:293
void SumOuterProd(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string Normalization, SimMatrix &s)
Given Normalization modifies d1 and d2, and subsequently sums ElemWiseSumOuterProd() of d1 vectors wi...
Definition: chromSimMatrix.cpp:163
void ElemWiseSumOuterProdMeanSub(const std::vector< double > &d1, const std::vector< double > &d2, SimMatrix &s, const std::vector< double > &mean1, const std::vector< double > &mean2)
Adds outer prodict of (d1-mean1) and (d2-mean2) in similarity matrix s.
Definition: chromSimMatrix.cpp:125
void ElemWiseOuterCosine(const std::vector< double > &d1, const std::vector< double > &d2, const std::vector< double > &d1_mag, const std::vector< double > &d2_mag, SimMatrix &s)
Adds outer prodict of cosAng(d1,d2) in similarity matrix s.
Definition: chromSimMatrix.cpp:149
void SumOuterCov(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string Normalization, SimMatrix &s)
Given Normalization modifies d1 and d2, and subsequently sums ElemWiseSumOuterProdMeanSub() of d1 vec...
Definition: chromSimMatrix.cpp:189
Similarity matrix.
Definition: similarityMatrix.h:14
SimMatrix getSimilarityMatrix(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string Normalization, const std::string SimType, double cosAngleThresh, double dotProdThresh)
Returns a similarity matrix between d1 and d2 vector of vectors.
Definition: chromSimMatrix.cpp:324
Calculates sum of previous result and square of current element (useful for sum of squares)...
Definition: chromSimMatrix.h:21
void SumOuterEucl(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string Normalization, SimMatrix &s)
Given Normalization modifies d1 and d2, and subsequently sums ElemWiseSumOuterEucl() of d1 vectors wi...
Definition: chromSimMatrix.cpp:262
void SumOuterCorr(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string Normalization, SimMatrix &s)
Given Normalization modifies d1 and d2, and subsequently sums correlation coefficient of d1 vectors w...
Definition: chromSimMatrix.cpp:218
std::vector< std::vector< double > > divideVecOfVec(const std::vector< std::vector< double >> &d, double num)
Returns a vector of vector with values divided by num.
Definition: chromSimMatrix.cpp:105