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