Skip to content
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

Fix of gauss_2d_large(seed=63) -> NaN #76

Merged
merged 5 commits into from Jan 23, 2019

Conversation

abukaj
Copy link
Member

@abukaj abukaj commented Jan 22, 2019

kcsd.validation.csd_profile.gauss_2d_large(seed=63) does not return
NaN anymore.

repeatUntilValid() decorator has been defined for that purpose.

A simple test for the fix provided in the __main__ section of the module.

Note: The issue has not been solved by fixing distribution of
the zs variable in order to provide backward-compatibility.

`kcsd.validation.csd_profile.gauss_2d_large(seed=63)` does not return
NaN anymore.

`repeatUntilValid()` decorator has been defined for that purpose.

A simple test for the fix provided in the `__main__` section of the module.

Note: The issue has not been solved by fixing distribution of
the `zs` variable in order to provide backward-compatibility.
@coveralls
Copy link

coveralls commented Jan 22, 2019

Pull Request Test Coverage Report for Build 159

  • 18 of 25 (72.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.09%) to 60.271%

Changes Missing Coverage Covered Lines Changed/Added Lines %
kcsd/validation/csd_profile.py 18 25 72.0%
Totals Coverage Status
Change from base Build 154: 0.09%
Covered Lines: 1693
Relevant Lines: 2809

💛 - Coveralls

…on.csd_profile.repeatUntilValid()` decorator.
@ccluri
Copy link
Collaborator

ccluri commented Jan 22, 2019

Nice workaround!
This should apply to 1D and 3D, small and large as well - right?

Although I only tested for seeds between 1-100, maybe the seeds else where have the same issue?

@abukaj
Copy link
Member Author

abukaj commented Jan 22, 2019

@ccluri Thanks! I have not checked the other functions but I will do in a moment. A respective commit shall arrive today.

@ccluri
Copy link
Collaborator

ccluri commented Jan 22, 2019

I would say use something like
seed = rstate.randint(2**32 - seed)
Just so its not the same seed for all the failed candidates.
Over engineering - yes.

@abukaj
Copy link
Member Author

abukaj commented Jan 22, 2019

@ccluri
The 2**32 argument of rstate.randint() is the upper bound (exclusive) on the random int. Also on the seed parameter of np.random.RandomState constructor.

The actual seed for rstate.randint() is given when the rstate object is created. The idea is to have a 'seedchain' seed[n+1] = randint(2**32, seed=seed[n]).

BTW: I am testing the csd_profile functions with the following code (I hope):

import numpy as np
from kcsd import csd_profile as CSD
import collections
x1d = np.mgrid[0.:1.:10j]
x2d = np.mgrid[0.:1.:10j, 0.:1.:10j]
x3d = np.mgrid[0.:1.:10j, 0.:1.:10j, 0.:1.:10j]
seed = 0
fails = []
fs = [CSD.gauss_1d_mono, CSD.gauss_1d_dipole, CSD.gauss_2d_large, CSD.gauss_2d_small, CSD.gauss_3d_small, CSD.gauss_3d_large]
while True: 
     if seed % 10000 == 0: 
         print(f'Fails for seed < {seed}:') 
         for name, n in collections.Counter(a for a,_ in fails).items(): 
             print(f' {name} : {n}') 
              
     for f in fs: 
         try: 
             res = f(x3d, seed) 
         except ValueError: 
             try: 
                 res = f(x2d, seed) 
             except ValueError: 
                 res = f(x1d, seed) 
         if not np.isfinite(res).any(): 
             fails.append((f.__name__, seed)) 
             #print(f"{f.__name__}({seed})") 
              
     seed += 1 

So far (for 0 <= seed < 600000) only gauss_2d_large() has failed (1158 times).

@ccluri
Copy link
Collaborator

ccluri commented Jan 22, 2019

Okay, let me know when you are content with the update - I am happy to merge when you are.

Seed sequence generation moved to `seedSequence()` generator function.
@abukaj
Copy link
Member Author

abukaj commented Jan 22, 2019

@ccluri I am happy with gauss_2d_large() implementation in f59c426. Did you say something about over engineering? ;)
But let's wait till tomorrow for results for other non-decorated functions. So far seeds < 4840000 caused no problem.

@abukaj
Copy link
Member Author

abukaj commented Jan 23, 2019

@ccluri I have tested 46600000 seeds. No NaNs returned by other functions.

@ccluri ccluri merged commit 5819472 into Neuroinflab:master Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants