Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Failure: test_noncentral_f in random (Trac #1801) #2394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 6 comments
Closed

Failure: test_noncentral_f in random (Trac #1801) #2394

numpy-gitbot opened this issue Oct 19, 2012 · 6 comments

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/1801 on 2011-04-17 by @rgommers, assigned to unknown.

Reported by Christoph Gohlke against 1.6.0b2 on 64-bit Windows with MKL. Unlike #2361 this seems to be a real bug, not just about test precision.

======================================================================
FAIL: test_noncentral_f (test_random.TestRandomDist)
----------------------------------------------------------------------
Traceback (most recent call last):
  File
"X:\Python26-x64\lib\site-packages\numpy\random\tests\test_random.py",
line 297, in test_noncentral_f
    np.testing.assert_array_almost_equal(actual, desired, decimal=14)
  File "X:\Python26-x64\lib\site-packages\numpy\testing\utils.py", line
800, in assert_array_almost_equal
    header=('Arrays are not almost equal to %d decimals' % decimal))
  File "X:\Python26-x64\lib\site-packages\numpy\testing\utils.py", line
636, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Arrays are not almost equal to 14 decimals

(mismatch 100.0%)
 x: array([[ 1.62003345,  1.7253997 ],
       [ 0.96735921,  0.42933718],
       [ 0.71714872,  6.24979552]])
 y: array([[ 1.405981  ,  0.34207973],
       [ 3.57715069,  7.92632663],
       [ 0.43741599,  1.17742088]])

Christoph, could you please have a look at this? I haven't got a 64-bit Windows machine available.

@numpy-gitbot
Copy link
Author

@cgohlke wrote on 2011-04-17

The following code returns unexpected results with any of my 64 bit msvc9 builds of numpy 1.5.1 or 1.6.x, and also with EPD 7.0-1 64 bit:

>>> import numpy as np
>>> np.random.seed(1234567890)
>>> np.random.noncentral_f(dfnum=5, dfden=2, nonc=1.0, size=(3, 2))
array([[ 1.62003345,  1.7253997 ],
       [ 0.96735921,  0.42933718],
       [ 0.71714872,  6.24979552]])

Expected result:

array([[ 1.405981  ,  0.34207973],
       [ 3.57715069,  7.92632663],
       [ 0.43741599,  1.17742088]])

The code fails whether MKL is used/linked or not.

The 32 bit msvc9 and 64 bit "Windows Server 2003 R2 Platform SDK" builds are OK. So this seems to be a 64 bit msvc9 specific issue.

Other numpy.random tests pass with the same seed. Specifically, chisquare and noncentral_chisquare return expected results.

The noncentral_f function is implemented in numpy\random\mtrand\distributions.c as

double rk_noncentral_f(rk_state *state, double dfnum, double dfden, double nonc)
{
    return ((rk_noncentral_chisquare(state, dfnum, nonc)*dfden) /
            (rk_chisquare(state, dfden)*dfnum));
}

I changed the function to the following, which does return the correct results:

double rk_noncentral_f(rk_state *state, double dfnum, double dfden, double nonc)
{
    double t1, t2;
    t1 = rk_noncentral_chisquare(state, dfnum, nonc) * dfden;
    t2 = rk_chisquare(state, dfden) * dfnum;
    t1 /= t2;
    return t1;
}

So far I only tested this with numpy-1.5.1.win-amd64-py2.6.

@numpy-gitbot
Copy link
Author

@rgommers wrote on 2011-04-17

Strange problem. Your change looks OK to me and works with Python 3.1 on OS X.

@numpy-gitbot
Copy link
Author

@cgohlke wrote on 2011-04-17

Could be that msvc9 compiled code for amd64 executed rk_chisquare() before rk_noncentral_chisquare(), unlike code compiled by other compilers. In that case the following should work reliable (not tested):

double rk_noncentral_f(rk_state *state, double dfnum, double dfden, double nonc)
{
double t = rk_noncentral_chisquare(state, dfnum, nonc) * dfden;
return t / (rk_chisquare(state, dfden) * dfnum);
}

@numpy-gitbot
Copy link
Author

@cgohlke wrote on 2011-04-18

The attached patch fixes the test failure on win-amd64 and should be safe for all platforms.

@numpy-gitbot
Copy link
Author

Attachment added by @cgohlke on 2011-04-18: mtrand_distributions.diff

@numpy-gitbot
Copy link
Author

@rgommers wrote on 2011-04-22

Thanks, applied in 137ec8e and 7bb23a7e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant