Docs
Loading...
Searching...
No Matches
U_sampler.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
10#include <random>
11
28class U_sampler {
29
30protected:
33
37
40
42 int accepted_U = 0;
43
45 std::random_device rd;
46
48 mutable std::mt19937 gen;
49
55
57 const double a_over_sigma = params.a / params.sigma;
58
60 const double tau_power_sigma = std::pow(params.tau, params.sigma);
61
63 const int n = data.get_n();
64
66 double U = 1.0;
67
69
79
110 double log_conditional_density_U(double u) const;
111
138 double log_conditional_density_V(double v) const;
139
141
142public:
154 U_sampler(Params &p, Data &d) : params(p), data(d) {};
155
163 virtual void update_U() = 0;
164
170 double get_U() const { return U; }
171
176 double get_acceptance_rate() const {
177 if(total_iterations == 0)
178 return 0.0;
179 return static_cast<double>(accepted_U) / static_cast<double>(total_iterations);
180 }
181
185 virtual ~U_sampler() = default;
186};
Data structure for managing point distances and cluster allocations.
Parameter management for Bayesian nonparametric MCMC models.
Manages distance matrices and cluster allocations for points.
Definition Data.hpp:27
double get_U() const
Getter for the current value of U.
Definition U_sampler.hpp:170
int total_iterations
Counter for total MCMC iterations performed.
Definition U_sampler.hpp:39
virtual ~U_sampler()=default
Virtual destructor for the U_sampler class.
U_sampler(Params &p, Data &d)
Constructor for the U_sampler class.
Definition U_sampler.hpp:154
std::random_device rd
Random device for seeding.
Definition U_sampler.hpp:45
const int n
Number of observations n.
Definition U_sampler.hpp:63
std::mt19937 gen
Mersenne Twister random number generator.
Definition U_sampler.hpp:48
Data & data
Reference to the data object containing observations and cluster assignments.
Definition U_sampler.hpp:36
double log_conditional_density_V(double v) const
Computes the log conditional density of V = log(U) given the partition.
Definition U_sampler.cpp:27
double U
Current value of the latent variable U (initialized to 1.0).
Definition U_sampler.hpp:66
virtual void update_U()=0
Pure virtual method to update the latent variable U.
const double tau_power_sigma
Pre-computed tau^sigma for efficient computation.
Definition U_sampler.hpp:60
Params & params
Reference to the parameters object containing NGGP parameters.
Definition U_sampler.hpp:32
const double a_over_sigma
Ratio a/sigma for efficient computation.
Definition U_sampler.hpp:57
int accepted_U
Counter of accepted U.
Definition U_sampler.hpp:42
double log_conditional_density_U(double u) const
Computes the log conditional density of U given the partition.
Definition U_sampler.cpp:9
double get_acceptance_rate() const
Getter for the acceptance rate of U updates.
Definition U_sampler.hpp:176
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35