def test_pvalues_of_F(): #According to a great online F distribution calculator: # If X = F(3,12), P(X<1.75) = .79 # P(X< 0.5) = 0.31 sigFig = 2 F = stats.f( dimension, sample_size-dimension) print almost_equal(f.cdf(1.75), 0.79, sigFig) print almost_equal(f.cdf(0.5), 0.31, sigFig)
def inv_safe(data): '''I was having some strange things happening where matrices that should be invertible were having incorrect inverses. ''' eps =1e-2 d_sinv = sp.linalg.inv(data) #print data*d_sinv return almost_equal(sp.dot(data,d_sinv), np.eye(data.shape[0]))
def test_inv(): print "Test that inverse is working:" x = True #a,b,c,d,e,f,g,h,i=range(1,10) #a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g for i in range(5): data = np.random.rand(3,3) * 10 #print "next" #print np.dot(sp.linalg.invhilbert(data), data) #print np.dot(sp.linalg.inv(data), data) #print sp.linalg.inv(data) * data #print np.dot(d_inv, data) if not inv_safe(data) and not almost_equal(sp.linalg.det(data),0.0) : print "broken" x = False if x: print "Inverse is working"