Reputation: 77
I am trying to apply the Q-function values for a problem. I don't know the function available for it in Python.
What is the python equivalent for the following code in octave?
>> f=0:0.01:1;
>> qfunc(f)
Upvotes: 0
Views: 11515
Reputation: 1
I've used this Q function for my code and it worked perfectly well,
from scipy import special as sp
def qfunc(x):
return 0.5-0.5*sp.erf(x/sqrt(2))
I'vent used this one but I think it should work,
def invQfunc(x):
return sqrt(2)*sp.erfinv(1-2x)
references: https://mail.python.org/pipermail/scipy-dev/2016-February/021252.html Python equivalent of MATLAB's qfuncinv() Thanks @Anton for letting me know how to write a good answer
Upvotes: 0
Reputation: 71
The Q-function can be expressed in terms of the error function. Check here for more info. "scipy" has the error function, special.erf(), that can be used to calculate the Q-function.
import numpy as np
from scipy import special
f = np.linspace(0,1,101)
0.5 - 0.5*special.erf(f/np.sqrt(2)) # Q(f) = 0.5 - 0.5 erf(f/sqrt(2))
Upvotes: 2
Reputation: 655
Take a look at this https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.stats.norm.html Looks like the norm.sf method (survival function) might be what you're looking for.
Upvotes: 1