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

working auto differentiation, enables the hmc on test cases. #53

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

wdpozzo
Copy link
Collaborator

@wdpozzo wdpozzo commented Oct 14, 2019

whenever autodiff fails reverts to finite differencing with obvious performance degradation. Also fixes a bug in the differential evolution proposal.

… autodiff fails reverts to finite differencing with obvious performance degradation
@pep8speaks
Copy link

pep8speaks commented Oct 14, 2019

Hello @wdpozzo! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 4:1: E302 expected 2 blank lines, found 1
Line 13:55: E251 unexpected spaces around keyword / parameter equals
Line 13:57: E251 unexpected spaces around keyword / parameter equals
Line 14:23: E221 multiple spaces before operator
Line 15:25: E221 multiple spaces before operator
Line 16:18: E221 multiple spaces before operator
Line 17:22: E221 multiple spaces before operator
Line 18:19: E221 multiple spaces before operator
Line 19:15: E221 multiple spaces before operator
Line 20:24: E221 multiple spaces before operator
Line 21:19: E221 multiple spaces before operator
Line 21:54: E231 missing whitespace after ','
Line 21:77: E251 unexpected spaces around keyword / parameter equals
Line 21:79: E251 unexpected spaces around keyword / parameter equals
Line 21:80: E501 line too long (90 > 79 characters)
Line 22:54: E231 missing whitespace after ','
Line 22:77: E251 unexpected spaces around keyword / parameter equals
Line 22:79: E251 unexpected spaces around keyword / parameter equals
Line 22:80: E501 line too long (90 > 79 characters)
Line 23:25: E221 multiple spaces before operator
Line 24:1: W293 blank line contains whitespace
Line 29:29: E712 comparison to True should be 'if cond is True:' or 'if cond:'
Line 33:1: W293 blank line contains whitespace
Line 37:20: E228 missing whitespace around modulo operator
Line 39:1: W293 blank line contains whitespace
Line 43:1: W293 blank line contains whitespace
Line 46:10: E221 multiple spaces before operator
Line 49:14: E231 missing whitespace after ','
Line 52:17: E221 multiple spaces before operator
Line 55:1: W293 blank line contains whitespace
Line 56:13: E221 multiple spaces before operator
Line 58:30: E221 multiple spaces before operator
Line 60:80: E501 line too long (83 > 79 characters)
Line 61:1: E266 too many leading '#' for block comment
Line 67:1: W293 blank line contains whitespace
Line 70:10: E221 multiple spaces before operator
Line 71:80: E501 line too long (95 > 79 characters)
Line 72:1: W293 blank line contains whitespace
Line 76:73: E231 missing whitespace after ','
Line 78:1: W293 blank line contains whitespace
Line 80:29: E712 comparison to True should be 'if cond is True:' or 'if cond:'
Line 83:31: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
Line 86:1: E305 expected 2 blank lines after class or function definition, found 1
Line 86:12: E225 missing whitespace around operator
Line 89:5: E301 expected 1 blank line, found 0
Line 91:1: W293 blank line contains whitespace
Line 92:1: W293 blank line contains whitespace
Line 93:5: E303 too many blank lines (2)
Line 93:30: E231 missing whitespace after ','
Line 93:34: E231 missing whitespace after ','
Line 93:45: E231 missing whitespace after ','
Line 96:1: W293 blank line contains whitespace
Line 101:21: E231 missing whitespace after ','
Line 101:41: E231 missing whitespace after ','
Line 103:1: W391 blank line at end of file

Line 11:1: E265 block comment should start with '# '
Line 14:1: E265 block comment should start with '# '
Line 19:1: E402 module level import not at top of file
Line 287:1: E302 expected 2 blank lines, found 1
Line 297:19: E221 multiple spaces before operator
Line 298:15: E221 multiple spaces before operator
Line 299:15: E221 multiple spaces before operator
Line 300:20: E221 multiple spaces before operator
Line 301:19: E221 multiple spaces before operator
Line 302:20: E221 multiple spaces before operator
Line 303:15: E221 multiple spaces before operator
Line 304:19: E221 multiple spaces before operator
Line 305:15: E221 multiple spaces before operator
Line 306:33: E221 multiple spaces before operator
Line 307:25: E221 multiple spaces before operator
Line 308:26: E221 multiple spaces before operator
Line 309:28: E221 multiple spaces before operator
Line 310:34: E221 multiple spaces before operator
Line 310:80: E261 at least two spaces before inline comment
Line 310:80: E501 line too long (80 > 79 characters)
Line 311:24: E221 multiple spaces before operator
Line 312:23: E221 multiple spaces before operator
Line 313:74: E251 unexpected spaces around keyword / parameter equals
Line 313:76: E251 unexpected spaces around keyword / parameter equals
Line 313:80: E501 line too long (88 > 79 characters)
Line 314:66: E221 multiple spaces before operator
Line 314:66: E251 unexpected spaces around keyword / parameter equals
Line 314:76: E251 unexpected spaces around keyword / parameter equals
Line 314:80: E501 line too long (80 > 79 characters)
Line 315:63: E221 multiple spaces before operator
Line 315:63: E251 unexpected spaces around keyword / parameter equals
Line 315:76: E251 unexpected spaces around keyword / parameter equals
Line 315:80: E501 line too long (81 > 79 characters)
Line 316:66: E221 multiple spaces before operator
Line 316:66: E251 unexpected spaces around keyword / parameter equals
Line 316:76: E251 unexpected spaces around keyword / parameter equals
Line 316:80: E501 line too long (81 > 79 characters)
Line 317:1: W293 blank line contains whitespace
Line 318:33: E221 multiple spaces before operator
Line 319:37: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
Line 320:28: E221 multiple spaces before operator
Line 322:28: E221 multiple spaces before operator
Line 322:80: E501 line too long (110 > 79 characters)
Line 322:103: E251 unexpected spaces around keyword / parameter equals
Line 322:105: E251 unexpected spaces around keyword / parameter equals
Line 323:1: W293 blank line contains whitespace
Line 324:26: E231 missing whitespace after ','
Line 331:10: E221 multiple spaces before operator
Line 332:37: E231 missing whitespace after ','
Line 334:17: E225 missing whitespace around operator
Line 335:80: E501 line too long (104 > 79 characters)
Line 336:29: E221 multiple spaces before operator
Line 337:32: E221 multiple spaces before operator
Line 339:18: E231 missing whitespace after ','
Line 341:32: E231 missing whitespace after ','
Line 343:29: E221 multiple spaces before operator
Line 344:32: E221 multiple spaces before operator
Line 345:80: E501 line too long (101 > 79 characters)
Line 347:34: E221 multiple spaces before operator
Line 347:80: E501 line too long (80 > 79 characters)
Line 348:1: W293 blank line contains whitespace
Line 354:1: W293 blank line contains whitespace
Line 359:1: W293 blank line contains whitespace
Line 365:1: W293 blank line contains whitespace
Line 367:35: E701 multiple statements on one line (colon)
Line 368:1: W293 blank line contains whitespace
Line 369:11: E221 multiple spaces before operator
Line 369:20: E261 at least two spaces before inline comment
Line 369:20: E262 inline comment should start with '# '
Line 370:10: E221 multiple spaces before operator
Line 370:18: E261 at least two spaces before inline comment
Line 370:18: E262 inline comment should start with '# '
Line 374:1: W293 blank line contains whitespace
Line 379:1: W293 blank line contains whitespace
Line 383:1: W293 blank line contains whitespace
Line 393:37: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
Line 394:14: E221 multiple spaces before operator
Line 394:38: E231 missing whitespace after ':'
Line 396:24: E701 multiple statements on one line (colon)
Line 396:31: E225 missing whitespace around operator
Line 399:14: E221 multiple spaces before operator
Line 401:1: W293 blank line contains whitespace
Line 418:1: W293 blank line contains whitespace
Line 419:55: E251 unexpected spaces around keyword / parameter equals
Line 419:57: E251 unexpected spaces around keyword / parameter equals
Line 424:1: W293 blank line contains whitespace
Line 429:24: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
Line 429:32: E701 multiple statements on one line (colon)
Line 429:45: E221 multiple spaces before operator
Line 429:80: E501 line too long (81 > 79 characters)
Line 430:26: E712 comparison to True should be 'if cond is True:' or 'if cond:'
Line 430:33: E701 multiple statements on one line (colon)
Line 430:45: E221 multiple spaces before operator
Line 430:80: E501 line too long (81 > 79 characters)
Line 637:32: E231 missing whitespace after ','
Line 639:1: W293 blank line contains whitespace
Line 683:15: E221 multiple spaces before operator
Line 689:24: E221 multiple spaces before operator
Line 689:80: E501 line too long (98 > 79 characters)
Line 689:91: E251 unexpected spaces around keyword / parameter equals
Line 689:93: E251 unexpected spaces around keyword / parameter equals
Line 690:36: E231 missing whitespace after ','
Line 695:15: E221 multiple spaces before operator
Line 701:24: E221 multiple spaces before operator
Line 701:80: E501 line too long (98 > 79 characters)
Line 701:91: E251 unexpected spaces around keyword / parameter equals
Line 701:93: E251 unexpected spaces around keyword / parameter equals
Line 702:36: E231 missing whitespace after ','
Line 703:1: W293 blank line contains whitespace
Line 737:1: E302 expected 2 blank lines, found 1
Line 738:80: E501 line too long (95 > 79 characters)
Line 739:80: E501 line too long (101 > 79 characters)
Line 748:80: E501 line too long (85 > 79 characters)
Line 751:80: E501 line too long (82 > 79 characters)
Line 758:80: E501 line too long (84 > 79 characters)

Line 158:23: E701 multiple statements on one line (colon)
Line 166:19: E221 multiple spaces before operator
Line 166:38: E231 missing whitespace after ','
Line 331:21: E221 multiple spaces before operator
Line 341:36: E221 multiple spaces before operator
Line 354:31: E221 multiple spaces before operator
Line 355:1: W293 blank line contains whitespace
Line 356:33: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
Line 358:68: E251 unexpected spaces around keyword / parameter equals
Line 358:70: E251 unexpected spaces around keyword / parameter equals
Line 358:80: E501 line too long (87 > 79 characters)
Line 360:80: E501 line too long (97 > 79 characters)
Line 361:35: E228 missing whitespace around modulo operator
Line 363:68: E251 unexpected spaces around keyword / parameter equals
Line 363:70: E251 unexpected spaces around keyword / parameter equals
Line 363:80: E501 line too long (87 > 79 characters)
Line 365:80: E501 line too long (97 > 79 characters)
Line 367:80: E501 line too long (87 > 79 characters)

Line 30:56: E251 unexpected spaces around keyword / parameter equals
Line 30:58: E251 unexpected spaces around keyword / parameter equals
Line 31:19: E231 missing whitespace after ','
Line 31:36: E251 unexpected spaces around keyword / parameter equals
Line 31:38: E251 unexpected spaces around keyword / parameter equals
Line 31:46: E251 unexpected spaces around keyword / parameter equals
Line 31:48: E251 unexpected spaces around keyword / parameter equals
Line 33:26: E231 missing whitespace after ','

Line 9:10: E225 missing whitespace around operator
Line 9:15: E231 missing whitespace after ','
Line 9:19: E231 missing whitespace after ','
Line 9:23: E231 missing whitespace after ','
Line 9:27: E231 missing whitespace after ','
Line 13:28: E231 missing whitespace after ','
Line 14:33: E251 unexpected spaces around keyword / parameter equals
Line 14:35: E251 unexpected spaces around keyword / parameter equals
Line 20:1: E302 expected 2 blank lines, found 1
Line 20:22: E251 unexpected spaces around keyword / parameter equals
Line 20:24: E251 unexpected spaces around keyword / parameter equals
Line 40:9: E225 missing whitespace around operator
Line 40:37: E231 missing whitespace after ','
Line 40:47: E231 missing whitespace after ','
Line 40:58: E231 missing whitespace after ','
Line 40:69: E231 missing whitespace after ','
Line 40:80: E501 line too long (96 > 79 characters)
Line 40:82: E231 missing whitespace after ','

Line 7:1: E302 expected 2 blank lines, found 1
Line 11:10: E225 missing whitespace around operator
Line 11:15: E231 missing whitespace after ','
Line 11:19: E231 missing whitespace after ','
Line 11:23: E231 missing whitespace after ','
Line 11:27: E231 missing whitespace after ','
Line 12:11: E225 missing whitespace around operator
Line 12:15: E231 missing whitespace after ','
Line 12:27: E231 missing whitespace after ','
Line 12:30: E231 missing whitespace after ','
Line 12:42: E231 missing whitespace after ','
Line 12:45: E231 missing whitespace after ','
Line 12:57: E231 missing whitespace after ','
Line 12:60: E231 missing whitespace after ','
Line 12:72: E231 missing whitespace after ','
Line 12:75: E231 missing whitespace after ','
Line 12:80: E501 line too long (87 > 79 characters)
Line 15:28: E231 missing whitespace after ','
Line 16:33: E251 unexpected spaces around keyword / parameter equals
Line 16:35: E251 unexpected spaces around keyword / parameter equals
Line 18:19: E231 missing whitespace after ','
Line 19:30: E251 unexpected spaces around keyword / parameter equals
Line 19:32: E251 unexpected spaces around keyword / parameter equals
Line 19:41: E231 missing whitespace after ':'
Line 19:60: E231 missing whitespace after ':'
Line 19:80: E501 line too long (85 > 79 characters)
Line 22:1: E302 expected 2 blank lines, found 1
Line 22:22: E251 unexpected spaces around keyword / parameter equals
Line 22:24: E251 unexpected spaces around keyword / parameter equals
Line 28:1: E302 expected 2 blank lines, found 1
Line 33:18: E225 missing whitespace around operator
Line 33:46: E231 missing whitespace after ','
Line 33:56: E231 missing whitespace after ','
Line 33:67: E231 missing whitespace after ','
Line 33:78: E231 missing whitespace after ','
Line 33:80: E501 line too long (91 > 79 characters)
Line 38:1: E302 expected 2 blank lines, found 1
Line 41:1: E305 expected 2 blank lines after class or function definition, found 1
Line 41:12: E225 missing whitespace around operator
Line 42:9: E117 over-indented
Line 42:13: E225 missing whitespace around operator
Line 42:41: E231 missing whitespace after ','
Line 42:51: E231 missing whitespace after ','
Line 42:62: E231 missing whitespace after ','
Line 42:73: E231 missing whitespace after ','
Line 42:80: E501 line too long (116 > 79 characters)
Line 42:86: E231 missing whitespace after ','
Line 44:1: W391 blank line at end of file

Line 18:80: E501 line too long (98 > 79 characters)
Line 34:19: E225 missing whitespace around operator
Line 34:37: E251 unexpected spaces around keyword / parameter equals
Line 34:39: E251 unexpected spaces around keyword / parameter equals
Line 35:18: E225 missing whitespace around operator
Line 35:80: E501 line too long (125 > 79 characters)
Line 35:121: E251 unexpected spaces around keyword / parameter equals
Line 35:123: E251 unexpected spaces around keyword / parameter equals

Line 13:19: E225 missing whitespace around operator
Line 13:80: E501 line too long (95 > 79 characters)
Line 19:1: E115 expected an indented block (comment)
Line 33:18: E225 missing whitespace around operator
Line 33:48: E231 missing whitespace after ','
Line 33:58: E231 missing whitespace after ','
Line 33:69: E231 missing whitespace after ','
Line 33:80: E501 line too long (80 > 79 characters)
Line 34:44: E231 missing whitespace after ','
Line 34:57: E231 missing whitespace after ','

Comment last updated at 2020-02-27 21:03:06 UTC

@wdpozzo wdpozzo requested a review from johnveitch October 18, 2019 05:51
Copy link
Owner

@johnveitch johnveitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a lot of changes to digest here but there's some stuff missing that you'll need to add to the repo before I can test more.

cpnest/NestedSampling.py Outdated Show resolved Hide resolved
cpnest/cpnest.py Outdated Show resolved Hide resolved
cpnest/proposal.py Outdated Show resolved Hide resolved
cpnest/proposal.py Outdated Show resolved Hide resolved
directional derivatives of the likelihood
at x.

It uses jax.grad for automatic differentiation, but reverts to
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should jax be added to the requirements in setup.py then?

examples/eggbox.py Outdated Show resolved Hide resolved
@wdpozzo
Copy link
Collaborator Author

wdpozzo commented Nov 4, 2019

I pushed the changes you requested

try:
from jax import grad, jit
FINITEDIFFERENCING = False
except:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use a bare except. Use except ImportError if that is what you want to catch

self.analytic_log_Z=0.0 - sum([np.log(self.bounds[i][1]-self.bounds[i][0]) for i in range(self.dim)])

def log_likelihood(self,p):
return np.sum([-0.5*p[n]**2-0.5*np.log(2.0*np.pi) for n in p.names])##np.sum([self.distr.logpdf(p[n]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the way of getting the parameter? Isn't this going to be slower?

@johnveitch
Copy link
Owner

Hi @wdpozzo am seeing this on the branch but I can't work out why.

john@virgo:~/src/cpnest$ python3 setup.py test
running test
WARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox.
running egg_info
writing cpnest.egg-info/PKG-INFO
writing dependency_links to cpnest.egg-info/dependency_links.txt
writing requirements to cpnest.egg-info/requires.txt
writing top-level names to cpnest.egg-info/top_level.txt
reading manifest file 'cpnest.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'cpnest.egg-info/SOURCES.txt'
running build_ext
skipping 'cpnest/parameter.c' Cython extension (up-to-date)
copying build/lib.linux-x86_64-3.6/cpnest/parameter.cpython-36m-x86_64-linux-gnu.so -> cpnest
Checkpoint exception raise
test_run (tests.test_gaussian.GaussianTestCase) ... 2019-12-20, 10:42:34 - CPNest  : Running with 8 parallel threads
Process Process-8:
Traceback (most recent call last):
  File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/john/src/cpnest/cpnest/sampler.py", line 157, in produce_sample
    self._produce_sample()
  File "/home/john/src/cpnest/cpnest/sampler.py", line 191, in _produce_sample
    (Nmcmc, outParam) = next(self.yield_sample(self.logLmin.value))
  File "/home/john/src/cpnest/cpnest/sampler.py", line 288, in yield_sample
    self.estimate_nmcmc()
  File "/home/john/src/cpnest/cpnest/sampler.py", line 148, in estimate_nmcmc
    self.Nmcmc_exact = (1.0 - 1.0/tau)*self.Nmcmc_exact + (safety/tau)*(2.0/self.sub_acceptance - 1.0)
ZeroDivisionError: float division by zero

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

Successfully merging this pull request may close these issues.

3 participants