Docs
Toggle main menu visibility
Loading...
Searching...
No Matches
neal.hpp
Go to the documentation of this file.
1
13
14
#pragma once
15
16
#include "
../utils/Sampler.hpp
"
17
#include <vector>
18
43
class
Neal3
:
public
Sampler
{
44
private
:
45
// ========== Random Number Generation ==========
46
48
mutable
std::mt19937
gen
;
49
50
// ========== Core Algorithm Methods ==========
51
66
void
step_1_observation
(
int
index);
67
78
int
sample_from_log_probs
(
int
num_clusters);
79
80
// Pre-allocated buffers to avoid repeated allocations
81
std::vector<int>
indices
;
82
std::vector<double>
log_likelihoods
;
83
std::vector<double>
weights
;
84
int
n_data
;
85
86
public
:
87
// ========== Constructor ==========
88
101
Neal3
(
Data
&d,
Likelihood
&l,
Process
&pr)
102
:
Sampler
(d, l, pr),
gen
(
rd
()),
n_data
(d.get_n()) {
103
// Pre-allocate to max size (all points in separate clusters + 1 new
104
// cluster)
105
log_likelihoods
.reserve(
n_data
+ 1);
106
weights
.reserve(
n_data
+ 1);
107
108
indices
.resize(
n_data
);
109
std::iota(
indices
.begin(),
indices
.end(), 0);
110
}
111
112
// ========== MCMC Interface ==========
113
128
void
step
()
override
;
129
};
Sampler.hpp
Abstract base class for MCMC sampling algorithms.
Data
Manages distance matrices and cluster allocations for points.
Definition
Data.hpp:26
Likelihood
Abstract base class for likelihood computation.
Definition
Likelihood.hpp:26
Neal3::weights
std::vector< double > weights
Definition
neal.hpp:83
Neal3::sample_from_log_probs
int sample_from_log_probs(int num_clusters)
Sample an index from log-probabilities using the log-sum-exp trick.
Definition
neal.cpp:17
Neal3::gen
std::mt19937 gen
Mersenne Twister random number generator for sampling operations.
Definition
neal.hpp:48
Neal3::n_data
int n_data
Definition
neal.hpp:84
Neal3::Neal3
Neal3(Data &d, Likelihood &l, Process &pr)
Constructor for Neal's Algorithm 3 sampler.
Definition
neal.hpp:101
Neal3::step
void step() override
Perform one complete iteration of Neal's Algorithm 3.
Definition
neal.cpp:83
Neal3::step_1_observation
void step_1_observation(int index)
Sample cluster assignment for a single observation.
Definition
neal.cpp:47
Neal3::indices
std::vector< int > indices
Definition
neal.hpp:81
Neal3::log_likelihoods
std::vector< double > log_likelihoods
Definition
neal.hpp:82
Process
Abstract base class for Bayesian nonparametric processes.
Definition
Process.hpp:40
Sampler::rd
std::random_device rd
Random device for generating random numbers across sampling algorithms.
Definition
Sampler.hpp:67
Sampler::Sampler
Sampler(Data &d, const Likelihood &l, Process &pr)
Constructor initializing sampler with required components.
Definition
Sampler.hpp:89
BNPClust
samplers
neal.hpp
Generated by
1.17.0