Skip to content

Commit

Permalink
Move prng to front of nearest parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasColthurst committed Oct 4, 2024
1 parent b2fa293 commit 5763aa4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cxx/clean_relation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class CleanRelation : public Relation<T> {
}
}

ValueType nearest(const ValueType& x, const T_items& items, std::mt19937* prng) const {
ValueType nearest(std::mt19937* prng, const ValueType& x, const T_items& items) const {
std::vector<int> z = get_cluster_assignment(items);
if (clusters.contains(z)) {
return clusters.at(z)->nearest(x);
Expand Down
6 changes: 3 additions & 3 deletions cxx/clean_relation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(test_clean_relation) {
BOOST_TEST(z1[0] == 0);
BOOST_TEST(z1[1] == 0);
BOOST_TEST(z1[2] == 0);
BOOST_TEST(R1.nearest(1, {1, 1, 3}, &prng) == 1);
BOOST_TEST(R1.nearest(&prng, 1, {1, 1, 3}) == 1);

auto z2 = R1.get_cluster_assignment_gibbs({0, 1, 3}, D2, 1, 191);
BOOST_TEST(z2.size() == 3);
Expand Down Expand Up @@ -222,6 +222,6 @@ BOOST_AUTO_TEST_CASE(test_nearest) {
R1.incorporate(&prng, {1, 1}, "911");
R1.incorporate(&prng, {2, 2}, "8675309");

BOOST_TEST(R1.nearest("1234", {0, 1}, &prng) == "1234");
BOOST_TEST(R1.nearest("jj9jddd322", {1, 2}, &prng) == "9322");
BOOST_TEST(R1.nearest(&prng, "1234", {0, 1}) == "1234");
BOOST_TEST(R1.nearest(&prng, "jj9jddd322", {1, 2}) == "9322");
}
4 changes: 2 additions & 2 deletions cxx/noisy_relation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(test_noisy_relation) {
BOOST_TEST(z1[0] == 0);
BOOST_TEST(z1[1] == 0);
BOOST_TEST(z1[2] == 0);
BOOST_TEST(NR1.nearest(1, {1, 1, 3}, &prng) == 1);
BOOST_TEST(NR1.nearest(&prng, 1, {1, 1, 3}) == 1);

double lpg __attribute__((unused));
lpg = NR1.logp_gibbs_approx(D1, 0, 1, &prng);
Expand Down Expand Up @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(test_noisy_relation) {
NR2.set_cluster_assignment_gibbs(D3, 3, 1, &prng);
D1.set_cluster_assignment_gibbs(0, 1);

BOOST_TEST(NR2.nearest("cat", {1, 3}, &prng) == "cat");
BOOST_TEST(NR2.nearest(&prng, "cat", {1, 3}) == "cat");
}

BOOST_AUTO_TEST_CASE(test_unincorporate) {
Expand Down
2 changes: 1 addition & 1 deletion cxx/relation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Relation {

// Return the value nearest to x that has non-zero probability under the
// Relation's distribution for the items.
virtual ValueType nearest(const ValueType& x, const T_items& items, std::mt19937* prng) const {
virtual ValueType nearest(std::mt19937* prng, const ValueType& x, const T_items& items) const {
return x;
};

Expand Down
2 changes: 1 addition & 1 deletion cxx/transition_latent_value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void transition_latent_value(
// > 0 probability. A better solution would involve rewritting the
// propose_clean methods to take the base_relation's Distribution as
// a parameter.
candidate = base_relation->nearest(candidate, base_items, prng);
candidate = base_relation->nearest(prng, candidate, base_items);
latent_value_candidates.push_back(candidate);
}
}
Expand Down

0 comments on commit 5763aa4

Please sign in to comment.