@@ -0,0 +1,2610 @@
+# NOTE: contains only one test, _est_cont_fit, that is renamed so that%0D%0A#       nose doesn't run it%0D%0A# I put this here for the record and for the case when someone wants to%0D%0A# verify the quality of fit%0D%0A# with current parameters: %0D%0A%0D%0A%0D%0Aimport numpy.testing as npt%0D%0Aimport numpy as np%0D%0A%0D%0Afrom scipy import stats%0D%0A%0D%0Afrom test_continuous_basic import distcont%0D%0A%0D%0A# this is not a proper statistical test for convergence, but only%0D%0A# verifies that the estimate and true values don't differ by too much%0D%0An_repl1 = 1000 # sample size for first run%0D%0An_repl2 = 5000 # sample size for second run, if first run fails%0D%0Athresh_percent = 0.25 # percent of true parameters for fail cut-off%0D%0Athresh_min = 0.75  # minimum difference estimate - true to fail test%0D%0A%0D%0A#distcont = %5B%5B'genextreme', (3.3184017469423535,)%5D%5D%0D%0A%0D%0Adef test_cont_fit():%0D%0A    # this tests the closeness of the estimated parameters to the true%0D%0A    # parameters with fit method of continuous distributions%0D%0A    # Note: is slow, some distributions don't converge with sample size %3C= 10000%0D%0A%0D%0A    for distname, arg in distcont:%0D%0A        yield check_cont_fit, distname,arg%0D%0A%0D%0A%0D%0Adef check_cont_fit(distname,arg):        %0D%0A    distfn = getattr(stats, distname)%0D%0A    rvs = distfn.rvs(size=n_repl1,*arg)%0D%0A    est = distfn.fit(rvs)  #,*arg) # start with default values%0D%0A%0D%0A    truearg = np.hstack(%5Barg,%5B0.0,1.0%5D%5D)%0D%0A    diff = est-truearg%0D%0A        %0D%0A    txt = ''%0D%0A    diffthreshold = np.max(np.vstack(%5Btruearg*thresh_percent,%0D%0A                    np.ones(distfn.numargs+2)*thresh_min%5D),0)%0D%0A    # threshold for location%0D%0A    diffthreshold%5B-2%5D = np.max(%5Bnp.abs(rvs.mean())*thresh_percent,thresh_min%5D)%0D%0A    %0D%0A    if np.any(np.isnan(est)):%0D%0A        raise AssertionError, 'nan returned in fit'%0D%0A    else:  %0D%0A        if np.any((np.abs(diff) - diffthreshold) %3E 0.0):%0D%0A##            txt = 'WARNING - diff too large with small sample'%0D%0A##            print 'parameter diff =', diff - diffthreshold, txt%0D%0A            rvs = np.concatenate(%5Brvs,distfn.rvs(size=n_repl2-n_repl1,*arg)%5D)%0D%0A            est = distfn.fit(rvs) #,*arg)%0D%0A            truearg = np.hstack(%5Barg,%5B0.0,1.0%5D%5D)%0D%0A            diff = est-truearg%0D%0A            if np.any((np.abs(diff) - diffthreshold) %3E 0.0):%0D%0A                txt  = 'parameter: %25s%5Cn' %25 str(truearg)%0D%0A                txt += 'estimated: %25s%5Cn' %25 str(est)%0D%0A                txt += 'diff     : %25s%5Cn' %25 str(diff)%0D%0A                raise AssertionError, 'fit not very good in %25s%5Cn' %25 distfn.name + txt%0D%0A                %0D%0A%0D%0A%0D%0Aif __name__ == %22__main__%22:%0D%0A    import nose%0D%0A    #nose.run(argv=%5B'', __file__%5D)%0D%0A    nose.runmodule(argv=%5B__file__,'-s'%5D, exit=False)%0D%0A

add fit test for record, test is renamed so nose doesn't run it