source: trunk/Detection/thresholding_functions.cc @ 56

Last change on this file since 56 was 56, checked in by Matthew Whiting, 18 years ago

Changes mostly motivated by additional plotting routines (not really used for
Duchamp, but for analysis programs):
Utils/cpgcumul.c -- A pgplot program to plot the cumulative distribution.
Utils/plottingUtilities.cc -- Various functions to draw lines and contour plots.
Utils/utils.hh -- Prototypes for the above, plus the removal of the isDetection function.
Detection/thresholding_functions.cc -- Removal of the #include call for utils.hh
Detection/detection.hh -- Added the prototype for isDetection
Utils/menus.cc -- Changed the menu() function to return "" instead of calling

the cubeMenu when a cube is requested. This enables the
calling program to use the Duchamp input file instead.

File size: 2.1 KB
Line 
1#include <iostream>
2#include <math.h>
3#include <Cubes/cubes.hh>
4
5bool 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
13bool Image::isDetection(float value)
14{
15  return ( ((value - this->mean) / this->sigma) > this->cutLevel ) ;
16}
17
18bool Image::isDetectionFDR(float pvalue)
19{
20  return (  pvalue < this->pCutLevel ) ;
21
22}
23
24bool isDetection(float value, float mean, float sigma, float cut)
25{
26  return ( ((value - mean) / sigma) > cut ) ;
27}
28
29int Image::setupFDR()
30{
31  this->alpha = this->par.alphaFDR;
32
33  // first calculate p-value for each pixel, using mean and sigma
34  // assume Gaussian for now.
35  bool *isGood = new bool[this->numPixels];
36  int *loopCtr = new int;
37  for(*loopCtr=0;*loopCtr<this->numPixels;(*loopCtr)++)
38    isGood[*loopCtr] = !(this->par.isBlank(this->array[*loopCtr]));
39
40  float *rootTwo = new float;
41  *rootTwo=sqrt(2.);
42  for(int j=0;j<this->numPixels;j++){
43    if(isGood[j])
44      this->pValue[j] = 0.5*erfc((this->array[j] - this->mean) / (*rootTwo * this->sigma));
45    else
46      this->pValue[j] = 1.;  //need to make this high so that it won't be below the P cut level.
47  }
48  delete rootTwo;
49
50  // now order them
51  float *orderedP = new float[this->numPixels];
52  int *count = new int;
53  *count = 0;
54  for(*loopCtr=0;*loopCtr<this->numPixels;(*loopCtr)++)
55    if(isGood[*loopCtr])
56      orderedP[(*count)++] = this->pValue[*loopCtr];
57
58  sort(orderedP,0,(*count-1));
59 
60  // now find the maximum P value.
61  int *max = new int;
62  *max = -1;
63  float *cN  = new float;
64  *cN = 0.;
65  int *psfCtr = new int;
66  int *numPix = new int;
67  *numPix = int(this->par.getBeamSize());
68  for(*psfCtr=1;*psfCtr<=*numPix;(*psfCtr)++)
69    *cN += 1./float(*psfCtr);
70  delete psfCtr;
71  delete numPix;
72
73  for(*loopCtr=0;*loopCtr<*count;(*loopCtr)++) {
74    if( orderedP[*loopCtr] < (double(*loopCtr+1)*this->alpha/(*cN * double(*count))) )
75      *max = *loopCtr;
76  }
77
78  this->pCutLevel = orderedP[*max];
79
80  delete [] orderedP;
81  delete [] isGood;
82  delete max;
83  delete cN;
84  delete count;
85  delete loopCtr;
86}
87
Note: See TracBrowser for help on using the repository browser.