Changeset 11398:7e9b4eb30015 in orange
 Timestamp:
 03/12/13 17:05:00 (13 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/classification/logreg.py
r11397 r11398 921 921 ## PROBABILITY CALCULATIONS 922 922 923 def lchisqprob(chisq, df):923 def lchisqprob(chisq, df): 924 924 """ 925 925 Return the (1tailed) probability value associated with the provided … … 927 927 """ 928 928 BIG = 20.0 929 929 930 def ex(x): 930 931 932 933 934 935 if chisq <= 0 or df < 1:936 931 BIG = 20.0 932 if x < BIG: 933 return 0.0 934 else: 935 return math.exp(x) 936 if chisq <= 0 or df < 1: 937 return 1.0 937 938 a = 0.5 * chisq 938 if df %2 == 0:939 939 if df % 2 == 0: 940 even = 1 940 941 else: 941 942 even = 0 942 943 if df > 1: 943 944 y = ex(a) 944 945 if even: 945 946 s = y 946 947 else: 947 948 s = 2.0 * zprob(math.sqrt(chisq)) … … 954 955 if a > BIG: 955 956 if even: 956 957 e = 0.0 957 958 else: 958 959 e = math.log(math.sqrt(math.pi)) 959 960 c = math.log(a) 960 961 while (z <= chisq): 961 962 s = s + ex(c*zae)963 962 e = math.log(z) + e 963 s = s + ex(c * z  a  e) 964 z = z + 1.0 964 965 return s 965 966 else: … … 970 971 c = 0.0 971 972 while (z <= chisq): 972 e = e * (a /float(z))973 e = e * (a / float(z)) 973 974 c = c + e 974 975 z = z + 1.0 975 return (c *y+s)976 return (c * y + s) 976 977 else: 977 978 return s … … 981 982 """ 982 983 Returns the area under the normal curve 'to the left of' the given z value. 983 Thus:: 984 Thus:: 984 985 985 986 for z<0, zprob(z) = 1tail probability … … 991 992 Z_MAX = 6.0 # maximum meaningful zvalue 992 993 if z == 0.0: 993 994 x = 0.0 994 995 else: 995 996 if y >= (Z_MAX*0.5):997 998 999 w = y*y1000 1001 0.001075204047) * w +0.005198775019) * w1002 0.019198292004) * w +0.059054035642) * w1003 0.151968751364) * w +0.319152932694) * w1004 0.531923007300) * w +0.797884560593) * y * 2.01005 1006 1007 1008 +0.000152529290) * y 0.000019538132) * y1009 0.000676904986) * y +0.001390604284) * y1010 0.000794620820) * y 0.002034254874) * y1011 +0.006549791214) * y 0.010557625006) * y1012 +0.011630447319) * y 0.009279453341) * y1013 +0.005353579108) * y 0.002141268741) * y1014 +0.000535310849) * y +0.999936657524996 y = 0.5 * math.fabs(z) 997 if y >= (Z_MAX * 0.5): 998 x = 1.0 999 elif (y < 1.0): 1000 w = y * y 1001 x = ((((((((0.000124818987 * w 1002  0.001075204047) * w + 0.005198775019) * w 1003  0.019198292004) * w + 0.059054035642) * w 1004  0.151968751364) * w + 0.319152932694) * w 1005  0.531923007300) * w + 0.797884560593) * y * 2.0 1006 else: 1007 y = y  2.0 1008 x = (((((((((((((0.000045255659 * y 1009 + 0.000152529290) * y  0.000019538132) * y 1010  0.000676904986) * y + 0.001390604284) * y 1011  0.000794620820) * y  0.002034254874) * y 1012 + 0.006549791214) * y  0.010557625006) * y 1013 + 0.011630447319) * y  0.009279453341) * y 1014 + 0.005353579108) * y  0.002141268741) * y 1015 + 0.000535310849) * y + 0.999936657524 1015 1016 if z > 0.0: 1016 prob = ((x+1.0)*0.5)1017 prob = ((x + 1.0) * 0.5) 1017 1018 else: 1018 prob = ((1.0x)*0.5)1019 prob = ((1.0  x) * 0.5) 1019 1020 return prob 1020 1021
Note: See TracChangeset
for help on using the changeset viewer.