-
Notifications
You must be signed in to change notification settings - Fork 0
/
moment_sequence.hpp
99 lines (81 loc) · 3.17 KB
/
moment_sequence.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Copyright (C) 2013 University of Southern California and
* Andrew D. Smith and Timothy Daley
*
* Authors: Andrew D. Smith and Timothy Daley
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOMENT_SEQUENCE_HPP
#define MOMENT_SEQUENCE_HPP
#include <vector>
#include <numeric>
// test Hankel moment matrix to ensure the moment sequence
// is positive definite
size_t ensure_pos_def_mom_seq(std::vector<double> &moments,
const double tolerance,
const bool VERBOSE);
struct MomentSequence {
// Constructors
MomentSequence() {}
MomentSequence(const std::vector<double> &obs_moms);
MomentSequence(const std::vector<double> &a,
const std::vector<double> &b):
alpha(a), beta(b) {};
// Estimate 3-term recurrence
// these will be removed from the header when they are tested
void gw_three_term_calc(const bool VERBOSE, const size_t n_points);
void unmodified_Chebyshev(const bool VERBOSE);
void modified_Chebyshev(const bool VERBOSE,
const size_t n_points,
const std::vector<double> &mod_alpha,
const std::vector<double> &mod_beta,
const std::vector<double> &modified_moments);
void full_3term_recurrence(const bool VERBOSE,
std::vector<double> &full_alpha,
std::vector<double> &full_beta);
// quadrature rules using polynomial solver
void poly_solve_gauss_quad(const size_t n_points,
std::vector<double> &weights,
std::vector<double> &points);
// quadrature rules using QR on Jacobi matrix
bool Lower_quadrature_rules(const bool VERBOSE,
const size_t n_points,
const double tolerance,
const size_t max_iter,
std::vector<double> &points,
std::vector<double> &weights);
bool GaussRadau_quadrature_rules(const bool VERBOSE,
const size_t n_points,
const double tolerance,
const size_t max_iter,
const double fixed_left_end_point,
std::vector<double> &points,
std::vector<double> &weights);
// points are determined assuming data is NegBin distrbuted
// 3-term recurrence is therefore known
// weights are determined by satisfying observed moment conditions
bool NegBin_quadrature_rules(const bool VERBOSE,
const size_t n_points,
const double tolerance,
const size_t max_iter,
const double estimated_mu,
const double estimated_alpha,
std::vector<double> &points,
std::vector<double> &weights);
std::vector<double> moments;
// 3-term recurrence
std::vector<double> alpha;
std::vector<double> beta;
};
#endif