Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
CDF Class Reference

#include <histogram.h>

Collaboration diagram for CDF:
Collaboration graph
[legend]

Public Member Functions

void calculateCDF (MultidimArray< double > &V, double probStep=0.005)
 Calculate the CDF of V with a probability step of 0.005 (p is between 0 and 1) More...
 
double getProbability (double x)
 Get the probability Pr{V<=x}. More...
 

Public Attributes

MultidimArray< double > x
 
MultidimArray< double > probXLessThanx
 
double minVal
 
double maxVal
 

Detailed Description

Cumulative density function. This function computes a table with the cumulative density function

Definition at line 365 of file histogram.h.

Member Function Documentation

◆ calculateCDF()

void CDF::calculateCDF ( MultidimArray< double > &  V,
double  probStep = 0.005 
)

Calculate the CDF of V with a probability step of 0.005 (p is between 0 and 1)

Definition at line 258 of file histogram.cpp.

259 {
260  double *ptr=&DIRECT_MULTIDIM_ELEM(V,0);
261  size_t N=MULTIDIM_SIZE(V);
262  std::sort(ptr,ptr+N);
263  minVal = ptr[0];
264  maxVal = ptr[N-1];
265 
266  int Nsteps=(int)round(1.0/probStep);
267  x.resizeNoCopy(Nsteps);
269  int i=0;
270  for (double p=probStep/2; p<1; p+=probStep, i++)
271  {
272  size_t idx=(size_t)round(p*N);
274  A1D_ELEM(x,i)=ptr[idx];
275  }
276 }
#define MULTIDIM_SIZE(v)
MultidimArray< double > probXLessThanx
Definition: histogram.h:369
void resizeNoCopy(const MultidimArray< T1 > &v)
#define A1D_ELEM(v, i)
#define i
#define DIRECT_MULTIDIM_ELEM(v, n)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
int round(double x)
Definition: ap.cpp:7245
double maxVal
Definition: histogram.h:370
MultidimArray< double > x
Definition: histogram.h:368
double minVal
Definition: histogram.h:370

◆ getProbability()

double CDF::getProbability ( double  x)

Get the probability Pr{V<=x}.

Definition at line 280 of file histogram.cpp.

281 {
282  if (xi>maxVal)
283  return 1;
284  else if (xi<minVal)
285  return 0;
286  else
287  {
288  size_t N=XSIZE(x);
289  if (xi<DIRECT_A1D_ELEM(x,0))
291  else if (xi>DIRECT_A1D_ELEM(x,N-1))
293  else
294  {
295  int iLeft=0;
296  int iRight=N-1;
297  while (iLeft<=iRight)
298  {
299  int iMiddle = iLeft+(iRight-iLeft)/2;
300  if (xi>=DIRECT_A1D_ELEM(x,iMiddle) && xi<=DIRECT_A1D_ELEM(x,iMiddle+1))
301  {
302  if (DIRECT_A1D_ELEM(x,iMiddle)==DIRECT_A1D_ELEM(x,iMiddle+1))
303  return 0.5*(DIRECT_A1D_ELEM(probXLessThanx,iMiddle)+DIRECT_A1D_ELEM(probXLessThanx,iMiddle+1));
304  else
305  return INTERP(xi,DIRECT_A1D_ELEM(x,iMiddle), DIRECT_A1D_ELEM(probXLessThanx,iMiddle),
306  DIRECT_A1D_ELEM(x,iMiddle+1),DIRECT_A1D_ELEM(probXLessThanx,iMiddle+1));
307  }
308  else if (xi<DIRECT_A1D_ELEM(x,iMiddle))
309  iRight=iMiddle;
310  else
311  iLeft=iMiddle;
312  }
313  // std::cout << "It should never reach here" << std::endl;
314  }
315  }
316  return 0.0;
317 }
double xi
MultidimArray< double > probXLessThanx
Definition: histogram.h:369
#define DIRECT_A1D_ELEM(v, i)
#define INTERP(x, x0, y0, xF, yF)
Definition: histogram.cpp:278
#define XSIZE(v)
double maxVal
Definition: histogram.h:370
MultidimArray< double > x
Definition: histogram.h:368
double minVal
Definition: histogram.h:370

Member Data Documentation

◆ maxVal

double CDF::maxVal

Definition at line 370 of file histogram.h.

◆ minVal

double CDF::minVal

Definition at line 370 of file histogram.h.

◆ probXLessThanx

MultidimArray<double> CDF::probXLessThanx

Definition at line 369 of file histogram.h.

◆ x

MultidimArray<double> CDF::x

Definition at line 368 of file histogram.h.


The documentation for this class was generated from the following files: