#include <iterator>#include <fstream>#include <iostream>#include <cmath>#include <cassert>#include <string>#include <map>#include <functional>Go to the source code of this file.
Typedefs | |
| typedef map< double, int > | CMap |
Functions | |
| void | calculateSums (float inFloat) |
| void | vectorToMap (float *inBegin, float *inEnd, CMap &outMap) |
| double | rankifyMatrix (float *inMatrix, int inSize) |
| double | rescale (float inFloat) |
| void | changeSign (float *inMatrix, int inSize) |
| void | symmetrify (float *inMatrix, int inSize) |
| main (int argc, char **argv) | |
Variables | |
| int | gCount = 0 |
| double | gSum = 0 |
| double | gSumOfSquares = 0 |
| typedef map<double,int> CMap |
Definition at line 31 of file modifyDistanceMatrix.cc.
| void calculateSums | ( | float | inFloat | ) |
Definition at line 25 of file modifyDistanceMatrix.cc.
References gCount, gSum, and gSumOfSquares.
Referenced by main().
00025 { 00026 gCount ++; 00027 gSum += inFloat; 00028 gSumOfSquares+= inFloat * inFloat; 00029 }
| void changeSign | ( | float * | inMatrix, | |
| int | inSize | |||
| ) |
Definition at line 100 of file modifyDistanceMatrix.cc.
Referenced by main().
00101 { 00102 inSize=inSize*inSize; 00103 00104 for(float* p=inMatrix;p!=inMatrix+inSize;p++){ 00105 *p = 1 - *p; 00106 } 00107 }
| main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 128 of file modifyDistanceMatrix.cc.
References calculateSums(), changeSign(), rankifyMatrix(), and symmetrify().
00128 { 00129 00130 if(argc!=4){ 00131 cout << "usage: " 00132 << argv[0] 00133 << " <INFILE> <OUTFILE> <SIZE>" 00134 << endl; 00135 exit(1); 00136 } 00137 00138 string lInName=argv[1]; 00139 string lOutName=argv[2]; 00140 int lSize=atoi(argv[3]); 00141 00142 float* lMatrix=new float[lSize*lSize]; 00143 assert(lMatrix); 00144 { 00145 ifstream lIn(lInName.c_str()); 00146 00147 while(lIn){ 00148 float lBuffer; 00149 lIn.read((char*)&lBuffer,sizeof(lBuffer)); 00150 calculateSums(lBuffer); 00151 } 00152 } 00153 cout << "until here " 00154 << flush 00155 << endl; 00156 { 00157 ifstream lIn(lInName.c_str()); 00158 ofstream lOut(lOutName.c_str()); 00159 00160 assert(lOut); 00161 00162 int lCount=0; 00163 while(lIn){ 00164 float lBuffer; 00165 lIn.read((char*)&lBuffer, 00166 sizeof(lBuffer)); 00167 lMatrix[lCount++]=lBuffer; 00168 } 00169 00170 #ifdef VISTEX 00171 rankifyMatrix(lMatrix, 00172 lSize); 00173 #endif 00174 00175 //symmetrify the matrix 00176 symmetrify(lMatrix, 00177 lSize); 00178 00179 //get from score to distance 00180 changeSign(lMatrix, 00181 lSize); 00182 00183 00184 lOut.write((char*)lMatrix, 00185 sizeof(float) 00186 *(lSize*lSize)); 00187 00188 } 00189 }
| double rankifyMatrix | ( | float * | inMatrix, | |
| int | inSize | |||
| ) |
Take the matrix make pairs of score and ID
Definition at line 45 of file modifyDistanceMatrix.cc.
References vectorToMap().
Referenced by main().
00046 { 00049 for(int lLine=0; 00050 lLine<inSize; 00051 lLine++){ 00052 //this map is sorted by rank inascending order 00053 CMap lMap; 00054 vectorToMap(inMatrix + lLine*inSize, 00055 inMatrix + (1+lLine)*inSize, 00056 lMap); 00057 //cout << endl; 00058 00059 int lCount=inSize; 00060 for(CMap::const_iterator i=lMap.begin(); 00061 i!=lMap.end(); 00062 i++){ 00063 //in the matrix now are the query ranks 00064 float l= float(--lCount)/inSize; 00065 if(l>1) 00066 l=1; 00067 if(l<0) 00068 l=0; 00069 inMatrix[(lLine*inSize)+i->second]=1-l; 00070 } 00071 } 00072 }
| double rescale | ( | float | inFloat | ) |
Definition at line 75 of file modifyDistanceMatrix.cc.
References gCount, gSum, and gSumOfSquares.
00075 { 00076 double lAverage=(gSum/gCount); 00077 double lAverageSquare= 00078 gSumOfSquares/gCount; 00079 double lSDev= 00080 sqrt(lAverageSquare 00081 - 00082 lAverage*lAverage); 00083 //...so from score to pseudo distance 00084 double lReturnValue=0.5-((inFloat-lAverage)/lSDev/3); 00085 00086 if(lReturnValue>.9999) 00087 lReturnValue=1; 00088 if(lReturnValue<0.0001) 00089 lReturnValue=0; 00090 00091 // cout << "[" << lReturnValue << "]" <<flush; 00092 assert((lReturnValue<=1) && (lReturnValue>=0)); 00093 00094 return 00095 lReturnValue; 00096 }
| void symmetrify | ( | float * | inMatrix, | |
| int | inSize | |||
| ) |
Definition at line 110 of file modifyDistanceMatrix.cc.
Referenced by main().
00111 { 00112 for(int i=0; 00113 i<inSize; 00114 i++){ 00115 for(int j=0; 00116 j<inSize; 00117 j++){ 00118 float l=min(inMatrix[i*inSize+j], 00119 inMatrix[j*inSize+i]); 00120 inMatrix[i*inSize+j]=l; 00121 inMatrix[j*inSize+i]=l; 00122 } 00123 00124 } 00125 };
| void vectorToMap | ( | float * | inBegin, | |
| float * | inEnd, | |||
| CMap & | outMap | |||
| ) |
Definition at line 33 of file modifyDistanceMatrix.cc.
Referenced by rankifyMatrix().
00035 { 00036 int lCount=0; 00037 for(float* i=inBegin; 00038 i!=inEnd; 00039 i++){ 00040 outMap.insert(make_pair(*i,lCount++)); 00041 // cout << "-" << flush; 00042 } 00043 }
| int gCount = 0 |
Definition at line 21 of file modifyDistanceMatrix.cc.
Referenced by calculateSums(), and rescale().
| double gSum = 0 |
Definition at line 22 of file modifyDistanceMatrix.cc.
Referenced by calculateSums(), and rescale().
| double gSumOfSquares = 0 |
Definition at line 23 of file modifyDistanceMatrix.cc.
Referenced by calculateSums(), and rescale().
1.5.6