Skip to content

Commit

Permalink
Add asserts to scored_method, infinity HACK to psi voting with sum = 0.
Browse files Browse the repository at this point in the history
Also note a bug in QPQ: it seems like it's reading ratings, and it
shouldn't be doing that...
  • Loading branch information
kristomu committed Sep 21, 2024
1 parent 029c202 commit 9f8e3aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/multiwinner/methods/exhaustive/psi.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ double digamma(double x) {
// Check the input.

if (x <= 0.0) {
throw std::invalid_argument("digamma: x < 0 is not supported");
throw std::invalid_argument("digamma: x <= 0 is not supported");
}

// Initialize.
Expand Down Expand Up @@ -99,6 +99,12 @@ double psi_voting_eval::evaluate(combo::it & start, combo::it & end,
norm_rating_sum += this_ballot.get_norm_score(*pos);
}

// digamma(0) = infinity. HACK to deal with this without having
// to bring in infinities.
if (delta + norm_rating_sum == 0) {
return 1e9 * this_ballot.weight;
}

return digamma(delta + norm_rating_sum) * this_ballot.weight;
}

Expand Down
4 changes: 4 additions & 0 deletions src/multiwinner/methods/exhaustive/scored_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class scored_ballot {
std::vector<double> scores; // #voters by #cands

double get_norm_score(size_t candidate) const {
assert(min <= max);
assert(scores[candidate] >= min);
assert(scores[candidate] <= max);

return renorm(min, max,
scores[candidate], 0.0, 1.0);
}
Expand Down
5 changes: 4 additions & 1 deletion src/multiwinner/methods/qpq.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include "methods.h"
//#include "../tiebreaker.cc"
#include <vector>
#include <list>

// KNOWN BUG: Does not handle negative scores well. I have no idea why,
// since this is a ranked method. Use multiwinner_spatial with Euclidean
// distance and no noise to reproduce.

class QPQ : public multiwinner_method {
private:
ordering::const_iterator ballot_contribution(
Expand Down

0 comments on commit 9f8e3aa

Please sign in to comment.