Skip to content

Add weighted picking#4

Open
MurtadaSoftwire wants to merge 1 commit intoalexttyip:mainfrom
MurtadaSoftwire:add-weighted-picking
Open

Add weighted picking#4
MurtadaSoftwire wants to merge 1 commit intoalexttyip:mainfrom
MurtadaSoftwire:add-weighted-picking

Conversation

@MurtadaSoftwire
Copy link
Copy Markdown

Adding automatic weighting to try to force uniformity might be a bad idea given that users can be excluded e.g. users is excluded for a long time they come back and are suddenly picked for everything so that the pick ratio balances out, so have instead gone with a manual weights approach which I think might be better?

Also haven't tested how the random distribution for random.org looks like since they have a 10 requests per sec limit, but instead added in another random function using math.random and checked that the distribution is indeed uniform

Comment thread src/events/weights.ts
return sayInThread(say, mentionTs, [
getSimpleTextBlock(
`Weights:\n \`\`\`${Object.entries(weights)
.map((userWeightPair) => `${userWeightPair[0]}: ${userWeightPair[1]}`)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user id here probably needs to be mapped to user name

Comment thread src/events/weights.ts
) => {
console.log("editWeights");
const { weights } = context.conversation;
const user = restOfCommand[0] ?? "";
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user name here probably needs to be mapped to user id

const mapDbConversationStateToConversationState = ({
excluded,
teams,
pickingAlgorithm,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Db will need some migrations to add pickingAlgorithm and weights tables / similar

@@ -1,4 +1,4 @@
export const getRandomInteger = async (
export const getAtmosphericNoiseRandomInteger = async (
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed this based on how random.org says their algo works

Comment thread src/events/algortithm.ts

return sayInThread(say, mentionTs, [
getSimpleTextBlock(
`Picking Algorithm: ${pickingAlgorithm}`,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping needed to a good display name but it was a bit annoying with enums so thought I'd deal with it later

@MurtadaSoftwire
Copy link
Copy Markdown
Author

I figured out an algorithm for auto balancing that will work even with adding new users and with excluding users and adding them back and have verified that it works through some testing and plotting, although not really bothered to add it rn

algorithm is as follows:

  1. All users start of with an equal and normalised weighting
  2. The weighted picking algorithm (same as implemented here) picks a user based on the weights
  3. whenever a user is picked their weighting is divided by 2 and all the weights are normalised again
    1. note that the min weight value needs to be clamped to avoid it reaching 0 as there is no way back from that
  4. Whenever a user is excluded / removed all the weights get normalised again
  5. Whenever a user is added we add them with the current mean weight and then normalise all the weights again

Might also be interesting to add:

  • round robin mode, users are picked in a repeating sequence
  • force balance mode, weighted picking based on totalPicks / timesUserPicked as a weight for each user
    • this is what I was trying to avoid in the begining when thinking about autobalancing, as its very unfair for new users / people who get excluded and added back (although that might be what you want in this case)

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

Successfully merging this pull request may close these issues.

1 participant