yat  0.21pre
NegativeBinomialExtendedMixture.h
1 #ifndef theplu_yat_statistics_negative_binomial_extended_mixture_
2 #define theplu_yat_statistics_negative_binomial_extended_mixture_
3 
4 // $Id: NegativeBinomialExtendedMixture.h 4192 2022-08-11 07:35:35Z peter $
5 
6 /*
7  Copyright (C) 2022 Peter Johansson
8 
9  This file is part of the yat library, https://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <https://www.gnu.org/licenses/>.
23 */
24 
25 #include <yat/utility/MultiMinimizerDerivative.h>
26 #include <yat/utility/Vector.h>
27 
28 #include <vector>
29 
30 namespace theplu {
31 namespace yat {
32  namespace utility {
33  class Matrix;
34  class MultiMinimizerDerivative;
35  }
36 namespace statistics {
37 
50  {
51  public:
59  void add(unsigned long int k, double y);
60 
64  const utility::Vector& alpha(void) const;
65 
69  void clear(void);
70 
74  void fit(size_t n);
75 
80  void fit(const utility::VectorBase& m,
82  const utility::VectorBase& tau);
83 
87  double logL(void) const;
88 
94  const utility::Vector& m(void) const;
95 
101  const utility::Vector& tau(void) const;
102  private:
103  std::vector<std::pair<unsigned long int, double>> data_;
104 
105  utility::Vector tau_;
106  utility::Vector m_;
107  utility::Vector alpha_;
108 
109  double pdf(unsigned long int k, double m, double alpha) const;
110 
111  // p = (alpha-1.0) / alpha = 1.0 - 1.0/alpha
112  double p(size_t i) const;
113  // r = m*(1-p)/p = m / alpha^2
114  double r(size_t i) const;
115 
116  void init_fit(size_t n);
117  void optimize(void);
118 
119  bool expectation_step(utility::Matrix& H);
120  bool optimize_tau(const utility::Matrix& H);
121  bool optimize_param(const utility::Matrix& H,
123 
124  class Q
125  {
126  public:
127  Q(const std::vector<std::pair<unsigned long int, double>>& data,
128  const yat::utility::VectorBase& h);
129  double operator()(const yat::utility::VectorBase& x);
130  void operator()(const yat::utility::VectorBase& x,
131  yat::utility::VectorMutable& gradient);
132 
133  private:
134  const std::vector<std::pair<unsigned long int, double>>& data_;
135  const yat::utility::VectorBase& h_;
136 
137  double
138  log_L(double m, double alpha, unsigned long int k, double y) const;
139 
140  // return <dlogL/dm, dlogL/dalpha>
142  calc_gradient(double m, double alpha, unsigned long int k,
143  double y) const;
144 
145  double
146  calculate_dp(double p, double r, unsigned long int k) const;
147  double
148  calculate_dr(double p, double r, unsigned long int k) const;
149  };
150 
151  };
152 
153 }}}
154 #endif
The Department of Theoretical Physics namespace as we define it.
void add(unsigned long int k, double y)
Add a data point.
This is the yat interface to GSL vector.
Definition: Vector.h:59
This is the yat interface to GSL vector.
Definition: VectorBase.h:55
Wrapper class around gsl_multimin_fdfminimizer in GSL.
Definition: MultiMinimizerDerivative.h:43
This is the mutable interface to GSL vector.
Definition: VectorMutable.h:56
Interface to GSL matrix.
Definition: Matrix.h:104
Definition: NegativeBinomialExtendedMixture.h:49

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14