npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
GaussianMixtureEntry.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_GAUSSIANMIXTUREENTRY_HH_
2 #define NPSTAT_GAUSSIANMIXTUREENTRY_HH_
3 
4 /*!
5 // \file GaussianMixtureEntry.hh
6 //
7 // \brief A helper class for constructing one-dimensional Gaussian mixtures
8 //
9 // Author: I. Volobouev
10 //
11 // October 2011
12 */
13 
14 #include <stdexcept>
15 
16 #include "geners/ClassId.hh"
17 
18 namespace npstat {
19  class GaussianMixture1D;
20 
21  /** A Gaussian mixture component */
23  {
24  public:
25  inline GaussianMixtureEntry() : w_(0.0), mean_(0.0), stdev_(1.0) {}
26 
27  /** Constructor arguments are weight, mean, and standard deviation */
28  inline GaussianMixtureEntry(const double w, const double mean,
29  const double stdev)
30  : w_(w), mean_(mean), stdev_(stdev)
31  {
32  if (w_ < 0.0) throw std::invalid_argument(
33  "In npstat::GaussianMixtureEntry constructor: "
34  "component weight must be non-negative");
35  if (w_ > 0.0 && stdev_ <= 0.0) throw std::invalid_argument(
36  "In npstat::GaussianMixtureEntry constructor: "
37  "standard deviation must be positive");
38  }
39 
40  //@{
41  /** Examine object properties */
42  inline double weight() const {return w_;}
43  inline double mean() const {return mean_;}
44  inline double stdev() const {return stdev_;}
45  //@}
46 
47  bool operator==(const GaussianMixtureEntry& r) const;
48  inline bool operator!=(const GaussianMixtureEntry& r) const
49  {return !(*this == r);}
50 
51  //@{
52  /** Method needed for "geners" I/O */
53  inline gs::ClassId classId() const {return gs::ClassId(*this);}
54  bool write(std::ostream& os) const;
55  //@}
56 
57  static inline const char* classname()
58  {return "npstat::GaussianMixtureEntry";}
59  static inline unsigned version() {return 1;}
60  static void restore(const gs::ClassId& id, std::istream& in,
61  GaussianMixtureEntry* entry);
62  private:
63  friend class GaussianMixture1D;
64 
65  double w_;
66  double mean_;
67  double stdev_;
68  };
69 }
70 
71 #endif // NPSTAT_GAUSSIANMIXTUREENTRY_HH_
Definition: GaussianMixtureEntry.hh:23
gs::ClassId classId() const
Definition: GaussianMixtureEntry.hh:53
double weight() const
Definition: GaussianMixtureEntry.hh:42
GaussianMixtureEntry(const double w, const double mean, const double stdev)
Definition: GaussianMixtureEntry.hh:28
Definition: AbsArrayProjector.hh:14