Skip to content

Instantly share code, notes, and snippets.

@m1el
Last active March 28, 2021 17:05
Show Gist options
  • Save m1el/5f86205a249dcacd05e73697b0fce44c to your computer and use it in GitHub Desktop.
Save m1el/5f86205a249dcacd05e73697b0fce44c to your computer and use it in GitHub Desktop.
sdutils
set term svg
set output 'sdist_under.svg'
set xrange [-4:4]
set yrange [0:0.45]
set samples 1000
plot \
x < 1 ? exp(-x*x/2)/sqrt(6.283185307179586) : 1/0 with filledcurves x1 lc rgb "grey", \
exp(-x*x/2)/sqrt(6.283185307179586) lw 2 lc rgb "black"
set output 'sdist_inside.svg'
plot \
abs(x) < 1 ? exp(-x*x/2)/sqrt(6.283185307179586) : 1/0 with filledcurves x1 lc rgb "grey", \
exp(-x*x/2)/sqrt(6.283185307179586) lw 2 lc rgb "black"
import math
import scipy.special as sp
SQRT2 = math.sqrt(2)
'''
See https://i.imgur.com/UqmxwuF.png for visualisation of these probabilities
'''
'''find P(value < μ + arg*σ), or area to the left of certain value'''
def sdu(arg):
return (sp.erf(arg / SQRT2) + 1) / 2
'''find P(μ + a*σ < value < μ + b*σ), or area between cetain values'''
def sdr(a, b):
return (sp.erf(b / SQRT2) - sp.erf(a / SQRT2)) / 2
'''find P(abs(value - μ) < arg*σ), or area within certain distance from mean'''
def sdi(arg):
return sp.erf(arg / SQRT2)
'''find x such that P(value < μ + xσ) = p'''
def sdu_inv(p):
return sp.erfinv(p * 2 - 1) * SQRT2
'''find x such that P(abs(value - μ) < xσ) = p'''
def sdi_inv(p):
return sp.erfinv(p) * SQRT2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment