[3] | 1 | #include <iostream> |
---|
| 2 | #include <math.h> |
---|
| 3 | #include <Cubes/cubes.hh> |
---|
| 4 | |
---|
| 5 | bool Image::isDetection(long x, long y) |
---|
| 6 | { |
---|
| 7 | if(this->par.getFlagFDR()) |
---|
[141] | 8 | return ( (!this->par.isBlank(this->array[y*axisDim[0]+x])) && |
---|
| 9 | (this->pValue[y*axisDim[0]+x] < this->pCutLevel) ); |
---|
[3] | 10 | else |
---|
[141] | 11 | return ( (!this->par.isBlank(this->array[y*axisDim[0]+x])) && |
---|
| 12 | ( ((this->array[y*axisDim[0]+x]-this->mean)/this->sigma) |
---|
| 13 | > this->cutLevel ) ); |
---|
[3] | 14 | } |
---|
| 15 | |
---|
| 16 | bool Image::isDetection(float value) |
---|
| 17 | { |
---|
[141] | 18 | return ( (!this->par.isBlank(value)) && |
---|
| 19 | (((value - this->mean) / this->sigma) > this->cutLevel) ); |
---|
[3] | 20 | } |
---|
| 21 | |
---|
| 22 | bool Image::isDetectionFDR(float pvalue) |
---|
| 23 | { |
---|
[141] | 24 | return ( (pvalue < this->pCutLevel ) ); |
---|
[3] | 25 | |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | bool isDetection(float value, float mean, float sigma, float cut) |
---|
| 29 | { |
---|
| 30 | return ( ((value - mean) / sigma) > cut ) ; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | int Image::setupFDR() |
---|
| 34 | { |
---|
[86] | 35 | /** |
---|
| 36 | * Image::setupFDR() |
---|
| 37 | * Determines the critical Prob value for the False Discovery Rate |
---|
| 38 | * detection routine. All pixels with Prob less than this value will |
---|
| 39 | * be considered detections. |
---|
| 40 | * The Prob here is the probability, assuming a Normal distribution, of |
---|
| 41 | * obtaining a value as high or higher than the pixel value (ie. only the |
---|
| 42 | * positive tail of the PDF) |
---|
| 43 | */ |
---|
| 44 | |
---|
[3] | 45 | this->alpha = this->par.alphaFDR; |
---|
| 46 | |
---|
| 47 | // first calculate p-value for each pixel, using mean and sigma |
---|
| 48 | // assume Gaussian for now. |
---|
| 49 | |
---|
[141] | 50 | float *orderedP = new float[this->numPixels]; |
---|
| 51 | int count = 0; |
---|
| 52 | for(int pix=0; pix<this->numPixels; pix++){ |
---|
| 53 | |
---|
| 54 | if( !(this->par.isBlank(this->array[pix])) ){ |
---|
| 55 | float zStat = (this->array[pix] - this->mean) / (this->sigma); |
---|
| 56 | this->pValue[pix] = 0.5 * erfc(zStat/M_SQRT2); |
---|
[82] | 57 | // Want the factor of 0.5 here, as we are only considering the positive tail |
---|
| 58 | // of the distribution. Don't care about negative detections. |
---|
[141] | 59 | |
---|
| 60 | orderedP[count++] = this->pValue[pix]; |
---|
[82] | 61 | } |
---|
[141] | 62 | else this->pValue[pix] = 1.0; |
---|
| 63 | //need to make this high so that it won't be below the P cut level. |
---|
[3] | 64 | } |
---|
| 65 | |
---|
[141] | 66 | // now order them |
---|
[82] | 67 | sort(orderedP,0,count); |
---|
[3] | 68 | |
---|
| 69 | // now find the maximum P value. |
---|
[117] | 70 | int max = 0; |
---|
[82] | 71 | float cN = 0.; |
---|
| 72 | int psfCtr; |
---|
| 73 | int numPix = int(this->par.getBeamSize()); |
---|
| 74 | for(psfCtr=1;psfCtr<=numPix;(psfCtr)++) |
---|
| 75 | cN += 1./float(psfCtr); |
---|
[3] | 76 | |
---|
[82] | 77 | for(int loopCtr=0;loopCtr<count;loopCtr++) { |
---|
[103] | 78 | if( orderedP[loopCtr] < (double(loopCtr+1)*this->alpha/(cN * double(count))) ) { |
---|
[82] | 79 | max = loopCtr; |
---|
[103] | 80 | } |
---|
[3] | 81 | } |
---|
| 82 | |
---|
[82] | 83 | this->pCutLevel = orderedP[max]; |
---|
[3] | 84 | |
---|
| 85 | delete [] orderedP; |
---|
[141] | 86 | |
---|
[3] | 87 | } |
---|
| 88 | |
---|