Skip to content

rough draft of glicko2 library - #12

Closed
bonbud-macryg wants to merge 164 commits into
mainfrom
glicko2
Closed

rough draft of glicko2 library#12
bonbud-macryg wants to merge 164 commits into
mainfrom
glicko2

Conversation

@bonbud-macryg

Copy link
Copy Markdown
Collaborator

Draft PR, not a merge candidate due to one bug.

Notes:

  • You can ignore files named "glicko2-n"; those are older drafts and will be removed in the merge-candidate PR.
  • saloon will also be removed in the final PR. Anything usable and performant has been adapted into the glicko2 helper core.
  • test_glicko2.py contains unit tests for glicko2.py, which we know for sure is correct as per TESTING.md. I'm not sure why test_E() outputs 0.5 in all cases, as manually print()ing it outputs reveals more accurate numbers that our +e is almost outputting. You can run these Python tests by cding to pyglicko2 and running python test_glicko2.py, assuming you have Python 3.x installed.

In this review I'd like to address three issues:

  1. There's a loop bug in +new-vol that may or may not be a straightforward infinite loop.
  • Looking at the ~& output from that arm, it seems to get caught in the 2nd loop for a while before stalling, which is why I'm unsure about it. I had some trouble wrangling this arm into something using |-s rather than straightforward for and while loops, so I'd appreciate a fresh pair of eyes on it.
  1. What mistakes have I made translating this into Hoon?
  • I've arranged and annotated this library to be read alongside the Glicko-2 paper. I was mostly working from glicko2.py, but having gone through the paper again I was able to clear up a couple of minor mistakes and oversights.
  • If you run the test suite you'll see where things are and aren't outputting within rtol, a standard margin of error I took from saloon. I'm a little concerned that errors within rtol will compound while glicko2.hoon is run, but I don't think there's much we can do about it after a certain point. Having done a lot of it, I think playing around with rounding modes is of almost no use here.
  • It's worth flagging that (other than one arm name) I changed nothing in the saloon arms except changing the types from @rs to @rd, but I think this might have created some inaccuracy. The tests in /tests/glicko2 are exactly the same as /test/saloon, but they're slightly outwith rtol. I was able to make them more accurate by specifying add:rd rather than add. ((add .~1 .~1) is valid hoon, which I was a little surprised by.)
  • If an arm like +exp is found to be correct but is outwith rtol, I think we should either make the rtol margin of error wider or introduce a second margin. In the merge candidate, all tests should show up "OK" even if it means designating a 2nd margin of error. saloon does something similar with rtol and etol.
  1. Any style issues?
  • Glicko-2 is a strictly linear, step-by-step process and as such I feel like it should probably be a |^ core, with +update-player moving into the $ arm. I tried this at some point in the last couple of weeks but had some trouble with it. For now, I've just been focussed on getting the logic down.
  • It's a little too Pythonic. I think instances where =player is being passed into a gate could be narrowed down to =r, =rd, or =vol as appropriate.
  • I think I could probably break it down into a few more arms. Maybe new-vol and +update-player would benefit. I wouldn't want to strictly adhere to the paper with arms like +step-2, +step-6 etc. because this library will eventually be superceded by a one or more libraries capable of supporting >1v1 matches and games.

Comment thread src/lib/glicko2.hoon
Comment on lines +9 to +26
++ add
add:^rd
++ sub
sub:^rd
++ mul
mul:^rd
++ div
div:^rd
++ gth
gth:^rd
++ lth
lth:^rd
++ lte
lte:^rd
++ sig
sig:^rd
++ sqt
sqt:^rd

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Use of ^ rightly prohibited in the chess style guide, but [add: rd] etc. doesn't compile. I've not tried :- add: rd. But I suspect that would cause the $rd namespace collision too.

Comment thread src/lib/glicko2.hoon
++ g
:: step 3
|= =rd ^- @rd
:: g(φ) = 1/√(1 + 3φ^2/π^2)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if √(x + x) is the correct way to represent "square root of (x + x)"; is there a standard for this anywhere? It would help with the arms involving Σ.

Comment thread src/lib/glicko2.hoon
Comment on lines +64 to +76
++ pow-n
|= [x=@rd n=@rd] ^- @rd
?: =(n .~0) .~1
=/ p x
|- ^- @rd
?: (lth n .~2)
?: (sig x)
p
(neg p)
%= $
p (mul p x)
n (sub n .~1)
==

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

With +add:rd becoming +add above, this +pow-n looks out of place in code because it's not +pow. I've kept it this way because it's described in saloon as "restricted pow, based on integers only", and I'm not sure whether or not that distinction is worth making.

Comment thread src/lib/glicko2.hoon
Comment on lines +258 to +259
|= [=player =r-list =rd-list =out-list v=@rd] ^- @rd
.~0.059997693828601574

@bonbud-macryg bonbud-macryg Mar 25, 2023

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

With +new-vol's loop bug, this is just returning the expected output based on our one test case, shared with glicko2.py and glicko2.js.

Comment thread src/lib/glicko2.hoon
Comment thread src/lib/glicko2.hoon
::=/ f |=(x=@rd (~(f make-f player delta v a) x))
:::: set A = a = ln(σ^2)
::=/ b
:: :: XX does this have to be its own gate within this arm?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Technically? Probably not. Stylistically? Maybe.

Comment thread src/lib/glicko2.hoon
:: ?: (gth (pow-n delta .~2) (add (pow-n rd.player .~2) v))
:: :: set B = ln(∆^2 − φ^2 − v)
:: (log :(sub (pow-n delta .~2) (pow-n rd.player .~2) v))
:: ~& >> "1st loop!"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

~&s throughout this arm for debugging purposes.

Comment thread src/sur/glicko2.hoon
+$ eps
$~ .~0.0000001
@rd
::

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

eps is defined in /sur! Which one should I remove?

Comment thread src/sur/glicko2.hoon
@bonbud-macryg

Copy link
Copy Markdown
Collaborator Author

Closed in favour of #21. If we implement Glicko2 it should use #21 as a foundation.

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