Skip to content

Instantly share code, notes, and snippets.

@hexgnu
Created November 21, 2011 21:24
Show Gist options
  • Save hexgnu/1383990 to your computer and use it in GitHub Desktop.
Save hexgnu/1383990 to your computer and use it in GitHub Desktop.
Mapping from user input to scores
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