CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
BinomialNoncentralInterval< Sorter > Class Template Reference

#include <BinomialNoncentralInterval.h>

Inheritance diagram for BinomialNoncentralInterval< Sorter >:
BinomialInterval

Public Member Functions

void calculate (const double X, const double n)
 
bool find_rho_set (const double rho, const int ntot, int &x_l, int &x_r) const
 
bool neyman (const int ntot, const int nrho, double *rho, double *x_l, double *x_r)
 
- Public Member Functions inherited from BinomialInterval
double alpha () const
 
bool contains (double rho)
 
double coverage_prob (const double rho, const int trials)
 
void dump (const int trials_min, const int trials_max)
 
void init (const double alpha, const tail_type t=equal_tailed)
 
double length () const
 
double lower () const
 
virtual const char * name () const =0
 
void scan_ntot (const double rho, const int ntot_min, const int ntot_max, double *ntot, double *prob)
 
void scan_rho (const int ntot, const int nrho, double *rho, double *prob)
 
double upper () const
 

Private Attributes

Sorter sorter_
 

Additional Inherited Members

- Public Types inherited from BinomialInterval
enum  tail_type { equal_tailed, lower_tailed, upper_tailed }
 
- Protected Member Functions inherited from BinomialInterval
void set (double l, double u)
 
- Protected Attributes inherited from BinomialInterval
double alpha_
 
double alpha_min_
 
double kappa2_
 
double kappa_
 
double lower_
 
tail_type type_
 
double upper_
 

Detailed Description

template<typename Sorter>
class BinomialNoncentralInterval< Sorter >

Definition at line 31 of file BinomialNoncentralInterval.h.

Member Function Documentation

template<typename Sorter>
void BinomialNoncentralInterval< Sorter >::calculate ( const double  X,
const double  n 
)
inlinevirtual

Implements BinomialInterval.

Definition at line 78 of file BinomialNoncentralInterval.h.

78  {
79  set(0, 1);
80 
81  const double tol = 1e-9;
82  double rho_min, rho_max, rho;
83  int x_l, x_r;
84 
85  // Binary search for the smallest rho whose acceptance set has right
86  // endpoint X; this is the lower endpoint of the rho interval.
87  rho_min = 0; rho_max = 1;
88  while (std::fabs(rho_max - rho_min) > tol) {
89  rho = (rho_min + rho_max)/2;
90  find_rho_set(rho, int(n), x_l, x_r);
91  if (x_r < X)
92  rho_min = rho;
93  else
94  rho_max = rho;
95  }
96  lower_ = rho;
97 
98  // Binary search for the largest rho whose acceptance set has left
99  // endpoint X; this is the upper endpoint of the rho interval.
100  rho_min = 0; rho_max = 1;
101  while (std::fabs(rho_max - rho_min) > tol) {
102  rho = (rho_min + rho_max)/2;
103  find_rho_set(rho, int(n), x_l, x_r);
104  if (x_l > X)
105  rho_max = rho;
106  else
107  rho_min = rho;
108  }
109  upper_ = rho;
110  }
bool find_rho_set(const double rho, const int ntot, int &x_l, int &x_r) const
#define X(str)
Definition: MuonsGrabber.cc:48
template<typename Sorter>
bool BinomialNoncentralInterval< Sorter >::find_rho_set ( const double  rho,
const int  ntot,
int &  x_l,
int &  x_r 
) const
inline

Definition at line 35 of file BinomialNoncentralInterval.h.

Referenced by BinomialNoncentralInterval< FeldmanCousinsSorter >::calculate(), and BinomialNoncentralInterval< FeldmanCousinsSorter >::neyman().

35  {
36  // Get the binomial probabilities for every x = 0..n, and sort them
37  // in decreasing order, determined by the Sorter class.
38  std::vector<BinomialProbHelper> probs;
39  for (int i = 0; i <= ntot; ++i)
40  probs.push_back(BinomialProbHelper(rho, i, ntot));
41  std::sort(probs.begin(), probs.end(), sorter_);
42 
43  // Add up the probabilities until the total is 1 - alpha or
44  // bigger, adding the biggest point first, then the next biggest,
45  // etc. "Biggest" is given by the Sorter class and is taken care
46  // of by the sort above. JMTBAD need to find equal probs and use
47  // the sorter to differentiate between them.
48  const double target = 1 - alpha_;
49  // An invalid interval.
50  x_l = ntot;
51  x_r = 0;
52  double sum = 0;
53  for (int i = 0; i <= ntot && sum < target; ++i) {
54  sum += probs[i].prob();
55  const int& x = probs[i].x();
56  if (x < x_l) x_l = x;
57  if (x > x_r) x_r = x;
58  }
59 
60  return x_l <= x_r;
61  }
template<typename Sorter>
bool BinomialNoncentralInterval< Sorter >::neyman ( const int  ntot,
const int  nrho,
double *  rho,
double *  x_l,
double *  x_r 
)
inlinevirtual

Reimplemented from BinomialInterval.

Definition at line 65 of file BinomialNoncentralInterval.h.

65  {
66  int xL, xR;
67  for (int i = 0; i < nrho; ++i) {
68  rho[i] = double(i)/nrho;
69  find_rho_set(rho[i], ntot, xL, xR);
70  x_l[i] = xL;
71  x_r[i] = xR;
72  }
73  return true;
74  }
bool find_rho_set(const double rho, const int ntot, int &x_l, int &x_r) const

Member Data Documentation

template<typename Sorter>
Sorter BinomialNoncentralInterval< Sorter >::sorter_
private