<commit_before>Example ideas:
We're turning off scaling for the initial examples, as it's simpler without that feature.
You can give someone whuffie, and see that they have it.
Give them some more, and see their whuffie has increased by that much
Whuffie is subjective, so a spammer giving another person whuffie only increases their whuffie from the spammer's point of view, not from yours.
Whuffie is transitive, so if you give someone some whuffie, and they give that to a third person, the third person has that amount of whuffie from your point of view.
But it's shared rather than transferred, so the intermediate person also still has it after they gave it to the third person
Giving part of their whuffie shares that much
Giving more whuffie than they got from you shares what they have


python2.6 -i whuffie-credits.py 
disable_scaling()

credit(amount=3.5, by="you", subject="someone")
query(by="you", subject="someone")

credit(amount=0.3, by="you", subject="someone")
query(by="you", subject="someone")

credit(amount=1000, by="spammer", subject="another")
query(by="spammer", subject="another")
query(by="you", subject="another")

credit(amount=5, by="you", subject="second")
credit(amount=5, by="second", subject="third")
query(by="you", subject="third")

query(by="you", subject="second")

credit(amount=5, by="you",subject="B")
credit(amount=3, by="B",subject="C")
query(by="you", subject="C")

credit(amount=5, by="you",subject="D")
credit(amount=7, by="D",subject="E")
query(by="you", subject="E")


======
More session ideas:
Show reciprocity, basic and indirect
Show scaling
Show PuLP error when it's not installed with a solver
Show debits
Show debits reducing indirect reciprocity (a flaw in the system)
=======

Reciprocity:
This session shows how whuffie can encourage reciprocity, paying back help.
We're turning off scaling as before
You help someone, they appreciate that and the system keeps a record of it for them.
They see your whuffie's gone up, and can decide to do something for you in return.
If you like what they did, the system records that (when you tell it)
So their whuffie has gone up.
You could then do something for them, and so on.

That's a simple situation, the system hasn't been very useful yet. In the next example, you're paid back by a different person from the one you helped. First, you help a second person, and they give you whuffie for this.
Next, the second person helps a third person, and gets whuffie from the third person.
In this example, suppose the third person can't do anything really useful for the second person at the moment. So they see you now have whuffie, and help you. Once you give them whuffie for this, it raises the second person's whuffie (according to you), encouraging you to continue the cycle by helping the second person again.

So you help them and earn whuffie, and in the second cycle, your whuffie with the third person, who seems to have something useful for you, goes up to twice as much it was before

whuffie_init()
disable_scaling()
credit(12,"them", "you")
query("them","you")
credit(11,"you","them")
query("you","them")
credit(13,"them", "you")
query("them","you")
credit(14,"you","them")
query("you","them")



credit(4,"second","you")
credit(5,"third","second")
query("third","you")

query("you","second")
credit(3,"you","third")
query("you","second")

credit(4,"second","you")
query("third","you")
credit(5,"third","second")
query("third","you")


=====
Scaling
Rather than have everyone have to measure out the whuffie they give on the same scale, each person can use their own and have the system automatically rescale.
The way the scaling works, the whuffie each person's given out is scaled to match the total they received, though with a few complications.
Example: you give someone 30 credits, they give out a total of 3, so those 3 credits are scaled up by a factor of 10

credit(30,"you","them")
credit(1,"them","A")
credit(2,"them","B")
query("you","A")
query("you","B")

This shows a few of the complications: the credit given by node "you" was not scaled down to zero for a few reasons: a "fudge factor" prevents any scaling factor from going down as low as zero, and the node doing the query is not scaled at all (partly so "you" can read the result in your own scale). Also the results were not exact, mainly due to the fudge factor, but also due to rounding errors.

=====
PuLP test
If PuLP is not installed at all you would get a straightforward error about this.
But if the solver's not working correctly (like when I used the latest python 2.7)
$ python -i whuffie-credits.py 
test_pulp()
=====
Debits
If a favour is repaid, the whuffie can be cancelled with the debit function. Sometimes this can help prevent the same favor being repaid over and over again, totalling an unfair amount of repayment. Debiting has drawbacks, so you wouldn't always want to do it, or you might only debit a small amount.

Direct example:
credit(10,"you","them")
query("you","them")
debit(10,"you","them")
query("you","them")

You could have just remembered that you'd repaid "them" though.

Indirect example, cancelling the whuffie from you shared by X and Y. First give the whuffie:
credit(10,"you","X")
credit(10,"X","Y")
query("you","Y")
query("you","X")
query("you","X")

Then cancel it with a debit:
debit(10,"you","Y")
query("you","Y")
query("you","X")
It also cancelled Y's whuffie from X
query("X","Y")

Otherwise both "you" and "X" might repay "Y". In this example it might not be so bad, but in a long chain of you, A,B,C,D,E,F...Y it could be more unfair than people would tolerate.

Partial cancellation example
credit(10,"you","A")
query("you","A")
debit(2,"you","A")
query("you","A")




The next scenario's easier to show with scaling turned off. Also it has a lot of people so we'll reset the system first:
whuffie_init()
disable_scaling()

M helps a lot of people
credit(1,"A","M")
credit(1,"B","M")
credit(1,"C","M")
credit(1,"D","M")
credit(1,"E","M")

and is helped by a lot of people
credit(1,"M","V")
credit(1,"M","W")
credit(1,"M","X")
credit(1,"M","Y")
credit(1,"M","Z")

All the people who helped M now have credit with people helped by M, e.g.
query("A","V")
query("A","Z")
query("C","Z")

"A" might help Z an amount they thought proportionate, then B,C,D,E might also do so, giving a total of 5 times as much help as they thought proportionate, and not having helped V,W,X, or Y at all.

So to solve this, "A" and "Z" agree to a debit when A repays Z

debit(1,"A","Z")

In this case it fully cancelled all credit from A, and all credit to Z

query("A","V")
query("A","Z")
query("C","Z")
query("C","V")

If you'd wanted to only partially cancel it, that's an option too, e.g. if B then helps Y

debit(0.3,"B","Y")
query("B","V")
query("B","Y")
query("C","Y")
query("C","V")

Finally, one of the drawbacks. Where there haven't been any debits, the system allows more opportunity of indirect payback. e.g. if E helps V and gets whuffie for it, then E has whuffie from everyone who had given whuffie to V previously.
query("D","E")
query("M","E")
query("V","E")
credit(1,"V","E")
query("D","E")
query("M","E")
query("V","E")

Any of them might then repay E.

But if Z gives whuffie to A for help received, since Z's whuffie from others was cancelled, there's only direct whuffie to repay A.

credit(1,"Z","A")
query("D","A")
query("M","A")
query("Z","A")

It's not so bad if the whuffie was only partially cancelled, as in the case of B and Y, but there's still a reduction of indirect whuffie available.

credit(1,"Y","B")
query("D","B")
query("M","B")
query("Y","B")

=======
Another session, maybe with more mathematical details

Debits do no change the scaling factors (complicated example, didn't include in main debits session):
credit(10,"you","C")
credit(1,"B","C")
query("you","C")
The credit was scaled up to match what you'd given to "B".
credit(4,"B","C")
query("you","C")
The credit scaling was reduced, so the total still matches what you'd given to "B".
debit(4,"B","C")
query("you","C")
Scaling was not changed by the debit, total is now less than what you'd given "B"
query("you","B")

An example showing how the system is sometimes equivalent to a maximum flow problem.
https://en.wikipedia.org/wiki/Maximum_flow_problem


<commit_msg>Session log idea - individual scaling change<commit_after>Example ideas:
We're turning off scaling for the initial examples, as it's simpler without that feature.
You can give someone whuffie, and see that they have it.
Give them some more, and see their whuffie has increased by that much
Whuffie is subjective, so a spammer giving another person whuffie only increases their whuffie from the spammer's point of view, not from yours.
Whuffie is transitive, so if you give someone some whuffie, and they give that to a third person, the third person has that amount of whuffie from your point of view.
But it's shared rather than transferred, so the intermediate person also still has it after they gave it to the third person
Giving part of their whuffie shares that much
Giving more whuffie than they got from you shares what they have


python2.6 -i whuffie-credits.py 
disable_scaling()

credit(amount=3.5, by="you", subject="someone")
query(by="you", subject="someone")

credit(amount=0.3, by="you", subject="someone")
query(by="you", subject="someone")

credit(amount=1000, by="spammer", subject="another")
query(by="spammer", subject="another")
query(by="you", subject="another")

credit(amount=5, by="you", subject="second")
credit(amount=5, by="second", subject="third")
query(by="you", subject="third")

query(by="you", subject="second")

credit(amount=5, by="you",subject="B")
credit(amount=3, by="B",subject="C")
query(by="you", subject="C")

credit(amount=5, by="you",subject="D")
credit(amount=7, by="D",subject="E")
query(by="you", subject="E")


======
More session ideas:
Show reciprocity, basic and indirect
Show scaling
Show PuLP error when it's not installed with a solver
Show debits
Show debits reducing indirect reciprocity (a flaw in the system)
=======

Reciprocity:
This session shows how whuffie can encourage reciprocity, paying back help.
We're turning off scaling as before
You help someone, they appreciate that and the system keeps a record of it for them.
They see your whuffie's gone up, and can decide to do something for you in return.
If you like what they did, the system records that (when you tell it)
So their whuffie has gone up.
You could then do something for them, and so on.

That's a simple situation, the system hasn't been very useful yet. In the next example, you're paid back by a different person from the one you helped. First, you help a second person, and they give you whuffie for this.
Next, the second person helps a third person, and gets whuffie from the third person.
In this example, suppose the third person can't do anything really useful for the second person at the moment. So they see you now have whuffie, and help you. Once you give them whuffie for this, it raises the second person's whuffie (according to you), encouraging you to continue the cycle by helping the second person again.

So you help them and earn whuffie, and in the second cycle, your whuffie with the third person, who seems to have something useful for you, goes up to twice as much it was before

whuffie_init()
disable_scaling()
credit(12,"them", "you")
query("them","you")
credit(11,"you","them")
query("you","them")
credit(13,"them", "you")
query("them","you")
credit(14,"you","them")
query("you","them")



credit(4,"second","you")
credit(5,"third","second")
query("third","you")

query("you","second")
credit(3,"you","third")
query("you","second")

credit(4,"second","you")
query("third","you")
credit(5,"third","second")
query("third","you")


=====
Scaling
Rather than have everyone have to measure out the whuffie they give on the same scale, each person can use their own and have the system automatically rescale.
The way the scaling works, the whuffie each person's given out is scaled to match the total they received, though with a few complications.
Example: you give someone 30 credits, they give out a total of 3, so those 3 credits are scaled up by a factor of 10

credit(30,"you","them")
credit(1,"them","A")
credit(2,"them","B")
query("you","A")
query("you","B")

This shows a few of the complications: the credit given by node "you" was not scaled down to zero for a few reasons: a "fudge factor" prevents any scaling factor from going down as low as zero, and the node doing the query is not scaled at all (partly so "you" can read the result in your own scale). Also the results were not exact, mainly due to the fudge factor, but also due to rounding errors.

=====
PuLP test
If PuLP is not installed at all you would get a straightforward error about this.
But if the solver's not working correctly (like when I used the latest python 2.7)
$ python -i whuffie-credits.py 
test_pulp()
=====
Debits
If a favour is repaid, the whuffie can be cancelled with the debit function. Sometimes this can help prevent the same favor being repaid over and over again, totalling an unfair amount of repayment. Debiting has drawbacks, so you wouldn't always want to do it, or you might only debit a small amount.

Direct example:
credit(10,"you","them")
query("you","them")
debit(10,"you","them")
query("you","them")

You could have just remembered that you'd repaid "them" though.

Indirect example, cancelling the whuffie from you shared by X and Y. First give the whuffie:
credit(10,"you","X")
credit(10,"X","Y")
query("you","Y")
query("you","X")
query("you","X")

Then cancel it with a debit:
debit(10,"you","Y")
query("you","Y")
query("you","X")
It also cancelled Y's whuffie from X
query("X","Y")

Otherwise both "you" and "X" might repay "Y". In this example it might not be so bad, but in a long chain of you, A,B,C,D,E,F...Y it could be more unfair than people would tolerate.

Partial cancellation example
credit(10,"you","A")
query("you","A")
debit(2,"you","A")
query("you","A")




The next scenario's easier to show with scaling turned off. Also it has a lot of people so we'll reset the system first:
whuffie_init()
disable_scaling()

M helps a lot of people
credit(1,"A","M")
credit(1,"B","M")
credit(1,"C","M")
credit(1,"D","M")
credit(1,"E","M")

and is helped by a lot of people
credit(1,"M","V")
credit(1,"M","W")
credit(1,"M","X")
credit(1,"M","Y")
credit(1,"M","Z")

All the people who helped M now have credit with people helped by M, e.g.
query("A","V")
query("A","Z")
query("C","Z")

"A" might help Z an amount they thought proportionate, then B,C,D,E might also do so, giving a total of 5 times as much help as they thought proportionate, and not having helped V,W,X, or Y at all.

So to solve this, "A" and "Z" agree to a debit when A repays Z

debit(1,"A","Z")

In this case it fully cancelled all credit from A, and all credit to Z

query("A","V")
query("A","Z")
query("C","Z")
query("C","V")

If you'd wanted to only partially cancel it, that's an option too, e.g. if B then helps Y

debit(0.3,"B","Y")
query("B","V")
query("B","Y")
query("C","Y")
query("C","V")

Finally, one of the drawbacks. Where there haven't been any debits, the system allows more opportunity of indirect payback. e.g. if E helps V and gets whuffie for it, then E has whuffie from everyone who had given whuffie to V previously.
query("D","E")
query("M","E")
query("V","E")
credit(1,"V","E")
query("D","E")
query("M","E")
query("V","E")

Any of them might then repay E.

But if Z gives whuffie to A for help received, since Z's whuffie from others was cancelled, there's only direct whuffie to repay A.

credit(1,"Z","A")
query("D","A")
query("M","A")
query("Z","A")

It's not so bad if the whuffie was only partially cancelled, as in the case of B and Y, but there's still a reduction of indirect whuffie available.

credit(1,"Y","B")
query("D","B")
query("M","B")
query("Y","B")

=======
Another session, maybe with more mathematical details

Debits do no change the scaling factors (complicated example, didn't include in main debits session):
credit(10,"you","C")
credit(1,"B","C")
query("you","C")
The credit was scaled up to match what you'd given to "B".
credit(4,"B","C")
query("you","C")
The credit scaling was reduced, so the total still matches what you'd given to "B".
debit(4,"B","C")
query("you","C")
Scaling was not changed by the debit, total is now less than what you'd given "B"
query("you","B")

An example showing how the system is sometimes equivalent to a maximum flow problem.
https://en.wikipedia.org/wiki/Maximum_flow_problem

=====
Normally when scaling is turned on, whuffie out equals whuffie in. Show how you can change this by sending some of your credit to a "reservation" node

whuffie_init()
credit(100,"A","you")
credit(10,"you","B")
query("A","B")

99.999099999999999

That's too much

credit(40,"you","reserved")
query("A","B")

20.0

That's better
======


{'fraction_non_alphanumeric': 0.13131611606879026, 'fraction_numerical': 0.0105785710064417, 'mean_word_length': 5.359263434798947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5154057', 'n_tokens_mistral': 5450, 'n_tokens_neox': 5076, 'n_words': 2387}