CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
GaussianSumUtilities1D Class Reference

#include <GaussianSumUtilities1D.h>

Classes

struct  FinderState
 

Public Member Functions

double cdf (const double &) const
 value of the c.d.f. More...
 
const std::vector
< SingleGaussianState1D > & 
components () const
 components More...
 
double d1LnPdf (const double &) const
 first derivative of ln(pdf) More...
 
double d1Pdf (const double &) const
 first derivative of the p.d.f. More...
 
double d2LnPdf (const double &) const
 second derivative of ln(pdf) More...
 
double d2Pdf (const double &) const
 second derivative of the p.d.f. More...
 
double d3Pdf (const double &) const
 third derivative of the p.d.f. More...
 
 GaussianSumUtilities1D (const MultiGaussianState1D &state)
 
double lnPdf (const double &) const
 ln(pdf) More...
 
double mean (unsigned int i) const
 mean value of a component More...
 
double mean () const
 combined mean More...
 
const SingleGaussianState1Dmode () const
 
bool modeIsValid () const
 mode status More...
 
double pdf (unsigned int i, double x) const
 pdf of a single component at x More...
 
double pdf (double) const
 value of the p.d.f. More...
 
double quantile (const double) const
 Quantile (i.e. x for a given value of the c.d.f.) More...
 
unsigned int size () const
 number of components More...
 
double standardDeviation (unsigned int i) const
 standard deviation of a component More...
 
double variance (unsigned int i) const
 variance of a component More...
 
double variance () const
 combined covariance More...
 
double weight (unsigned int i) const
 weight of a component More...
 
double weight () const
 combined weight More...
 
 ~GaussianSumUtilities1D ()
 

Private Types

enum  ModeStatus { Valid, NotValid, NotComputed }
 

Private Member Functions

double combinedMean () const
 Mean value of combined state. More...
 
void computeMode () const
 calculation of mode More...
 
double d1LnPdf (double, const std::vector< double > &) const
 first derivative of ln(pdf) using the pdf components at the evaluation point More...
 
double d1Pdf (double, const std::vector< double > &) const
 first derivative of the p.d.f. using the pdf components at the evaluation point More...
 
double d2LnPdf (double, const std::vector< double > &) const
 second derivative of ln(pdf) using the pdf components at the evaluation point More...
 
double d2Pdf (double, const std::vector< double > &) const
 second derivative of the p.d.f. using the pdf components at the evaluation point More...
 
double d3Pdf (double, const std::vector< double > &) const
 third derivative of the p.d.f. using the pdf components at the evaluation point More...
 
bool findMode (double &mode, double &pdfAtMode, const double &xStart, const double &scale) const
 
double localVariance (double x) const
 
std::vector< double > pdfComponents (const double &) const
 pdf components More...
 
void pdfComponents (double, std::vector< double > &) const
 pdf components More...
 
void update (FinderState &state, double x) const
 

Static Private Member Functions

static double gauss (double, double, double)
 Value of gaussian distribution. More...
 
static double gaussInt (double, double, double)
 Integrated value of gaussian distribution. More...
 
static double lnPdf (double, const std::vector< double > &)
 ln(pdf) using the pdf components at the evaluation point More...
 
static double pdf (double, const std::vector< double > &)
 value of the p.d.f. using the pdf components at the evaluation point More...
 

Private Attributes

SingleGaussianState1D theMode
 
ModeStatus theModeStatus
 
const MultiGaussianState1DtheState
 

Detailed Description

Utility class for the analysis of one-dimensional Gaussian mixtures. The input state is assumed to exist for the lifetime of this object.

Definition at line 16 of file GaussianSumUtilities1D.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

GaussianSumUtilities1D::GaussianSumUtilities1D ( const MultiGaussianState1D state)
inline

Definition at line 21 of file GaussianSumUtilities1D.h.

21  :
22  theState(state),
23 // theStates(state.components()),
const MultiGaussianState1D & theState
GaussianSumUtilities1D::~GaussianSumUtilities1D ( )
inline

Definition at line 25 of file GaussianSumUtilities1D.h.

25 {}

Member Function Documentation

double GaussianSumUtilities1D::cdf ( const double &  x) const

value of the c.d.f.

Definition at line 288 of file GaussianSumUtilities1D.cc.

References gaussInt(), i, mean(), query::result, alignCSCRings::s, size(), standardDeviation(), and weight().

289 {
290  double result(0.);
291  size_t s=size();
292  for ( unsigned int i=0; i<s; i++ )
294  return result;
295 }
int i
Definition: DBlmapReader.cc:9
double weight() const
combined weight
unsigned int size() const
number of components
static double gaussInt(double, double, double)
Integrated value of gaussian distribution.
tuple result
Definition: query.py:137
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
Definition: DDAxes.h:10
double GaussianSumUtilities1D::combinedMean ( ) const
private

Mean value of combined state.

Definition at line 463 of file GaussianSumUtilities1D.cc.

References components(), i, alignCSCRings::s, size(), and weight().

464 {
465  double s0(0.);
466  double s1(0.);
467  int s = size();
468  SingleGaussianState1D const * __restrict__ sgv = &components().front();
469  for (int i=0; i<s; i++ )
470  s0 += sgv[i].weight();
471  for (int i=0; i<s; i++ )
472  s1 += sgv[i].weight()*sgv[i].mean();
473  return s1/s0;
474 }
int i
Definition: DBlmapReader.cc:9
double weight() const
combined weight
unsigned int size() const
number of components
const std::vector< SingleGaussianState1D > & components() const
components
const std::vector<SingleGaussianState1D>& GaussianSumUtilities1D::components ( ) const
inline

components

Definition at line 30 of file GaussianSumUtilities1D.h.

References MultiGaussianState1D::components(), and theState.

Referenced by combinedMean(), computeMode(), mean(), pdfComponents(), size(), standardDeviation(), variance(), and weight().

30  {
31  return theState.components();
32  }
const MultiGaussianState1D & theState
const SingleState1dContainer & components() const
access to components
void GaussianSumUtilities1D::computeMode ( ) const
private

calculation of mode

Definition at line 101 of file GaussianSumUtilities1D.cc.

References components(), alignCSCRings::e, findMode(), first, i, localVariance(), M_PI, MultiGaussianState1D::mean(), mean(), mode(), NotValid, pdf(), alignCSCRings::s, edm::second(), size(), mathSSE::sqrt(), standardDeviation(), theMode, theModeStatus, theState, Valid, TrackValidation_HighPurity_cff::valid, MultiGaussianState1D::variance(), variance(), w(), MultiGaussianState1D::weight(), weight(), x, and detailsBasic3DVector::y.

Referenced by mode(), and modeIsValid().

102 {
103 // TimerStack tstack;
104 // tstack.benchmark("GSU1D::benchmark",100000);
105 // FastTimerStackPush(tstack,"GaussianSumUtilities1D::computeMode");
107  //
108  // check for "degenerate" states (identical values with vanishing error)
109  //
110  if ( theState.variance()<1.e-14 ) {
112  theState.weight());
114  return;
115  }
116  //
117  // Use means of individual components as start values.
118  // Sort by value of pdf.
119  //
120  typedef std::multimap<double, int, std::greater<double> > StartMap;
121  StartMap xStart;
122  for ( unsigned int i=0; i<size(); i++ ) {
123  xStart.insert(std::make_pair(pdf(mean(i)),i));
124  }
125  //
126  // Now try with each start value
127  //
128  int iRes(-1); // index of start component for current estimate
129  double xRes(mean((*xStart.begin()).second)); // current estimate of mode
130  double yRes(-1.); // pdf at current estimate of mode
131 // std::pair<double,double> result(-1.,mean((*xStart.begin()).second));
132  for ( StartMap::const_iterator i=xStart.begin(); i!=xStart.end(); i++ ) {
133  //
134  // Convergence radius for a single Gaussian = 1 sigma: don't try
135  // start values within 1 sigma of the current solution
136  //
137  if ( theModeStatus==Valid &&
138  fabs(mean((*i).second)-mean(iRes))/standardDeviation(iRes)<1. ) continue;
139  //
140  // If a solution exists: drop as soon as the pdf at
141  // start value drops to < 75% of maximum (try to avoid
142  // unnecessary searches for the mode)
143  //
144  if ( theModeStatus==Valid &&
145  (*i).first/(*xStart.begin()).first<0.75 ) break;
146  //
147  // Try to find mode
148  //
149  double x;
150  double y;
151  bool valid = findMode(x,y,mean((*i).second),standardDeviation((*i).second));
152  //
153  // consider only successful searches
154  //
155  if ( valid ) { //...
156  //
157  // update result only for significant changes in pdf(solution)
158  //
159  if ( yRes<0. || (y-yRes)/(y+yRes)>1.e-10 ) {
160  iRes = (*i).second; // store index
161  theModeStatus = Valid; // update status
162  xRes = x; // current solution
163  yRes = y; // and its pdf value
164 // result = std::make_pair(y,x); // store solution and pdf(solution)
165  }
166  } //...
167  }
168  //
169  // check (existance of) solution
170  //
171  if ( theModeStatus== Valid ) {
172  //
173  // Construct single Gaussian state with
174  // mean = mode
175  // variance = local variance at mode
176  // weight such that the pdf's of the mixture and the
177  // single state are equal at the mode
178  //
179  double mode = xRes;
180  double varMode = localVariance(mode);
181  double wgtMode = pdf(mode)*sqrt(2*M_PI*varMode);
182  theMode = SingleGaussianState1D(mode,varMode,wgtMode);
183  }
184  else {
185  //
186  // mode finding failed: set solution to highest component
187  // (alternative would be global mean / variance ..?)
188  //
189  //two many log warnings to actually be useful - comment out
190  //edm::LogWarning("GaussianSumUtilities") << "1D mode calculation failed";
191 // double x = mean();
192 // double y = pdf(x);
193 // result = std::make_pair(y,x);
194 // theMode = SingleGaussianState1D(mean(),variance(),weight());
195  //
196  // look for component with highest value at mean
197  //
198  int icMax(0);
199  double ySqMax(0.);
200  int s = size();
201  for (int ic=0; ic<s; ++ic ) {
202  double w = weight(ic);
203  double ySq = w*w/variance(ic);
204  if ( ySq>ySqMax ) {
205  icMax = ic;
206  ySqMax = ySq;
207  }
208  }
210  }
211 
212 }
int i
Definition: DBlmapReader.cc:9
double weight() const
combined weight
const MultiGaussianState1D & theState
double mean() const
combined mean
double weight() const
combined weight
SingleGaussianState1D theMode
bool findMode(double &mode, double &pdfAtMode, const double &xStart, const double &scale) const
unsigned int size() const
number of components
U second(std::pair< T, U > const &p)
T sqrt(T t)
Definition: SSEVec.h:48
double variance() const
combined covariance
const SingleGaussianState1D & mode() const
double pdf(unsigned int i, double x) const
pdf of a single component at x
bool first
Definition: L1TdeRCT.cc:94
double variance() const
combined variance
double mean() const
combined mean
#define M_PI
Definition: BFit3D.cc:3
double localVariance(double x) const
double standardDeviation(unsigned int i) const
standard deviation of a component
T w() const
Definition: DDAxes.h:10
const std::vector< SingleGaussianState1D > & components() const
components
double GaussianSumUtilities1D::d1LnPdf ( const double &  x) const

first derivative of ln(pdf)

Definition at line 322 of file GaussianSumUtilities1D.cc.

References pdfComponents().

Referenced by d2LnPdf().

323 {
324  return d1LnPdf(x,pdfComponents(x));
325 }
std::vector< double > pdfComponents(const double &) const
pdf components
Definition: DDAxes.h:10
double d1LnPdf(const double &) const
first derivative of ln(pdf)
double GaussianSumUtilities1D::d1LnPdf ( double  x,
const std::vector< double > &  pdfs 
) const
private

first derivative of ln(pdf) using the pdf components at the evaluation point

Definition at line 422 of file GaussianSumUtilities1D.cc.

References d1Pdf(), f, min, pdf(), and query::result.

423 {
424 
425  double f = pdf(x,pdfs);
426  double result(d1Pdf(x,pdfs));
428  else result = 0.;
429  return result;
430 }
#define min(a, b)
Definition: mlp_lapack.h:161
double d1Pdf(const double &) const
first derivative of the p.d.f.
tuple result
Definition: query.py:137
double f[11][100]
double pdf(unsigned int i, double x) const
pdf of a single component at x
Definition: DDAxes.h:10
double GaussianSumUtilities1D::d1Pdf ( const double &  x) const

first derivative of the p.d.f.

Definition at line 298 of file GaussianSumUtilities1D.cc.

References pdfComponents().

Referenced by d1LnPdf(), and update().

299 {
300  return d1Pdf(x,pdfComponents(x));
301 }
std::vector< double > pdfComponents(const double &) const
pdf components
double d1Pdf(const double &) const
first derivative of the p.d.f.
Definition: DDAxes.h:10
double GaussianSumUtilities1D::d1Pdf ( double  x,
const std::vector< double > &  pdfs 
) const
private

first derivative of the p.d.f. using the pdf components at the evaluation point

Definition at line 376 of file GaussianSumUtilities1D.cc.

References i, mean(), query::result, alignCSCRings::s, size(), and standardDeviation().

377 {
378  double result(0.);
379  size_t s=size();
380  for ( unsigned int i=0; i<s; i++ ) {
381  double dx = (x-mean(i))/standardDeviation(i);
382  result += -pdfs[i]*dx/standardDeviation(i);
383  }
384  return result;
385 }
int i
Definition: DBlmapReader.cc:9
unsigned int size() const
number of components
tuple result
Definition: query.py:137
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
Definition: DDAxes.h:10
double GaussianSumUtilities1D::d2LnPdf ( const double &  x) const

second derivative of ln(pdf)

Definition at line 328 of file GaussianSumUtilities1D.cc.

References pdfComponents().

329 {
330  return d2LnPdf(x,pdfComponents(x));
331 }
std::vector< double > pdfComponents(const double &) const
pdf components
double d2LnPdf(const double &) const
second derivative of ln(pdf)
Definition: DDAxes.h:10
double GaussianSumUtilities1D::d2LnPdf ( double  x,
const std::vector< double > &  pdfs 
) const
private

second derivative of ln(pdf) using the pdf components at the evaluation point

Definition at line 433 of file GaussianSumUtilities1D.cc.

References d1LnPdf(), d2Pdf(), f, min, pdf(), and query::result.

434 {
435 
436  double f = pdf(x,pdfs);
437  double df = d1LnPdf(x,pdfs);
438  double result(-df*df);
439  if ( f>std::numeric_limits<double>::min() ) result += d2Pdf(x,pdfs)/f;
440  return result;
441 }
double d2Pdf(const double &) const
second derivative of the p.d.f.
#define min(a, b)
Definition: mlp_lapack.h:161
tuple result
Definition: query.py:137
double f[11][100]
double pdf(unsigned int i, double x) const
pdf of a single component at x
Definition: DDAxes.h:10
double d1LnPdf(const double &) const
first derivative of ln(pdf)
double GaussianSumUtilities1D::d2Pdf ( const double &  x) const

second derivative of the p.d.f.

Definition at line 304 of file GaussianSumUtilities1D.cc.

References pdfComponents().

Referenced by d2LnPdf(), localVariance(), and update().

305 {
306  return d2Pdf(x,pdfComponents(x));
307 }
std::vector< double > pdfComponents(const double &) const
pdf components
double d2Pdf(const double &) const
second derivative of the p.d.f.
Definition: DDAxes.h:10
double GaussianSumUtilities1D::d2Pdf ( double  x,
const std::vector< double > &  pdfs 
) const
private

second derivative of the p.d.f. using the pdf components at the evaluation point

Definition at line 388 of file GaussianSumUtilities1D.cc.

References i, mean(), query::result, alignCSCRings::s, size(), and standardDeviation().

389 {
390  double result(0.);
391  size_t s=size();
392  for ( unsigned int i=0; i<s; i++ ) {
393  double dx = (x-mean(i))/standardDeviation(i);
394  result += pdfs[i]/standardDeviation(i)/standardDeviation(i)*(dx*dx-1);
395  }
396  return result;
397 }
int i
Definition: DBlmapReader.cc:9
unsigned int size() const
number of components
tuple result
Definition: query.py:137
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
Definition: DDAxes.h:10
double GaussianSumUtilities1D::d3Pdf ( const double &  x) const

third derivative of the p.d.f.

Definition at line 310 of file GaussianSumUtilities1D.cc.

References pdfComponents().

311 {
312  return d3Pdf(x,pdfComponents(x));
313 }
std::vector< double > pdfComponents(const double &) const
pdf components
double d3Pdf(const double &) const
third derivative of the p.d.f.
Definition: DDAxes.h:10
double GaussianSumUtilities1D::d3Pdf ( double  x,
const std::vector< double > &  pdfs 
) const
private

third derivative of the p.d.f. using the pdf components at the evaluation point

Definition at line 400 of file GaussianSumUtilities1D.cc.

References i, mean(), query::result, alignCSCRings::s, size(), and standardDeviation().

401 {
402  double result(0.);
403  size_t s=size();
404  for ( unsigned int i=0; i<s; i++ ) {
405  double dx = (x-mean(i))/standardDeviation(i);
407  (-dx*dx+3)*dx;
408  }
409  return result;
410 }
int i
Definition: DBlmapReader.cc:9
unsigned int size() const
number of components
tuple result
Definition: query.py:137
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
Definition: DDAxes.h:10
bool GaussianSumUtilities1D::findMode ( double &  mode,
double &  pdfAtMode,
const double &  xStart,
const double &  scale 
) const
private

Finds mode. Input: start value and typical scale. Output: mode and pdf(mode). Return value is true on success.

Definition at line 215 of file GaussianSumUtilities1D.cc.

References min, query::result, size(), evf::utils::state, update(), GaussianSumUtilities1D::FinderState::x, SiStripMonitorClusterAlca_cfi::xmax, SiStripMonitorClusterAlca_cfi::xmin, GaussianSumUtilities1D::FinderState::y, GaussianSumUtilities1D::FinderState::yd, and GaussianSumUtilities1D::FinderState::yd2.

Referenced by computeMode().

218 {
219  //
220  // try with Newton on (lnPdf)'(x)
221  //
222  double x1(0.);
223  double y1(0.);
224  FinderState state(size());
225  update(state,xStart);
226 
227  double xmin(xStart-1.*scale);
228  double xmax(xStart+1.*scale);
229  //
230  // preset result
231  //
232  bool result(false);
233  xMode = state.x;
234  yMode = state.y;
235  //
236  // Iterate
237  //
238  int nLoop(0);
239  while ( nLoop++<20 ) {
240  if ( nLoop>1 && state.yd2<0. &&
241  ( fabs(state.yd*scale)<1.e-10 || fabs(state.y-y1)/(state.y+y1)<1.e-14 ) ) {
242  result = true;
243  break;
244  }
245  if ( fabs(state.yd2)<std::numeric_limits<float>::min() )
246  state.yd2 = state.yd2>0. ? std::numeric_limits<float>::min() : -std::numeric_limits<float>::min();
247  double dx = -state.yd/state.yd2;
248  x1 = state.x;
249  y1 = state.y;
250  double x2 = x1 + dx;
251  if ( state.yd2>0. && (x2<xmin||x2>xmax) ) return false;
252  update(state,x2);
253  }
254  //
255  // result
256  //
257  if ( result ) {
258  xMode = state.x;
259  yMode = state.y;
260  }
261  return result;
262 }
#define min(a, b)
Definition: mlp_lapack.h:161
unsigned int size() const
number of components
tuple result
Definition: query.py:137
char state
Definition: procUtils.cc:75
void update(FinderState &state, double x) const
double GaussianSumUtilities1D::gauss ( double  x,
double  mean,
double  sigma 
)
staticprivate

Value of gaussian distribution.

Definition at line 444 of file GaussianSumUtilities1D.cc.

Referenced by pdf(), and pdfComponents().

445 {
446 // const double fNorm(1./sqrt(2*M_PI));
447 // double result(0.);
448 
449 // double d((x-mean)/sigma);
450 // if ( fabs(d)<20. ) result = exp(-d*d/2.);
451 // result *= fNorm/sigma;
452 // return result;
453  return ROOT::Math::gaussian_pdf(x,sigma,mean);
454 }
double mean() const
combined mean
Definition: DDAxes.h:10
double GaussianSumUtilities1D::gaussInt ( double  x,
double  mean,
double  sigma 
)
staticprivate

Integrated value of gaussian distribution.

Definition at line 457 of file GaussianSumUtilities1D.cc.

Referenced by cdf().

458 {
459  return ROOT::Math::normal_cdf(x,sigma,mean);
460 }
double mean() const
combined mean
Definition: DDAxes.h:10
double GaussianSumUtilities1D::lnPdf ( const double &  x) const

ln(pdf)

Definition at line 316 of file GaussianSumUtilities1D.cc.

References pdfComponents().

317 {
318  return lnPdf(x,pdfComponents(x));
319 }
std::vector< double > pdfComponents(const double &) const
pdf components
Definition: DDAxes.h:10
double lnPdf(const double &) const
ln(pdf)
double GaussianSumUtilities1D::lnPdf ( double  x,
const std::vector< double > &  pdfs 
)
staticprivate

ln(pdf) using the pdf components at the evaluation point

Definition at line 413 of file GaussianSumUtilities1D.cc.

References f, create_public_lumi_plots::log, max(), min, pdf(), and query::result.

414 {
415  double f(pdf(x,pdfs));
418  return result;
419 }
#define min(a, b)
Definition: mlp_lapack.h:161
const T & max(const T &a, const T &b)
tuple result
Definition: query.py:137
double f[11][100]
double pdf(unsigned int i, double x) const
pdf of a single component at x
Definition: DDAxes.h:10
double GaussianSumUtilities1D::localVariance ( double  x) const
private

Local variance from Hessian matrix. Only valid if x corresponds to a (local) maximum!

Definition at line 477 of file GaussianSumUtilities1D.cc.

References d2Pdf(), pdf(), pdfComponents(), and query::result.

Referenced by computeMode().

478 {
479  std::vector<double> pdfs;
480  pdfComponents(x,pdfs);
481  double result = -pdf(x,pdfs)/d2Pdf(x,pdfs);
482  // FIXME: wrong curvature seems to be non-existant but should add a proper recovery
483  if ( result<0. )
484  edm::LogWarning("GaussianSumUtilities") << "1D variance at mode < 0";
485  return result;
486 }
std::vector< double > pdfComponents(const double &) const
pdf components
double d2Pdf(const double &) const
second derivative of the p.d.f.
tuple result
Definition: query.py:137
double pdf(unsigned int i, double x) const
pdf of a single component at x
Definition: DDAxes.h:10
double GaussianSumUtilities1D::mean ( unsigned int  i) const
inline
double GaussianSumUtilities1D::mean ( ) const
inline

combined mean

Definition at line 75 of file GaussianSumUtilities1D.h.

References MultiGaussianState1D::mean(), and theState.

Referenced by cdf(), computeMode(), d1Pdf(), d2Pdf(), d3Pdf(), pdf(), and pdfComponents().

75  {
76  return theState.mean();
77  }
const MultiGaussianState1D & theState
double mean() const
combined mean
const SingleGaussianState1D & GaussianSumUtilities1D::mode ( void  ) const
bool GaussianSumUtilities1D::modeIsValid ( ) const
double GaussianSumUtilities1D::pdf ( unsigned int  i,
double  x 
) const

pdf of a single component at x

Definition at line 22 of file GaussianSumUtilities1D.cc.

References gauss(), mean(), standardDeviation(), and weight().

Referenced by computeMode(), d1LnPdf(), d2LnPdf(), lnPdf(), localVariance(), pdf(), and update().

22  {
23  return weight(i)*gauss(x,mean(i),standardDeviation(i));
24 }
int i
Definition: DBlmapReader.cc:9
double weight() const
combined weight
static double gauss(double, double, double)
Value of gaussian distribution.
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
Definition: DDAxes.h:10
double GaussianSumUtilities1D::pdf ( double  x) const

value of the p.d.f.

Definition at line 278 of file GaussianSumUtilities1D.cc.

References i, pdf(), query::result, alignCSCRings::s, and size().

279 {
280  double result(0.);
281  size_t s=size();
282  for ( unsigned int i=0; i<s; i++ )
283  result += pdf(i,x);
284  return result;
285 }
int i
Definition: DBlmapReader.cc:9
unsigned int size() const
number of components
tuple result
Definition: query.py:137
double pdf(unsigned int i, double x) const
pdf of a single component at x
Definition: DDAxes.h:10
double GaussianSumUtilities1D::pdf ( double  ,
const std::vector< double > &  pdfs 
)
staticprivate

value of the p.d.f. using the pdf components at the evaluation point

Definition at line 370 of file GaussianSumUtilities1D.cc.

371 {
372  return std::accumulate(pdfs.begin(),pdfs.end(),0.);
373 }
std::vector< double > GaussianSumUtilities1D::pdfComponents ( const double &  x) const
private

pdf components

Definition at line 334 of file GaussianSumUtilities1D.cc.

References gauss(), i, mean(), query::result, size(), standardDeviation(), and weight().

Referenced by d1LnPdf(), d1Pdf(), d2LnPdf(), d2Pdf(), d3Pdf(), lnPdf(), localVariance(), and update().

335 {
336  std::vector<double> result;
337  result.reserve(size());
338  for ( unsigned int i=0; i<size(); i++ )
339  result.push_back(weight(i)*gauss(x,mean(i),standardDeviation(i)));
340  return result;
341 }
int i
Definition: DBlmapReader.cc:9
double weight() const
combined weight
static double gauss(double, double, double)
Value of gaussian distribution.
unsigned int size() const
number of components
tuple result
Definition: query.py:137
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
Definition: DDAxes.h:10
void GaussianSumUtilities1D::pdfComponents ( double  x,
std::vector< double > &  result 
) const
private

pdf components

Definition at line 352 of file GaussianSumUtilities1D.cc.

References begin, components(), end, alignCSCRings::s, size(), and create_public_pileup_plots::transform.

352  {
353  size_t s = size();
354  if (s!=result.size()) result.resize(s);
355  std::transform(components().begin(),components().end(),result.begin(),PDF(x));
356 }
unsigned int size() const
number of components
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:38
#define begin
Definition: vmac.h:31
Definition: DDAxes.h:10
const std::vector< SingleGaussianState1D > & components() const
components
double GaussianSumUtilities1D::quantile ( const double  q) const

Quantile (i.e. x for a given value of the c.d.f.)

Definition at line 28 of file GaussianSumUtilities1D.cc.

29 {
30  return ROOT::Math::gaussian_quantile(q,1.);
31 }
unsigned int GaussianSumUtilities1D::size ( void  ) const
inline

number of components

Definition at line 28 of file GaussianSumUtilities1D.h.

References components().

Referenced by cdf(), combinedMean(), computeMode(), d1Pdf(), d2Pdf(), d3Pdf(), findMode(), pdf(), and pdfComponents().

28 {return components().size();}
const std::vector< SingleGaussianState1D > & components() const
components
double GaussianSumUtilities1D::standardDeviation ( unsigned int  i) const
inline

standard deviation of a component

Definition at line 38 of file GaussianSumUtilities1D.h.

References components(), and i.

Referenced by cdf(), computeMode(), d1Pdf(), d2Pdf(), d3Pdf(), pdf(), and pdfComponents().

38  {
39 // return sqrt(components()[i].variance());
40  return components()[i].standardDeviation();
41  }
int i
Definition: DBlmapReader.cc:9
const std::vector< SingleGaussianState1D > & components() const
components
void GaussianSumUtilities1D::update ( FinderState state,
double  x 
) const
private

Definition at line 265 of file GaussianSumUtilities1D.cc.

References d1Pdf(), d2Pdf(), min, pdf(), pdfComponents(), GaussianSumUtilities1D::FinderState::pdfs, x, GaussianSumUtilities1D::FinderState::x, GaussianSumUtilities1D::FinderState::y, GaussianSumUtilities1D::FinderState::yd, and GaussianSumUtilities1D::FinderState::yd2.

Referenced by progressbar.ProgressBar::__next__(), relval_steps.Matrix::__setitem__(), relval_steps.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), findMode(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), relval_steps.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

265  {
266  state.x = x;
267 
268  pdfComponents(state.x, state.pdfs);
269  state.y = pdf(state.x, state.pdfs);
270  state.yd = 0;
272  state.yd2 = -state.yd*state.yd;
273  if (state.y > std::numeric_limits<double>::min()) state.yd2 += d2Pdf(state.x,state.pdfs)/state.y;
274 }
std::vector< double > pdfComponents(const double &) const
pdf components
double d2Pdf(const double &) const
second derivative of the p.d.f.
#define min(a, b)
Definition: mlp_lapack.h:161
double d1Pdf(const double &) const
first derivative of the p.d.f.
double pdf(unsigned int i, double x) const
pdf of a single component at x
char state
Definition: procUtils.cc:75
Definition: DDAxes.h:10
double GaussianSumUtilities1D::variance ( unsigned int  i) const
inline

variance of a component

Definition at line 43 of file GaussianSumUtilities1D.h.

References components(), and i.

Referenced by GsfTrackProducerBase::fillMode().

43 {return components()[i].variance();}
int i
Definition: DBlmapReader.cc:9
const std::vector< SingleGaussianState1D > & components() const
components
double GaussianSumUtilities1D::variance ( ) const
inline

combined covariance

Definition at line 79 of file GaussianSumUtilities1D.h.

References theState, and MultiGaussianState1D::variance().

Referenced by computeMode().

79  {
80  return theState.variance();
81  }
const MultiGaussianState1D & theState
double variance() const
combined variance
double GaussianSumUtilities1D::weight ( unsigned int  i) const
inline

weight of a component

Definition at line 34 of file GaussianSumUtilities1D.h.

References components(), and i.

Referenced by cuy.ValElement::__init__(), cuy.additionElement::__init__(), cuy.superimposeElement::__init__(), and cuy.graphElement::__init__().

34 {return components()[i].weight();}
int i
Definition: DBlmapReader.cc:9
const std::vector< SingleGaussianState1D > & components() const
components
double GaussianSumUtilities1D::weight ( void  ) const
inline

Member Data Documentation

SingleGaussianState1D GaussianSumUtilities1D::theMode
mutableprivate

Definition at line 139 of file GaussianSumUtilities1D.h.

Referenced by computeMode(), and mode().

ModeStatus GaussianSumUtilities1D::theModeStatus
mutableprivate

Definition at line 138 of file GaussianSumUtilities1D.h.

Referenced by computeMode(), mode(), and modeIsValid().

const MultiGaussianState1D& GaussianSumUtilities1D::theState
private

Definition at line 135 of file GaussianSumUtilities1D.h.

Referenced by components(), computeMode(), mean(), variance(), and weight().