Skip to content

Commit

Permalink
Multiwinner error measures: add G-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristomu committed Sep 19, 2024
1 parent 232716a commit 0986eb2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/multiwinner/helper/errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ double gallagher(const std::vector<double> & a,
return (sqrt(0.5 * squared));
}

// G-test. I'm still not sure that this is the correct order.
// Needs testing.
double g_test(const std::vector<double> & quantized,
const std::vector<double> & pop_profile) {

double sum = 0;
size_t elements = std::min(quantized.size(), pop_profile.size());

for (size_t i = 0; i < elements; ++i) {
double observed = quantized[i],
expected = pop_profile[i];

if (observed == 0) {
continue;
}
sum += observed * log(observed/expected);
}

return 2 * sum;
}

// Loosemore-Hanby
double lhi(const std::vector<double> & a, const std::vector<double> & b) {
Expand Down

0 comments on commit 0986eb2

Please sign in to comment.