CMS 3D CMS Logo

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

◆ ModeStatus

Constructor & Destructor Documentation

◆ GaussianSumUtilities1D()

GaussianSumUtilities1D::GaussianSumUtilities1D ( const MultiGaussianState1D state)
inline

Definition at line 21 of file GaussianSumUtilities1D.h.

◆ ~GaussianSumUtilities1D()

GaussianSumUtilities1D::~GaussianSumUtilities1D ( )
inline

Definition at line 25 of file GaussianSumUtilities1D.h.

25 {}

Member Function Documentation

◆ cdf()

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

value of the c.d.f.

Definition at line 268 of file GaussianSumUtilities1D.cc.

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

268  {
269  double result(0.);
270  size_t s = size();
271  for (unsigned int i = 0; i < s; i++)
273  return result;
274 }
static double gaussInt(double, double, double)
Integrated value of gaussian distribution.
double standardDeviation(unsigned int i) const
standard deviation of a component
unsigned int size() const
number of components
double weight() const
combined weight
double mean() const
combined mean

◆ combinedMean()

double GaussianSumUtilities1D::combinedMean ( ) const
private

Mean value of combined state.

Definition at line 399 of file GaussianSumUtilities1D.cc.

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

399  {
400  double s0(0.);
401  double s1(0.);
402  int s = size();
403  SingleGaussianState1D const* __restrict__ sgv = &components().front();
404  for (int i = 0; i < s; i++)
405  s0 += sgv[i].weight();
406  for (int i = 0; i < s; i++)
407  s1 += sgv[i].weight() * sgv[i].mean();
408  return s1 / s0;
409 }
const std::vector< SingleGaussianState1D > & components() const
components
unsigned int size() const
number of components
double weight() const
combined weight

◆ 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 { return theState.components(); }
const MultiGaussianState1D & theState
const SingleState1dContainer & components() const
access to components

◆ computeMode()

void GaussianSumUtilities1D::computeMode ( ) const
private

calculation of mode

Definition at line 91 of file GaussianSumUtilities1D.cc.

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

Referenced by mode(), and modeIsValid().

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

◆ d1LnPdf() [1/2]

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

first derivative of ln(pdf)

Definition at line 284 of file GaussianSumUtilities1D.cc.

References pdfComponents(), and x.

Referenced by d2LnPdf().

284 { return d1LnPdf(x, pdfComponents(x)); }
std::vector< double > pdfComponents(const double &) const
pdf components
double d1LnPdf(const double &) const
first derivative of ln(pdf)

◆ d1LnPdf() [2/2]

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 365 of file GaussianSumUtilities1D.cc.

References d1Pdf(), f, SiStripPI::min, pdf(), mps_fire::result, and x.

365  {
366  double f = pdf(x, pdfs);
367  double result(d1Pdf(x, pdfs));
369  result /= f;
370  else
371  result = 0.;
372  return result;
373 }
double pdf(unsigned int i, double x) const
pdf of a single component at x
double f[11][100]
double d1Pdf(const double &) const
first derivative of the p.d.f.

◆ d1Pdf() [1/2]

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

first derivative of the p.d.f.

Definition at line 276 of file GaussianSumUtilities1D.cc.

References pdfComponents(), and x.

Referenced by d1LnPdf(), and update().

276 { return d1Pdf(x, pdfComponents(x)); }
std::vector< double > pdfComponents(const double &) const
pdf components
double d1Pdf(const double &) const
first derivative of the p.d.f.

◆ d1Pdf() [2/2]

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 327 of file GaussianSumUtilities1D.cc.

References PVValHelper::dx, mps_fire::i, mean(), mps_fire::result, alignCSCRings::s, size(), standardDeviation(), and x.

327  {
328  double result(0.);
329  size_t s = size();
330  for (unsigned int i = 0; i < s; i++) {
331  double dx = (x - mean(i)) / standardDeviation(i);
332  result += -pdfs[i] * dx / standardDeviation(i);
333  }
334  return result;
335 }
double standardDeviation(unsigned int i) const
standard deviation of a component
unsigned int size() const
number of components
double mean() const
combined mean

◆ d2LnPdf() [1/2]

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

second derivative of ln(pdf)

Definition at line 286 of file GaussianSumUtilities1D.cc.

References pdfComponents(), and x.

286 { return d2LnPdf(x, pdfComponents(x)); }
std::vector< double > pdfComponents(const double &) const
pdf components
double d2LnPdf(const double &) const
second derivative of ln(pdf)

◆ d2LnPdf() [2/2]

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 375 of file GaussianSumUtilities1D.cc.

References d1LnPdf(), d2Pdf(), hgcalPerformanceValidation::df, f, SiStripPI::min, pdf(), mps_fire::result, and x.

375  {
376  double f = pdf(x, pdfs);
377  double df = d1LnPdf(x, pdfs);
378  double result(-df * df);
380  result += d2Pdf(x, pdfs) / f;
381  return result;
382 }
double pdf(unsigned int i, double x) const
pdf of a single component at x
double d2Pdf(const double &) const
second derivative of the p.d.f.
double f[11][100]
double d1LnPdf(const double &) const
first derivative of ln(pdf)

◆ d2Pdf() [1/2]

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

second derivative of the p.d.f.

Definition at line 278 of file GaussianSumUtilities1D.cc.

References pdfComponents(), and x.

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

278 { return d2Pdf(x, pdfComponents(x)); }
std::vector< double > pdfComponents(const double &) const
pdf components
double d2Pdf(const double &) const
second derivative of the p.d.f.

◆ d2Pdf() [2/2]

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 337 of file GaussianSumUtilities1D.cc.

References PVValHelper::dx, mps_fire::i, mean(), mps_fire::result, alignCSCRings::s, size(), standardDeviation(), and x.

337  {
338  double result(0.);
339  size_t s = size();
340  for (unsigned int i = 0; i < s; i++) {
341  double dx = (x - mean(i)) / standardDeviation(i);
342  result += pdfs[i] / standardDeviation(i) / standardDeviation(i) * (dx * dx - 1);
343  }
344  return result;
345 }
double standardDeviation(unsigned int i) const
standard deviation of a component
unsigned int size() const
number of components
double mean() const
combined mean

◆ d3Pdf() [1/2]

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

third derivative of the p.d.f.

Definition at line 280 of file GaussianSumUtilities1D.cc.

References pdfComponents(), and x.

280 { return d3Pdf(x, pdfComponents(x)); }
std::vector< double > pdfComponents(const double &) const
pdf components
double d3Pdf(const double &) const
third derivative of the p.d.f.

◆ d3Pdf() [2/2]

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 347 of file GaussianSumUtilities1D.cc.

References PVValHelper::dx, mps_fire::i, mean(), mps_fire::result, alignCSCRings::s, size(), standardDeviation(), and x.

347  {
348  double result(0.);
349  size_t s = size();
350  for (unsigned int i = 0; i < s; i++) {
351  double dx = (x - mean(i)) / standardDeviation(i);
352  result += pdfs[i] / standardDeviation(i) / standardDeviation(i) / standardDeviation(i) * (-dx * dx + 3) * dx;
353  }
354  return result;
355 }
double standardDeviation(unsigned int i) const
standard deviation of a component
unsigned int size() const
number of components
double mean() const
combined mean

◆ findMode()

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 200 of file GaussianSumUtilities1D.cc.

References PVValHelper::dx, SiStripPI::min, mps_fire::result, pfClustersFromCombinedCaloHF_cfi::scale, size(), update(), testProducerWithPsetDescEmpty_cfi::x1, testProducerWithPsetDescEmpty_cfi::x2, TrackerOfflineValidation_Dqm_cff::xmax, TrackerOfflineValidation_Dqm_cff::xmin, and testProducerWithPsetDescEmpty_cfi::y1.

Referenced by computeMode().

200  {
201  //
202  // try with Newton on (lnPdf)'(x)
203  //
204  double x1(0.);
205  double y1(0.);
206  FinderState state(size());
207  update(state, xStart);
208 
209  double xmin(xStart - 1. * scale);
210  double xmax(xStart + 1. * scale);
211  //
212  // preset result
213  //
214  bool result(false);
215  xMode = state.x;
216  yMode = state.y;
217  //
218  // Iterate
219  //
220  int nLoop(0);
221  while (nLoop++ < 20) {
222  if (nLoop > 1 && state.yd2 < 0. &&
223  (fabs(state.yd * scale) < 1.e-10 || fabs(state.y - y1) / (state.y + y1) < 1.e-14)) {
224  result = true;
225  break;
226  }
227  if (fabs(state.yd2) < std::numeric_limits<float>::min())
228  state.yd2 = state.yd2 > 0. ? std::numeric_limits<float>::min() : -std::numeric_limits<float>::min();
229  double dx = -state.yd / state.yd2;
230  x1 = state.x;
231  y1 = state.y;
232  double x2 = x1 + dx;
233  if (state.yd2 > 0. && (x2 < xmin || x2 > xmax))
234  return false;
235  update(state, x2);
236  }
237  //
238  // result
239  //
240  if (result) {
241  xMode = state.x;
242  yMode = state.y;
243  }
244  return result;
245 }
void update(FinderState &state, double x) const
unsigned int size() const
number of components

◆ gauss()

double GaussianSumUtilities1D::gauss ( double  x,
double  mean,
double  sigma 
)
staticprivate

Value of gaussian distribution.

Definition at line 384 of file GaussianSumUtilities1D.cc.

References mean(), and x.

Referenced by pdf(), and pdfComponents().

384  {
385  // const double fNorm(1./sqrt(2*M_PI));
386  // double result(0.);
387 
388  // double d((x-mean)/sigma);
389  // if ( fabs(d)<20. ) result = exp(-d*d/2.);
390  // result *= fNorm/sigma;
391  // return result;
392  return ROOT::Math::gaussian_pdf(x, sigma, mean);
393 }
double mean() const
combined mean

◆ gaussInt()

double GaussianSumUtilities1D::gaussInt ( double  x,
double  mean,
double  sigma 
)
staticprivate

Integrated value of gaussian distribution.

Definition at line 395 of file GaussianSumUtilities1D.cc.

References mean(), and x.

Referenced by cdf().

395  {
396  return ROOT::Math::normal_cdf(x, sigma, mean);
397 }
double mean() const
combined mean

◆ lnPdf() [1/2]

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

ln(pdf)

Definition at line 282 of file GaussianSumUtilities1D.cc.

References pdfComponents(), and x.

282 { return lnPdf(x, pdfComponents(x)); }
std::vector< double > pdfComponents(const double &) const
pdf components
double lnPdf(const double &) const
ln(pdf)

◆ lnPdf() [2/2]

double GaussianSumUtilities1D::lnPdf ( double  x,
const std::vector< double > &  pdfs 
)
staticprivate

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

Definition at line 357 of file GaussianSumUtilities1D.cc.

References f, dqm-mbProfile::log, SiStripPI::max, SiStripPI::min, pdf(), mps_fire::result, and x.

357  {
358  double f(pdf(x, pdfs));
361  result = log(f);
362  return result;
363 }
double pdf(unsigned int i, double x) const
pdf of a single component at x
double f[11][100]

◆ localVariance()

double GaussianSumUtilities1D::localVariance ( double  x) const
private

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

Definition at line 411 of file GaussianSumUtilities1D.cc.

References d2Pdf(), pdf(), pdfComponents(), mps_fire::result, and x.

Referenced by computeMode().

411  {
412  std::vector<double> pdfs;
413  pdfComponents(x, pdfs);
414  double result = -pdf(x, pdfs) / d2Pdf(x, pdfs);
415  // FIXME: wrong curvature seems to be non-existant but should add a proper recovery
416  if (result < 0.)
417  edm::LogWarning("GaussianSumUtilities") << "1D variance at mode < 0";
418  return result;
419 }
double pdf(unsigned int i, double x) const
pdf of a single component at x
std::vector< double > pdfComponents(const double &) const
pdf components
double d2Pdf(const double &) const
second derivative of the p.d.f.
Log< level::Warning, false > LogWarning

◆ mean() [1/2]

double GaussianSumUtilities1D::mean ( unsigned int  i) const
inline

mean value of a component

Definition at line 34 of file GaussianSumUtilities1D.h.

References components(), and mps_fire::i.

Referenced by multiTrajectoryStateMode::momentumFromModePPhiEta().

34 { return components()[i].mean(); }
const std::vector< SingleGaussianState1D > & components() const
components

◆ mean() [2/2]

double GaussianSumUtilities1D::mean ( ) const
inline

combined mean

Definition at line 71 of file GaussianSumUtilities1D.h.

References MultiGaussianState1D::mean(), and theState.

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

71 { return theState.mean(); }
const MultiGaussianState1D & theState
double mean() const
combined mean

◆ mode()

const SingleGaussianState1D & GaussianSumUtilities1D::mode ( void  ) const

◆ modeIsValid()

bool GaussianSumUtilities1D::modeIsValid ( ) const

◆ pdf() [1/3]

double GaussianSumUtilities1D::pdf ( unsigned int  i,
double  x 
) const

pdf of a single component at x

Definition at line 21 of file GaussianSumUtilities1D.cc.

References gauss(), mps_fire::i, mean(), standardDeviation(), weight(), and x.

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

21  {
22  return weight(i) * gauss(x, mean(i), standardDeviation(i));
23 }
static double gauss(double, double, double)
Value of gaussian distribution.
double standardDeviation(unsigned int i) const
standard deviation of a component
double weight() const
combined weight
double mean() const
combined mean

◆ pdf() [2/3]

double GaussianSumUtilities1D::pdf ( double  x) const

value of the p.d.f.

Definition at line 260 of file GaussianSumUtilities1D.cc.

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

260  {
261  double result(0.);
262  size_t s = size();
263  for (unsigned int i = 0; i < s; i++)
264  result += pdf(i, x);
265  return result;
266 }
double pdf(unsigned int i, double x) const
pdf of a single component at x
unsigned int size() const
number of components

◆ pdf() [3/3]

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 323 of file GaussianSumUtilities1D.cc.

323  {
324  return std::accumulate(pdfs.begin(), pdfs.end(), 0.);
325 }

◆ pdfComponents() [1/2]

std::vector< double > GaussianSumUtilities1D::pdfComponents ( const double &  x) const
private

pdf components

Definition at line 288 of file GaussianSumUtilities1D.cc.

References gauss(), mps_fire::i, mean(), mps_fire::result, size(), standardDeviation(), and x.

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

288  {
289  std::vector<double> result;
290  result.reserve(size());
291  for (unsigned int i = 0; i < size(); i++)
292  result.push_back(weight(i) * gauss(x, mean(i), standardDeviation(i)));
293  return result;
294 }
static double gauss(double, double, double)
Value of gaussian distribution.
Definition: weight.py:1
double standardDeviation(unsigned int i) const
standard deviation of a component
unsigned int size() const
number of components
double mean() const
combined mean

◆ pdfComponents() [2/2]

void GaussianSumUtilities1D::pdfComponents ( double  x,
std::vector< double > &  result 
) const
private

pdf components

Definition at line 305 of file GaussianSumUtilities1D.cc.

References components(), mps_fire::end, ExhumeParameters_cfi::PDF, mps_fire::result, alignCSCRings::s, size(), HcalDetIdTransform::transform(), and x.

305  {
306  size_t s = size();
307  if (s != result.size())
308  result.resize(s);
309  std::transform(components().begin(), components().end(), result.begin(), PDF(x));
310 }
const std::vector< SingleGaussianState1D > & components() const
components
unsigned int size() const
number of components
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ quantile()

double GaussianSumUtilities1D::quantile ( const double  q) const

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

Definition at line 25 of file GaussianSumUtilities1D.cc.

References submitPVResolutionJobs::q.

25 { return ROOT::Math::gaussian_quantile(q, 1.); }

◆ size()

unsigned int GaussianSumUtilities1D::size ( void  ) const
inline

number of components

Definition at line 28 of file GaussianSumUtilities1D.h.

References components().

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), cdf(), combinedMean(), computeMode(), d1Pdf(), d2Pdf(), d3Pdf(), findMode(), pdf(), and pdfComponents().

28 { return components().size(); }
const std::vector< SingleGaussianState1D > & components() const
components

◆ standardDeviation()

double GaussianSumUtilities1D::standardDeviation ( unsigned int  i) const
inline

standard deviation of a component

Definition at line 36 of file GaussianSumUtilities1D.h.

References components(), and mps_fire::i.

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

36  {
37  // return sqrt(components()[i].variance());
38  return components()[i].standardDeviation();
39  }
const std::vector< SingleGaussianState1D > & components() const
components

◆ update()

void GaussianSumUtilities1D::update ( FinderState state,
double  x 
) const
private

Definition at line 247 of file GaussianSumUtilities1D.cc.

References d1Pdf(), d2Pdf(), SiStripPI::min, pdf(), pdfComponents(), and x.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), findMode(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

247  {
248  state.x = x;
249 
250  pdfComponents(state.x, state.pdfs);
251  state.y = pdf(state.x, state.pdfs);
252  state.yd = 0;
254  state.yd = d1Pdf(state.x, state.pdfs) / state.y;
255  state.yd2 = -state.yd * state.yd;
257  state.yd2 += d2Pdf(state.x, state.pdfs) / state.y;
258 }
double pdf(unsigned int i, double x) const
pdf of a single component at x
std::vector< double > pdfComponents(const double &) const
pdf components
double d2Pdf(const double &) const
second derivative of the p.d.f.
double d1Pdf(const double &) const
first derivative of the p.d.f.

◆ variance() [1/2]

double GaussianSumUtilities1D::variance ( unsigned int  i) const
inline

variance of a component

Definition at line 41 of file GaussianSumUtilities1D.h.

References components(), and mps_fire::i.

41 { return components()[i].variance(); }
const std::vector< SingleGaussianState1D > & components() const
components

◆ variance() [2/2]

double GaussianSumUtilities1D::variance ( ) const
inline

combined covariance

Definition at line 73 of file GaussianSumUtilities1D.h.

References theState, and MultiGaussianState1D::variance().

Referenced by computeMode().

73 { return theState.variance(); }
const MultiGaussianState1D & theState
double variance() const
combined variance

◆ weight() [1/2]

double GaussianSumUtilities1D::weight ( unsigned int  i) const
inline

weight of a component

Definition at line 32 of file GaussianSumUtilities1D.h.

References components(), and mps_fire::i.

32 { return components()[i].weight(); }
const std::vector< SingleGaussianState1D > & components() const
components

◆ weight() [2/2]

double GaussianSumUtilities1D::weight ( ) const
inline

combined weight

Definition at line 69 of file GaussianSumUtilities1D.h.

References theState, and MultiGaussianState1D::weight().

Referenced by cdf(), combinedMean(), computeMode(), and pdf().

69 { return theState.weight(); }
double weight() const
combined weight
const MultiGaussianState1D & theState

Member Data Documentation

◆ theMode

SingleGaussianState1D GaussianSumUtilities1D::theMode
mutableprivate

Definition at line 130 of file GaussianSumUtilities1D.h.

Referenced by computeMode(), and mode().

◆ theModeStatus

ModeStatus GaussianSumUtilities1D::theModeStatus
mutableprivate

Definition at line 129 of file GaussianSumUtilities1D.h.

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

◆ theState

const MultiGaussianState1D& GaussianSumUtilities1D::theState
private

Definition at line 126 of file GaussianSumUtilities1D.h.

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