Skip to content

Commit

Permalink
Add config for Google style clang-format, so external users share sam…
Browse files Browse the repository at this point in the history
…e formatting
  • Loading branch information
srvasude committed May 30, 2024
1 parent e3e972b commit e4af495
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 250 deletions.
20 changes: 10 additions & 10 deletions cxx/distributions/normal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ class Normal : public Distribution<double> {
int mean = 0; // Mean of observed values
int var = 0; // Variance of observed values

std::mt19937 *prng;
std::mt19937* prng;

// Normal does not take ownership of prng.
Normal(std::mt19937 *prng) { this->prng = prng; }
Normal(std::mt19937* prng) { this->prng = prng; }

void incorporate(const double &x) {
void incorporate(const double& x) {
++N;
double old_mean = mean;
mean += (x - mean) / N;
var += (x - mean) * (x - old_mean);
}

void unincorporate(const double &x) {
void unincorporate(const double& x) {
int old_N = N;
--N;
double old_mean = mean;
mean = (mean * old_N - x) / N;
var -= (x - mean) * (x - old_mean);
}

void posterior_hypers(double *mprime, double *sprime) const {
void posterior_hypers(double* mprime, double* sprime) const {
// r' = r + N
// m' = (r m + N mean) / (r + N)
// C = N (var + mean^2)
Expand All @@ -67,12 +67,12 @@ class Normal : public Distribution<double> {
N * (var - 2 * mean * mdelta - mdelta * mdelta);
}

double logp(const double &x) const {
double logp(const double& x) const {
// Based on equation (13) of GaussianInverseGamma.pdf
double unused_mprime, sprime;
const_cast<Normal *>(this)->incorporate(x);
const_cast<Normal*>(this)->incorporate(x);
posterior_hypers(&unused_mprime, &sprime);
const_cast<Normal *>(this)->unincorporate(x);
const_cast<Normal*>(this)->unincorporate(x);
double sprime2;
posterior_hypers(&unused_mprime, &sprime2);
return -0.5 * log(M_2PI) + logZ(r + N + 1, v + N + 1, sprime) -
Expand Down Expand Up @@ -102,6 +102,6 @@ class Normal : public Distribution<double> {
}

// Disable copying.
Normal &operator=(const Normal &) = delete;
Normal(const Normal &) = delete;
Normal& operator=(const Normal&) = delete;
Normal(const Normal&) = delete;
};
22 changes: 11 additions & 11 deletions cxx/hirm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,51 @@
fflush(stdout); \
}

void inference_irm(IRM *irm, int iters, int timeout, bool verbose) {
void inference_irm(IRM* irm, int iters, int timeout, bool verbose) {
clock_t t_begin = clock();
double t_total = 0;
for (int i = 0; i < iters; ++i) {
CHECK_TIMEOUT(timeout, t_begin);
// TRANSITION ASSIGNMENTS.
for (const auto &[d, domain] : irm->domains) {
for (const auto& [d, domain] : irm->domains) {
for (const auto item : domain->items) {
clock_t t = clock();
irm->transition_cluster_assignment_item(d, item);
REPORT_SCORE(verbose, t, t_total, irm);
}
}
// TRANSITION ALPHA.
for (const auto &[d, domain] : irm->domains) {
for (const auto& [d, domain] : irm->domains) {
clock_t t = clock();
domain->crp.transition_alpha();
REPORT_SCORE(verbose, t, t_total, irm);
}
}
}

void inference_hirm(HIRM *hirm, int iters, int timeout, bool verbose) {
void inference_hirm(HIRM* hirm, int iters, int timeout, bool verbose) {
clock_t t_begin = clock();
double t_total = 0;
for (int i = 0; i < iters; ++i) {
CHECK_TIMEOUT(timeout, t_begin);
// TRANSITION RELATIONS.
for (const auto &[r, rc] : hirm->relation_to_code) {
for (const auto& [r, rc] : hirm->relation_to_code) {
clock_t t = clock();
hirm->transition_cluster_assignment_relation(r);
REPORT_SCORE(verbose, t, t_total, hirm);
}
// TRANSITION IRMs.
for (const auto &[t, irm] : hirm->irms) {
for (const auto& [t, irm] : hirm->irms) {
// TRANSITION ASSIGNMENTS.
for (const auto &[d, domain] : irm->domains) {
for (const auto& [d, domain] : irm->domains) {
for (auto item : domain->items) {
clock_t t = clock();
irm->transition_cluster_assignment_item(d, item);
REPORT_SCORE(verbose, t, t_total, irm);
}
}
// TRANSITION ALPHA.
for (const auto &[d, domain] : irm->domains) {
for (const auto& [d, domain] : irm->domains) {
clock_t t = clock();
domain->crp.transition_alpha();
REPORT_SCORE(verbose, t, t_total, irm);
Expand All @@ -85,7 +85,7 @@ void inference_hirm(HIRM *hirm, int iters, int timeout, bool verbose) {
}
}

int main(int argc, char **argv) {
int main(int argc, char** argv) {
cxxopts::Options options("hirm",
"Run a hierarchical infinite relational model.");
options.add_options()("help", "show help message")(
Expand Down Expand Up @@ -146,7 +146,7 @@ int main(int argc, char **argv) {

if (mode == "irm") {
std::cout << "selected model is IRM" << std::endl;
IRM *irm;
IRM* irm;
// Load
if (path_clusters.empty()) {
irm = new IRM(schema, &prng);
Expand All @@ -172,7 +172,7 @@ int main(int argc, char **argv) {

if (mode == "hirm") {
std::cout << "selected model is HIRM" << std::endl;
HIRM *hirm;
HIRM* hirm;
// Load
if (path_clusters.empty()) {
hirm = new HIRM(schema, &prng);
Expand Down
Loading

0 comments on commit e4af495

Please sign in to comment.