Repository: statsmodels/statsmodels

Issue:
parallel processing
just some thoughts

do we use joblib?

Alexandre rewrote the permutation t-test to use joblib.

Problems on Windows 

http://sourceforge.net/mailarchive/forum.php?thread_name=CAFvE7K5adiMWa9VZHn8G3fTheU3t1_ymdWOZF1bVm1tMA1Sm1w%40mail.gmail.com&forum_name=scikit-learn-general

see especially Robert's comments

cost of creating new process on Windows:
my guess: if each new process needs to import scipy.stats, then there is not much point to multiprocessing on Windows.
correct or not?  (example would be an rvs from scipy.stats.distributions)



Discussion:
added joblib in #111

for discussion
https://groups.google.com/group/pystatsmodels/browse_thread/thread/72fe8d8369e1d53e
https://groups.google.com/group/pystatsmodels/browse_thread/thread/c2dbea9345778ad7

conclusion was 
importing joblib from scikit-learn is slow
needs at least a few seconds of calculations to pay for the extra cost


Resolving patch:
diff --git a/statsmodels/tools/numdiff.py b/statsmodels/tools/numdiff.py
--- a/statsmodels/tools/numdiff.py
+++ b/statsmodels/tools/numdiff.py
@@ -79,7 +79,7 @@
 
 def _get_epsilon(x, s, epsilon, n):
     if epsilon is None:
-        h = EPS**(1./s)*x
+        h = EPS**(1. / s) * np.maximum(np.abs(x), 0.1)
     else:
         if np.isscalar(epsilon):
             h = np.empty(n)


Test patch:
diff --git a/statsmodels/tools/tests/test_numdiff.py b/statsmodels/tools/tests/test_numdiff.py
--- a/statsmodels/tools/tests/test_numdiff.py
+++ b/statsmodels/tools/tests/test_numdiff.py
@@ -8,7 +8,7 @@
 '''
 
 import numpy as np
-from numpy.testing import assert_almost_equal
+from numpy.testing import assert_almost_equal, assert_allclose
 import statsmodels.api as sm
 from statsmodels.tools import numdiff
 from statsmodels.tools.numdiff import (approx_fprime, approx_fprime_cs,
@@ -49,7 +49,7 @@ def test_score(self):
 
             sccs = numdiff.approx_fprime_cs(test_params.ravel(),
                                                       self.mod.loglike)
-            assert_almost_equal(sc, sccs, decimal=12)
+            assert_almost_equal(sc, sccs, decimal=11)
 
     def test_hess(self):
         for test_params in self.params:
@@ -61,18 +61,18 @@ def test_hess(self):
             assert_almost_equal(he, hefd, decimal=7)
             hefd = numdiff.approx_fprime(test_params, self.mod.score,
                                          centered=True)
-            assert_almost_equal(he, hefd, decimal=7)
+            assert_allclose(he, hefd, rtol=5e-10)
             hefd = numdiff.approx_fprime(test_params, self.mod.score,
                                          centered=False)
             assert_almost_equal(he, hefd, decimal=4)
 
             hescs = numdiff.approx_fprime_cs(test_params.ravel(),
                                                         self.mod.score)
-            assert_almost_equal(he, hescs, decimal=DEC8)
+            assert_allclose(he, hescs, rtol=1e-13)
 
             hecs = numdiff.approx_hess_cs(test_params.ravel(),
                                                         self.mod.loglike)
-            assert_almost_equal(he, hecs, decimal=DEC6)
+            assert_allclose(he, hecs, rtol=1e-9)
 
             #NOTE: Look at the lack of precision - default epsilon not always
             #best
diff --git a/statsmodels/tsa/tests/test_ar.py b/statsmodels/tsa/tests/test_ar.py
--- a/statsmodels/tsa/tests/test_ar.py
+++ b/statsmodels/tsa/tests/test_ar.py
@@ -3,7 +3,7 @@
 """
 import statsmodels.api as sm
 from statsmodels.tsa.ar_model import AR
-from numpy.testing import (assert_almost_equal, assert_equal, #assert_allclose,
+from numpy.testing import (assert_almost_equal, assert_equal, assert_allclose,
                            assert_)
 from results import results_ar
 import numpy as np
@@ -156,17 +156,17 @@ def test_dynamic_predict(self):
         # 9, 51
         start, end = 9, 51
         fv = res1.predict(start, end, dynamic=True)
-        assert_almost_equal(fv, res2.fcdyn[start:end+1], DECIMAL_4)
+        assert_allclose(fv, res2.fcdyn[start:end+1], rtol=7e-6)
 
         # 9, 308
         start, end = 9, 308
         fv = res1.predict(start, end, dynamic=True)
-        assert_almost_equal(fv, res2.fcdyn[start:end+1], DECIMAL_4)
+        assert_allclose(fv, res2.fcdyn[start:end+1], rtol=7e-6)
 
         # 9, 333
         start, end = 9, 333
         fv = res1.predict(start, end, dynamic=True)
-        assert_almost_equal(fv, res2.fcdyn[start:end+1], DECIMAL_4)
+        assert_allclose(fv, res2.fcdyn[start:end+1], rtol=7e-6)
 
         # 100, 151
         start, end = 100, 151