28 constexpr double gamma = 0.5;
29 constexpr double alpha_star = 0.234;
31 const double m = std::pow(n, -gamma) * (alpha - alpha_star) / slide::norm_sq<2>(w);
32 const double m_root = std::sqrt(std::abs(m));
37 auto I = slide::eye<N>(1.0);
39 slide::cholUpdate<N>(
I, w, m < 0);
41 auto S_new = slide::zeros<N, N>();
43 for (
size_t i = 0; i < w.size(); i++)
44 for (
size_t j = 0; j <= i; j++)
45 for (
size_t o = 0; o <= i; o++)
46 S_new[i][j] += S[i][o] *
I[o][j];
51template <
size_t N_PARAM,
size_t N_OUTPUT = 1>
54 std::array<double, N_PARAM>
param;
55 std::array<double, N_OUTPUT>
logR;
57 auto scale(
const std::array<double, N_PARAM> ¶m_scalar)
const
59 auto param_scaled =
param;
61 for (
size_t i = 0; i < param_scaled.size(); i++)
62 param_scaled[i] *= param_scalar[i];
71 else if (i == N_PARAM)
72 return logR[i - N_PARAM];
74 std::cout <<
"THIS SHOULD NOT HAPPEN out of bounds for MCMC_Input.\n";
83 else if (i == N_PARAM)
84 return logR[i - N_PARAM];
86 std::cout <<
"THIS SHOULD NOT HAPPEN out of bounds for MCMC_Input.\n";
95 auto size()
const {
return N_PARAM + N_OUTPUT; }
100template <
size_t N_PARAM,
size_t N_OUTPUT = 1>
110template <
typename Tdistribution>
117 template <
typename Tparam>
120 for (
const auto b_i : b)
122 return std::pair(-1e25,
false);
125 for (
size_t i = 0; i < b.size(); i++)
128 return std::pair(sum,
true);
138template <
typename ThetaType,
typename PriorType,
typename CostType,
typename SettingsType>
139auto LL(
const ThetaType &theta_cand, PriorType &prior,
const CostType &costFun,
const size_t Nobservations,
const SettingsType &mcmcSettings)
141 auto [P, flag] = prior(theta_cand.param);
146 auto err_sqr = costFun(theta_cand.scale(mcmcSettings.theta_scalar));
148 const auto R_volt_exp = theta_cand.get_R();
150 const double LLout1 = 0.5 * std::log(2.0 *
PhyConst::pi * R_volt_exp) * Nobservations;
151 const double LLout2 = 0.5 * err_sqr / R_volt_exp;
152 double LLout = -P + LLout1 + LLout2;
154 return std::pair(
LL_Result{ LLout, LLout1, LLout2, P, err_sqr }, flag);
158template <
size_t N_PARAM,
size_t N_OUTPUT = 1>
166 if (i <
input.size())
constexpr double pi
Definition: constants.hpp:23
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
std::array< std::array< T, COL >, ROW > Matrix
See source: http://cpptruths.blogspot.com/2011/10/multi-dimensional-arrays-in-c11....
Definition: matrix.hpp:21
auto LL(const ThetaType &theta_cand, PriorType &prior, const CostType &costFun, const size_t Nobservations, const SettingsType &mcmcSettings)
Definition: MCMC.hpp:139
std::array< double, 5 > LL_Result
Definition: MCMC.hpp:136
auto S_update(slide::Matrix< double, N, N > &S, std::array< double, N > w, double alpha, double n)
Definition: MCMC.hpp:26
out I
Definition: squeeze_variables.m:14
MCMC_Input< N_PARAM, N_OUTPUT > theta_init
Definition: MCMC.hpp:103
Matrix< double, N_PARAM, 2 > distParam
Definition: MCMC.hpp:105
size_t n_iter
Definition: MCMC.hpp:107
std::array< double, N_PARAM > theta_scalar
Definition: MCMC.hpp:104
LL_Result LLt_struct
Definition: MCMC.hpp:162
MCMC_Input< N_PARAM, N_OUTPUT > input
Definition: MCMC.hpp:161
auto size() const
Definition: MCMC.hpp:177
auto operator[](size_t i) const
Definition: MCMC.hpp:164
auto back() const
Definition: MCMC.hpp:172
std::vector< Tdistribution > distributionVec
Definition: MCMC.hpp:113
Prior(std::vector< Tdistribution > distributionVec)
Definition: MCMC.hpp:115
auto operator()(const Tparam &b)
Definition: MCMC.hpp:118