Created
November 21, 2011 21:24
-
-
Save hexgnu/1383990 to your computer and use it in GitHub Desktop.
Mapping from user input to scores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'distribution' | |
module Z | |
extend self | |
Z_EPSILON = 10e-16 | |
Z_MAX = 6.0 | |
def critical_z(p) | |
minz = -Z_MAX | |
maxz = Z_MAX | |
zval = 0.0 | |
return -1 unless (0..1) === (p) | |
while ((maxz - minz) > Z_EPSILON) | |
pval = Distribution::Normal.cdf(zval) | |
if pval > p | |
maxz = zval | |
else | |
minz = zval | |
end | |
zval = (maxz + minz) * 0.5 | |
end | |
zval | |
end | |
def score(p) | |
if (0..1) === p | |
critical_z(p) | |
else | |
raise 'Must be between 0 and 1' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment