-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
[MRG + 2] Fixes #4385: Move newton_cg test out of optimize #4389
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
Conversation
|
|
sklearn/utils/tests/test_optimize.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole should wrapped in a test_newton_cg function.
5ad1365 to
aed7460
Compare
|
|
|
What do you mean with "Some values"? the test is passing, right? You mean it is only passing for certain random values? Btw, the tests should fix the seed, by doin rng = np.random.RandomState(0)
X = rng.normal(...) |
|
I ran the file separately for a number of times. Yeah, it is passing for certain random values. |
|
can you give an example that is failing? |
[[ 1.15708586e+00 -7.53554218e-01 1.92638340e-01 -4.22095972e-01
1.05947906e+00 7.12534115e-01 -1.08987771e+00 -8.67327002e-02
8.91012678e-01 -6.49361597e-01]
[ 5.11517798e-01 5.42748472e-01 -1.70962041e+00 3.44213266e-01
-6.10681256e-01 1.66858078e-01 -2.78617883e-01 2.21745662e-01
-4.90909754e-01 3.36908877e-02]
[ -1.11800422e+00 -9.53622890e-01 1.22303315e-01 -4.99311580e-01
-1.35566242e+00 1.64765322e-01 -8.43358801e-01 -1.01145299e+00
-1.40650492e+00 -1.40414658e+00]
[ 6.77320171e-01 -6.38708002e-02 2.52441936e+00 3.94445473e-01
-6.46949685e-02 -1.09303154e+00 9.04073980e-01 -6.19499970e-01
1.04766931e+00 1.29344126e+00]
[ 5.62310901e-01 9.73506318e-01 -1.50972147e+00 -1.01770862e+00
-2.09378869e-01 1.49795408e+00 -3.96479915e-01 -3.19679964e-01
-5.85308304e-03 -2.09192281e-01]
[ -9.51038400e-01 9.70086713e-02 1.67750887e-01 2.18236953e-01
8.82427872e-01 -1.22539564e-01 -1.00844742e+00 -1.18707296e+00
-3.57170564e-01 1.43672534e+00]
[ -5.16575904e-01 -5.96124943e-01 -1.49768243e+00 -5.71985026e-01
1.18285232e+00 -3.85196463e-01 -3.28042340e-01 -1.87868432e+00
2.87559046e-01 -9.68149789e-02]
[ 2.17861091e+00 7.19657977e-01 3.44953952e-01 -8.22928846e-01
1.77570729e+00 7.00211315e-01 -2.07695790e+00 -1.41482472e+00
1.10388314e+00 1.32500136e+00]
[ -1.02570053e+00 1.57886815e+00 1.29796026e+00 4.16239032e-01
1.25294762e+00 3.62039055e-02 4.86538339e-01 1.92117054e+00
2.94275635e-01 -2.12145535e+00]
[ 1.01821253e+00 -3.62229904e-01 1.24953113e+00 -7.87755521e-01
-1.92401764e-01 -1.42230643e+00 1.00896705e-01 2.05603117e-03
1.80184012e+00 -1.35195352e+00]]
|
|
Can you just give the random state seed? Also, do you have any idea what the problem could be? |
|
I think RandomState solved it. |
|
|
|
Well but it should work for all seeds, not only for one ;) |
|
Is there any problem in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this different from hess? It seems you use two different interfaces. if you use this here, maybe use fhess in fmin_ncg instead fhess_p?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought the results really shouldn't depend on that.
|
just set tol in |
|
Some cases show convergence warnings for newton_cg but I think that shouldn't be a problem as assert doesn't raise any error. |
|
|
|
Ok thanks, lgtm. |
sklearn/utils/tests/test_optimize.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use a local random number generator with a specific seed:
rng = np.random.RandomState(0) A = rng.normal(size=(10, 10))
|
+1 for merge after the use of a local RNG |
simplified code Used fhess_p Added RandomState Added tol=1e-10 to newton_cg Added RandomState with seed 0
16bacfa to
0cf41c8
Compare
|
@GaelVaroquaux - Used a local RNG and squashed the commits. |
|
Good job! Will merge once travis is green. |
|
Ok :) |
|
|
[MRG + 2] Fixes #4385: Move newton_cg test out of optimize
#4385
I had to make new grad and hess functions from
func_grad_hessto resolve errors. Still, I'm getting an error withfmin_ncg:Traceback (most recent call last): File "test.py", line 25, in assert_almost_equal(newton_cg(func_grad_hess, func, grad, x0), fmin_ncg(f=func, x0=x0, fprime=grad, fhess=hess)) File "/usr/lib/python3.4/site-packages/scipy/optimize/optimize.py", line 1313, in fmin_ncg callback=callback, **opts) File "/usr/lib/python3.4/site-packages/scipy/optimize/optimize.py", line 1405, in _minimize_newtoncg Ap = numpy.dot(A, psupi) TypeError: unsupported operand type(s) for *: 'function' and 'float'Can anyone help me to resolve this?
ping @amueller
UPD The assertion is holding for some values now :|
UPD I think the test works fine now.