CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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.

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

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

268  {
269  double result(0.);
270  size_t s = size();
271  for (unsigned int i = 0; i < s; i++)
273  return result;
274 }
double weight() const
combined weight
unsigned int size() const
number of components
tuple result
Definition: mps_fire.py:311
static double gaussInt(double, double, double)
Integrated value of gaussian distribution.
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
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 }
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 { return theState.components(); }
const MultiGaussianState1D & theState
const SingleState1dContainer & components() const
access to components
void GaussianSumUtilities1D::computeMode ( ) const
private

calculation of mode

Definition at line 91 of file GaussianSumUtilities1D.cc.

References components(), alignCSCRings::e, findMode(), 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, 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 weight() const
combined weight
const double w
Definition: UKUtility.cc:23
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:19
double variance() const
combined covariance
const SingleGaussianState1D & mode() const
double pdf(unsigned int i, double x) const
pdf of a single component at x
#define M_PI
double variance() const
combined variance
double mean() const
combined mean
double localVariance(double x) const
double standardDeviation(unsigned int i) const
standard deviation of a component
const std::vector< SingleGaussianState1D > & components() const
components
double GaussianSumUtilities1D::d1LnPdf ( const double &  x) const

first derivative of ln(pdf)

Definition at line 284 of file GaussianSumUtilities1D.cc.

References pdfComponents().

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)
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(), validate-o2o-wbm::f, min(), pdf(), and mps_fire::result.

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 d1Pdf(const double &) const
first derivative of the p.d.f.
tuple result
Definition: mps_fire.py:311
double pdf(unsigned int i, double x) const
pdf of a single component at x
T min(T a, T b)
Definition: MathUtil.h:58
double GaussianSumUtilities1D::d1Pdf ( const double &  x) const

first derivative of the p.d.f.

Definition at line 276 of file GaussianSumUtilities1D.cc.

References pdfComponents().

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.
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(), and standardDeviation().

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 }
unsigned int size() const
number of components
tuple result
Definition: mps_fire.py:311
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
double GaussianSumUtilities1D::d2LnPdf ( const double &  x) const

second derivative of ln(pdf)

Definition at line 286 of file GaussianSumUtilities1D.cc.

References pdfComponents().

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)
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(), isotrackApplyRegressor::df, validate-o2o-wbm::f, min(), pdf(), and mps_fire::result.

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 d2Pdf(const double &) const
second derivative of the p.d.f.
tuple result
Definition: mps_fire.py:311
double pdf(unsigned int i, double x) const
pdf of a single component at x
T min(T a, T b)
Definition: MathUtil.h:58
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 278 of file GaussianSumUtilities1D.cc.

References pdfComponents().

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.
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(), and standardDeviation().

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 }
unsigned int size() const
number of components
tuple result
Definition: mps_fire.py:311
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
double GaussianSumUtilities1D::d3Pdf ( const double &  x) const

third derivative of the p.d.f.

Definition at line 280 of file GaussianSumUtilities1D.cc.

References pdfComponents().

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.
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(), and standardDeviation().

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 }
unsigned int size() const
number of components
tuple result
Definition: mps_fire.py:311
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
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, min(), mps_fire::result, size(), update(), GaussianSumUtilities1D::FinderState::x, hlt_dqm_clientPB-live_cfg::xmax, hlt_dqm_clientPB-live_cfg::xmin, GaussianSumUtilities1D::FinderState::y, GaussianSumUtilities1D::FinderState::yd, and GaussianSumUtilities1D::FinderState::yd2.

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 }
unsigned int size() const
number of components
tuple result
Definition: mps_fire.py:311
T min(T a, T b)
Definition: MathUtil.h:58
void update(FinderState &state, double x) const
double GaussianSumUtilities1D::gauss ( double  x,
double  mean,
double  sigma 
)
staticprivate

Value of gaussian distribution.

Definition at line 384 of file GaussianSumUtilities1D.cc.

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
double GaussianSumUtilities1D::gaussInt ( double  x,
double  mean,
double  sigma 
)
staticprivate

Integrated value of gaussian distribution.

Definition at line 395 of file GaussianSumUtilities1D.cc.

Referenced by cdf().

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

ln(pdf)

Definition at line 282 of file GaussianSumUtilities1D.cc.

References pdfComponents().

282 { return lnPdf(x, pdfComponents(x)); }
std::vector< double > pdfComponents(const double &) const
pdf components
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 357 of file GaussianSumUtilities1D.cc.

References validate-o2o-wbm::f, log, SiStripPI::max, min(), pdf(), and mps_fire::result.

357  {
358  double f(pdf(x, pdfs));
361  result = log(f);
362  return result;
363 }
static std::vector< std::string > checklist log
tuple result
Definition: mps_fire.py:311
double pdf(unsigned int i, double x) const
pdf of a single component at x
T min(T a, T b)
Definition: MathUtil.h:58
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(), and mps_fire::result.

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 }
std::vector< double > pdfComponents(const double &) const
pdf components
double d2Pdf(const double &) const
second derivative of the p.d.f.
tuple result
Definition: mps_fire.py:311
double pdf(unsigned int i, double x) const
pdf of a single component at x
Log< level::Warning, false > LogWarning
double GaussianSumUtilities1D::mean ( unsigned int  i) const
inline
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(), pdf(), and pdfComponents().

71 { return theState.mean(); }
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 21 of file GaussianSumUtilities1D.cc.

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

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

21  {
22  return weight(i) * gauss(x, mean(i), standardDeviation(i));
23 }
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
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, and size().

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 }
unsigned int size() const
number of components
tuple result
Definition: mps_fire.py:311
double pdf(unsigned int i, double x) const
pdf of a single component at x
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 }
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 weight().

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 }
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: mps_fire.py:311
double mean() const
combined mean
double standardDeviation(unsigned int i) const
standard deviation of a component
void GaussianSumUtilities1D::pdfComponents ( double  x,
std::vector< double > &  result 
) const
private

pdf components

Definition at line 305 of file GaussianSumUtilities1D.cc.

References SplitLinear::begin, components(), dataset::end, alignCSCRings::s, size(), and HcalDetIdTransform::transform().

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 }
unsigned int size() const
number of components
tuple result
Definition: mps_fire.py:311
string end
Definition: dataset.py:937
const std::vector< SingleGaussianState1D > & components() const
components
unsigned transform(const HcalDetId &id, unsigned transformCode)
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.

25 { return ROOT::Math::gaussian_quantile(q, 1.); }
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
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
void GaussianSumUtilities1D::update ( FinderState state,
double  x 
) const
private

Definition at line 247 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__(), 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 }
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.
double pdf(unsigned int i, double x) const
pdf of a single component at x
T min(T a, T b)
Definition: MathUtil.h:58
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.

Referenced by GsfTrackProducerBase::fillMode().

41 { return components()[i].variance(); }
const std::vector< SingleGaussianState1D > & components() const
components
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
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
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(), pdf(), and pdfComponents().

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

Member Data Documentation

SingleGaussianState1D GaussianSumUtilities1D::theMode
mutableprivate

Definition at line 130 of file GaussianSumUtilities1D.h.

Referenced by computeMode(), and mode().

ModeStatus GaussianSumUtilities1D::theModeStatus
mutableprivate

Definition at line 129 of file GaussianSumUtilities1D.h.

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

const MultiGaussianState1D& GaussianSumUtilities1D::theState
private

Definition at line 126 of file GaussianSumUtilities1D.h.

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