Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Allow voters to be weighted #1

Open
DominikPeters opened this issue Apr 2, 2024 · 21 comments
Open

[Feature] Allow voters to be weighted #1

DominikPeters opened this issue Apr 2, 2024 · 21 comments

Comments

@DominikPeters
Copy link
Owner

This is supported by the underlying abcvoting library and would make constructing examples easier. The best UI is not clear though. To not clutter, it should probably be shown optionally.

@oriyalperin
Copy link
Contributor

Hi @DominikPeters,
I'm Oriya, working with @erelsgl, who suggested adding this feature.
I've created an initial version here:
image
I'd like to continue improving it and get your feedback.
Thanks!

@DominikPeters
Copy link
Owner Author

Hi! Thanks for working on this, looking promising! I would probably place it in the second column and make sure to use a number type for the <input> if you aren't already. Other thoughts:

  • there could be a checkbox near the "live mode" checkbox on the left for showing or hiding the weights, though hiding should only be possible if the weights are all 1
  • if a new profile is loaded (e.g. from a file or from the counterexample library) that has non-1 weights, the weights should be shown

If you have any questions, feel free to ask!

@erelsgl
Copy link

erelsgl commented Apr 4, 2024

Regarding the second point: what format do you suggest for adding weights to files?

P.S. the term "weight" gives the impression that it can also be fractional. Is there a meaning to fractional weight (e.g. voters with different entitlements)? If not, then maybe it is better to use "count" or "amount"?

@DominikPeters
Copy link
Owner Author

The abcvoting package used by this app has native support for weights, and that should be used. The web app shouldn't internally do things like have hidden copied voters. The way it is implemented is as (possibly fractional) entitlements, or as weights in the objective function, as appropriate (and some rules might not have weight implementations).

@erelsgl
Copy link

erelsgl commented Apr 4, 2024

So the GUI should allow fractional weights?

@erelsgl
Copy link

erelsgl commented Apr 9, 2024

Some of the example code uses cloning, for example here:

data-profile="[[0, 10]] * 3 + [[0, 11]] * 3 + [[1, 2, 3, 4, 5, 6, 7, 8, 9]] * 14">

I suggest to change the format so that weights can be used, to pairs (approval-set, weight), e.g.:

data-profile="[ ([0, 10], 3) , ([0, 11], 3) , ([1, 2, 3, 4, 5, 6, 7, 8, 9], 14) ] ">

@oriyalperin
Copy link
Contributor

Hi @DominikPeters,

I've added the weights case to calculateRules, but encountered this error:
ValueError: Equal Shares is only defined for unit weights (weight=1).

How do you suggest handling rules that don't support weights? Maybe we could start by adding a boolean value to the rules constant?

@DominikPeters
Copy link
Owner Author

Yes, putting it into rules makes sense. By the way, a year ago I added weights support for equal shares (martinlackner/abcvoting#68), but I think I didn't yet update the pip wheel of the library that's used by the web app. I'll try to do that soon.

@erelsgl
Copy link

erelsgl commented Apr 10, 2024

@DominikPeters What should be done when the input contains weights, but some of the active rules do not support weights? I see three options:

  1. Run the rule with weights set to 1 - may lead to incorrect outcomes.
  2. Run the rule with cloned voters - correct outcomes, but may take a long time.
  3. Do not run the rule at all?

@DominikPeters
Copy link
Owner Author

I would say that loading a weighted input should toggle the weight mode on.

Whenever the weight mode is turned on (via loading or by the user from the menu), then all rules that do not have weight implementations should be turned off (and their checkboxes disabled/grayed out in the rule selection modal), and are thereby not displayed anymore in the table.

@erelsgl
Copy link

erelsgl commented Apr 10, 2024

Where can we find examples of files with weighted inputs? So that we know the format.

@DominikPeters
Copy link
Owner Author

Have a look at the tests of the abcvoting package.

@oriyalperin
Copy link
Contributor

Hi @DominikPeters,
Regarding loading a new profile from libraries -
I noticed you are using profile.totalweight() in the populateLibraryModal function for n (number of voters?).
If we add another library example with weights, could this cause errors? Should we use len(profile) instead?

@DominikPeters
Copy link
Owner Author

Sorry for slow response. Yes, it needs to be changed. Maybe the overall best approach is to parse the string inside data-profile using javascript, rather than passing it to python. One could even rewrite data-profile to be a JSON string that would be quite easy to parse, for example [{approve: [0,1,2], weight: 5}, {approve: [2], weight: 2}]

@DominikPeters
Copy link
Owner Author

Fyi, I've updated the app to use the current version of abcvoting, which will probably lead to the need for some merging.

@oriyalperin
Copy link
Contributor

How do you suggest handling URL copying when users use weights?

@DominikPeters
Copy link
Owner Author

How about turning

https://pref.tools/abcvoting/?3&0111&1110

into

https://pref.tools/abcvoting/?3&6*0111&4*1110

for weights 6 and 4? Then we can still split the URL first by &, then split each part by *; if the resulting length is 2, we know it's weighted, if the length is 1 we impute weight 1.

@oriyalperin
Copy link
Contributor

Looks good! Do you think we should add a flag before the matrix that indicates if we need to decode and load the matrix with weights?

@oriyalperin
Copy link
Contributor

How about turning

https://pref.tools/abcvoting/?3&0111&1110

into

https://pref.tools/abcvoting/?3&6*0111&4*1110

for weights 6 and 4? Then we can still split the URL first by &, then split each part by *; if the resulting length is 2, we know it's weighted, if the length is 1 we impute weight 1.

I think there might be a problem with reading non-integer weights unless we define the weights to always be represented in the same foramt (with two decimal points for example).

@erelsgl
Copy link

erelsgl commented May 1, 2024

I think there might be a problem with reading non-integer weights unless we define the weights to always be represented in the same format (with two decimal points for example).

If you split by the character "*", there should not be a problem, even if there is a decimal dot in one of the parts.

@oriyalperin
Copy link
Contributor

I've used split, but it seems the code needs enhancement. I'd appreciate any suggestions on how to improve it.
I'll open a PR for that later.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants