(************** Content-type: application/mathematica **************
Mathematica-Compatible Notebook
This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.
To get the notebook into a Mathematica-compatible application, do
one of the following:
* Save the data starting with the line of stars above into a file
with a name ending in .nb, then open the file inside the
application;
* Copy the data starting with the line of stars above to the
clipboard, then use the Paste menu command inside the application.
Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode. Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).
NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.
For more information on notebooks and Mathematica-compatible
applications, contact Wolfram Research:
web: http://www.wolfram.com
email: info@wolfram.com
phone: +1-217-398-0700 (U.S.)
Notebook reader applications are available free of charge from
Wolfram Research.
*******************************************************************)
(*CacheID: 232*)
(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[ 10225, 307]*)
(*NotebookOutlinePosition[ 10870, 329]*)
(* CellTagsIndexPosition[ 10826, 325]*)
(*WindowFrame->Normal*)
Notebook[{
Cell["\<\
This notebook is designed to be executed in order. Some of the functions \
remember their previous values, so if you execute the notebook out of order \
it might be good to clear the functions or restart the kernel. There are \
optional examples included, which can be executed again or opened.\
\>", "Text",
FontSize->16],
Cell["\<\
These are the supposed probabilities of winning a match of length n if the \
true rating difference is d points on FIBS.\
\>", "Text"],
Cell[BoxData[
\(fp[d_, n_] := \(fp[d, n] =
N[1/\((1 + 10^\((\(-d\)\ Sqrt[n]/2000)\))\), 20]\)\)], "Input"],
Cell["\<\
Example: The estimated probability of winning a 25 point match if one is 50 \
points stronger.\
\>", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
\(fp[50, 25]\)], "Input"],
Cell[BoxData[
\(0.571463117408381432348240479263396`20\)], "Output"]
}, Closed]],
Cell[TextData[{
"This gives True if a uniformly distributed on [0,1] random variable is \
less than p, and False otherwise. I believe that ",
StyleBox["Mathematica",
FontSlant->"Italic"],
"'s pseudo random number generator is good enough for these purposes, \
though I have not tested it in detail."
}], "Text"],
Cell[BoxData[
\(win[p_] := {Random[] < p}[\([1]\)]\)], "Input"],
Cell[TextData[{
"This fixes the level of precision of x to n digits after the decimal \
point. Otherwise, in repeated calculations ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" loses precision erratically far faster than it ought to, probably because \
it loses track of how many digits are accurate when there are a lot of zeros \
at the end of the window of precision."
}], "Text"],
Cell[BoxData[
\(fixprecision[x_, n_] := N[IntegerPart[x\ 10^n]/10^n, n]\)], "Input"],
Cell["\<\
The following take in the previous rating, the opponent's rating, the length \
of the match, and whether one won (True) or not (False). \
\>", "Text"],
Cell[BoxData[
\(fnewrat[oldrat_, opprat_, n_, wins_] :=
fixprecision[
oldrat +
4\ Sqrt[n]
If[wins,
1 - fp[oldrat - opprat, n], \(-fp[oldrat - opprat, n]\)],
20]\)], "Input"],
Cell["\<\
The following is the force law with win probability function sp and rating \
snewrat of a player with strength rat1, rating rat2, and opponent strength \
opprat, for an n point match. I have not included other probability function \
and rating formulas, so sp should always be fp and snewrat should always be \
fnewrat.\
\>", "Text"],
Cell[BoxData[
\(drift[sp_, \ snewrat_, rat1_, rat2_, opprat_,
n_] := \(drift[sp, \ snewrat, rat1, rat2, opprat, n] =
sp[rat1 - opprat, n]
snewrat[rat2, opprat, n, True] + \((1 - sp[rat1 - opprat, n])\)
snewrat[rat2, opprat, n, False] - rat2\)\)], "Input"],
Cell["The following is the drift per experience point.", "Text"],
Cell[BoxData[
\(driftperexp[sp_, \ snewrat_, rat1_, rat2_, opprat_, n_] :=
drift[sp, \ snewrat, rat1, rat2, opprat, n]/n\)], "Input"],
Cell["\<\
The following is the drift per experience point of a player with playing \
strength 0, rating delta, and opponent strength and rating opprat.\
\>", "Text"],
Cell[BoxData[
\(dperexp[sp_, snewrat_, delta_, opprat_,
n_] := \(dperexp[sp, snewrat, delta, opprat, n] =
driftperexp[sp, \ snewrat, 0, delta, opprat, n]\)\)], "Input"],
Cell["\<\
The following is the variance per experience point. It should be the total \
stakes^2 p (1-p). The playing strength is assumed to be 0, and the oppenent \
has strength opprat.\
\>", "Text"],
Cell[BoxData[
\(varperexp[sp_, snewrat_, opprat_,
n_] := \(varperexp[sp, snewrat, opprat,
n] = \((\((snewrat[0, 0, n, True] -
snewrat[0, 0, n, False])\)^2\ sp[opprat,
n] \((1 - sp[opprat, n])\))\)/n\)\)], "Input"],
Cell["This is the k drift/variance.", "Text"],
Cell[BoxData[
\(ffactor[sp_, snewrat_, currat_, truerat_, opprat_,
n_] := \(ffactor[sp, snewrat, currat, truerat, opprat, n] =
2\ dperexp[sp, snewrat, currat - truerat, opprat - truerat, n]/
varperexp[sp, snewrat, truerat - opprat, n]\)\)], "Input"],
Cell["\<\
The stable distribution has probability density function pdf(x). The \
differential equation it satisfies is f'/f = ffactor. ctimespf is off by a \
constant factor, computed in normfibs.\
\>", "Text"],
Cell[BoxData[
\(ctimespdf[sp_, snewrat_, x_, opprat_, n_] :=
E^NIntegrate[
ffactor[sp, snewrat, t, 0, opprat, n], {t, 0, x}]\)], "Input"],
Cell[BoxData[
\(normfibs[opprat_, matchlength_] := \(normfibs[opprat, matchlength] =
NIntegrate[
ctimespdf[fp, fnewrat, x, opprat, matchlength], {x, \(-2000\),
2000}]\)\)], "Input"],
Cell[BoxData[
\(pdffibs[x_, opprat_, n_] :=
ctimespdf[fp, fnewrat, x, opprat, n]/normfibs[opprat, n]\)], "Input"],
Cell["\<\
To find the probability that one is between rat1 and rat2, numerically \
integrate pdffibs[x,_,_] from x=rat1 to x=rat2.\
\>", "Text"],
Cell[TextData[{
"The following gives the nth moment of the stable distribution on FIBS \
assuming opponents stronger by opprat and matches of length k. fibsstddev \
computes the standard deviation, with a miniscule error used to avoid a \
complaint by ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" when a numerical integral produces a value close to 0."
}], "Text"],
Cell[BoxData[
\(fibsnthmoment[opprat_, k_, n_] :=
NIntegrate[x^n\ pdffibs[x, opprat, k], {x, \(-1000\), 1000}]\)], "Input"],
Cell[BoxData[
\(fibsstddev[opprat_, k_] :=
Sqrt[fibsnthmoment[opprat, k, 2] -
fibsnthmoment[opprat + 0.01, k, 1]^2]\)], "Input"],
Cell["\<\
Example: The standard deviation of the stable distribution when one plays \
5-point matches against opponents who are correctly rated 400 points \
stronger.\
\>", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
\(fibsstddev[400, 5]\)], "Input"],
Cell[BoxData[
\(41.75303644224748`\)], "Output"]
}, Closed]],
Cell["\<\
For the purpose of finding percentiles of the distributions, the following is \
Newton's Method. iternm iterates this n times on the initial guess of x.\
\>", "Text"],
Cell[BoxData[
\(NewtonsMethod[f_, df_, x_, targval_] :=
x - \((f[x] - targval)\)/df[x]\)], "Input"],
Cell[BoxData[
\(iternm[f_, df_, x_, targval_, n_] := \[IndentingNewLine]NestList[
Function[t, NewtonsMethod[f, df, t, targval]], x, n]\)], "Input"],
Cell["\<\
Opponent's rating is opprat. The match length is n. fracabove is the desired \
fraction of the stable distribution above the output. k is the number of \
iterations of Newton's Method to use. If the last two values in the output \
are equal (usually for k>=5) then Newton's Method has converged and you can \
trust the last value given.\
\>", "Text"],
Cell[BoxData[
\(fibspercentile[opprat_, n_, fracabove_, k_] :=
iternm[Function[t, NIntegrate[pdffibs[x, opprat, n], {x, t, 1000}]],
Function[t, \(-pdffibs[t, opprat, n]\)], 0, fracabove, k]\)], "Input"],
Cell["\<\
The following computes the 90th percentile of the stable distribution. 10% of \
the time, one should be overrated by at least 53.4739 points if one only \
plays 5-point matches against people who are correctly rated at one's true \
rating.\
\>", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
\(fibspercentile[0, 5, 1/10, 5]\)], "Input"],
Cell[BoxData[
\({0, 41.820052760363275`, 51.86175548583558`, 53.43539712694747`,
53.473885452213075`, 53.473908222839576`}\)], "Output"]
}, Closed]],
Cell["\<\
Another example. This computes the 30th percentile when one plays 1 point \
matches against players who are correctly rated at 100 points stronger.\
\>", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
\(fibspercentile[100, 1, 7/10, 5]\)], "Input"],
Cell[BoxData[
\({0, \(-20.936339307661825`\), \(-21.89809716897574`\), \
\(-21.903797091517117`\), \(-21.90379729615721`\), \
\(-21.903797296157386`\)}\)], "Output"]
}, Closed]],
Cell["\<\
When one plays people who are stronger or weaker, the mode of the stable \
distribution is one's correct rating, but not the median.\
\>", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
\(fibspercentile[100, 25, 1/2, 5]\)], "Input"],
Cell[BoxData[
\({0, \(-0.939071854830435`\), \(-0.9391512900963661`\), \
\(-0.9391512900980546`\), \(-0.9391512900980546`\), \(-0.9391512900980546`\)}\
\)], "Output"]
}, Closed]]
},
FrontEndVersion->"4.1 for Microsoft Windows",
ScreenRectangle->{{0, 1024}, {0, 695}},
WindowSize->{496, 537},
WindowMargins->{{21, Automatic}, {27, Automatic}}
]
(*******************************************************************
Cached data follows. If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of the file. The cache data will then be recreated when
you save this file from within Mathematica.
*******************************************************************)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[1705, 50, 334, 6, 106, "Text"],
Cell[2042, 58, 144, 3, 52, "Text"],
Cell[2189, 63, 119, 2, 30, "Input"],
Cell[2311, 67, 118, 3, 33, "Text"],
Cell[CellGroupData[{
Cell[2454, 74, 43, 1, 30, "Input"],
Cell[2500, 77, 72, 1, 29, "Output"]
}, Closed]],
Cell[2587, 81, 321, 7, 68, "Text"],
Cell[2911, 90, 67, 1, 30, "Input"],
Cell[2981, 93, 398, 8, 90, "Text"],
Cell[3382, 103, 88, 1, 30, "Input"],
Cell[3473, 106, 160, 3, 52, "Text"],
Cell[3636, 111, 240, 7, 90, "Input"],
Cell[3879, 120, 343, 6, 90, "Text"],
Cell[4225, 128, 303, 5, 110, "Input"],
Cell[4531, 135, 64, 0, 33, "Text"],
Cell[4598, 137, 144, 2, 50, "Input"],
Cell[4745, 141, 165, 3, 52, "Text"],
Cell[4913, 146, 190, 3, 70, "Input"],
Cell[5106, 151, 199, 4, 52, "Text"],
Cell[5308, 157, 275, 5, 90, "Input"],
Cell[5586, 164, 45, 0, 33, "Text"],
Cell[5634, 166, 283, 4, 90, "Input"],
Cell[5920, 172, 210, 4, 52, "Text"],
Cell[6133, 178, 158, 3, 70, "Input"],
Cell[6294, 183, 217, 4, 90, "Input"],
Cell[6514, 189, 124, 2, 50, "Input"],
Cell[6641, 193, 144, 3, 52, "Text"],
Cell[6788, 198, 380, 8, 90, "Text"],
Cell[7171, 208, 134, 2, 50, "Input"],
Cell[7308, 212, 150, 3, 70, "Input"],
Cell[7461, 217, 180, 4, 52, "Text"],
Cell[CellGroupData[{
Cell[7666, 225, 51, 1, 30, "Input"],
Cell[7720, 228, 52, 1, 29, "Output"]
}, Closed]],
Cell[7787, 232, 176, 3, 49, "Text"],
Cell[7966, 237, 110, 2, 50, "Input"],
Cell[8079, 241, 159, 2, 70, "Input"],
Cell[8241, 245, 360, 6, 90, "Text"],
Cell[8604, 253, 222, 3, 110, "Input"],
Cell[8829, 258, 263, 5, 71, "Text"],
Cell[CellGroupData[{
Cell[9117, 267, 62, 1, 30, "Input"],
Cell[9182, 270, 147, 2, 29, "Output"]
}, Closed]],
Cell[9344, 275, 171, 3, 49, "Text"],
Cell[CellGroupData[{
Cell[9540, 282, 64, 1, 30, "Input"],
Cell[9607, 285, 169, 3, 29, "Output"]
}, Closed]],
Cell[9791, 291, 156, 3, 49, "Text"],
Cell[CellGroupData[{
Cell[9972, 298, 64, 1, 30, "Input"],
Cell[10039, 301, 170, 3, 29, "Output"]
}, Closed]]
}
]
*)
(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)