From ae1b102e4093310c01214aa3bf0e64267e50e2ad Mon Sep 17 00:00:00 2001 From: Mark Forrer Date: Wed, 12 Oct 2022 15:58:33 -0700 Subject: [PATCH 1/5] Update pre-commit hook versions Ran `pre-commit autoupdate`, then manually upgraded `flake6` to the latest, since it was out-of-date and causing build errors on Python 3.7. --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0bc6c8..7487bff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,16 @@ repos: - repo: https://github.com/ambv/black - rev: 19.10b0 + rev: 22.10.0 hooks: - id: black args: ["--config=pyproject.toml", "--check"] - repo: https://gitlab.com/pycqa/flake8 - rev: "3.7.7" + rev: 5.0.4 hooks: - id: flake8 args: ["--config=.flake8"] - repo: https://github.com/timothycrosley/isort - rev: 5.6.1 + rev: 5.10.1 hooks: - id: isort From ca933dc92fbcbb8a41a9964cf868f1a0e1cd9d0d Mon Sep 17 00:00:00 2001 From: Mark Forrer Date: Wed, 12 Oct 2022 17:28:17 -0700 Subject: [PATCH 2/5] Use pre-commit consistently Use `pre-commit` to consistently enforce the same code quality standards @ commit and build time. This should help prevent CI build errors by causing them to use the same `black` version and options as `pre-commit` does. Developers can use, e.g. (on MacOS) ``` brew install pre-commit pre-commit install ``` from the project base to enable pre-commit to run prior to each commit, and can then run `pre-commit` directly to format code. 1. Remove the black `--check` option Files will be auto-reformatted at commit time, which should help prevent failed builds and force developers to fix errors earlier. 2. Use `make format` as a test during builds Should still fail when pre-commit hooks weren't run prior to the build 3. Remove `make lint` Since `pre-commit` purposefully doesn't support overriding options, this is no longer possible --- .pre-commit-config.yaml | 2 +- Makefile | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7487bff..73b340f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: 22.10.0 hooks: - id: black - args: ["--config=pyproject.toml", "--check"] + args: ["--config=pyproject.toml"] - repo: https://gitlab.com/pycqa/flake8 rev: 5.0.4 hooks: diff --git a/Makefile b/Makefile index 657a5d9..54a6ebd 100644 --- a/Makefile +++ b/Makefile @@ -35,11 +35,7 @@ init: @./venv/bin/python3 -m pip install -e . format: - black . - -lint: - black --check . - flake8 . + pre-commit run --all-files clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts @@ -61,7 +57,7 @@ clean-test: ## remove test and coverage artifacts rm -f .coverage rm -fr htmlcov/ -test: lint ## run tests quickly with the default Python +test: format ## run tests quickly with the default Python pytest -v --durations=10 --full-trace --cov-report html --cov-config .coveragerc --cov=PTMCMCSampler tests coverage: test ## check code coverage quickly with the default Python @@ -74,7 +70,7 @@ dist: clean ## builds source and wheel package ls -l dist test-sdist: ## Test source distribution - mkdir tmp + mkdir tmp cd tmp python -m venv venv-sdist venv-sdist/bin/python -m pip install --upgrade pip setuptools wheel @@ -83,7 +79,7 @@ test-sdist: ## Test source distribution rm -rf tmp venv-sdist test-wheel: ## Test wheel - mkdir tmp2 + mkdir tmp2 cd tmp2 python -m venv venv-wheel venv-wheel/bin/python -m pip install --upgrade pip setuptools From 4f28b99a8af1b83fc5d3fed4b03996a76fc2f3d4 Mon Sep 17 00:00:00 2001 From: Mark Forrer Date: Wed, 12 Oct 2022 17:37:42 -0700 Subject: [PATCH 3/5] Update pre-commit version --- requirements_dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 44ea332..ea83c57 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,8 +1,8 @@ pip>=20.3.4 black~=19.10b0 flake8~=3.7.7 -pre-commit~=1.15.2 +pre-commit~=2.17.0 wheel>=0.29.0 pytest>=4.0.0 pytest-cov>=2.7.0 -jupyter>=1.0.0 \ No newline at end of file +jupyter>=1.0.0 From c96f3c7fbf835f12b9863fa083ac3b9910415625 Mon Sep 17 00:00:00 2001 From: Mark Forrer Date: Thu, 13 Oct 2022 09:20:47 -0700 Subject: [PATCH 4/5] Update CI config 1. Remove Python 3.6, which is past end-of-life 2. Add Python 3.10, which is the latest 3. Remove pinned `black` and `flake8` versions from `requirements_dev.txt` For consistency these should be run via `pre-commit` --- .github/workflows/ci_test.yml | 12 ++++++------ pyproject.toml | 6 +++--- requirements_dev.txt | 2 -- setup.py | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 388121e..b741102 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -5,7 +5,7 @@ on: branches: [ master ] pull_request: branches: [ master ] - release: + release: types: - published @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.7, 3.8, 3.9, '3.10'] steps: - name: Checkout repository @@ -57,10 +57,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python + - name: Set up Python uses: actions/setup-python@v2 with: - python-version: "3.7" + python-version: "3.10" - name: Install non-python dependencies on linux run: | sudo apt install libopenmpi-dev @@ -88,7 +88,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.7' + python-version: '3.10' - name: Install dependencies run: | python -m pip install --upgrade pip @@ -103,4 +103,4 @@ jobs: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - twine upload dist/* \ No newline at end of file + twine upload dist/* diff --git a/pyproject.toml b/pyproject.toml index f8334a0..ccf49ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ multi_line_output = 3 [tool.black] line-length = 120 -target_version = ['py36'] +target_version = ['py37', 'py38', 'py39', 'py310'] include = '\.pyi?$' exclude = ''' @@ -23,7 +23,7 @@ exclude = ''' | dist | docs | venv - | examples + | examples )/ ) ''' @@ -32,4 +32,4 @@ requires = [ "setuptools>=40.8.0", "wheel", ] -build-backend = "setuptools.build_meta" \ No newline at end of file +build-backend = "setuptools.build_meta" diff --git a/requirements_dev.txt b/requirements_dev.txt index ea83c57..8da9e35 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,6 +1,4 @@ pip>=20.3.4 -black~=19.10b0 -flake8~=3.7.7 pre-commit~=2.17.0 wheel>=0.29.0 pytest>=4.0.0 diff --git a/setup.py b/setup.py index ee5d0d5..446f508 100755 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ long_description_content_type="text/markdown", package_data={"": ["README.md", "HISTORY.md"]}, install_requires=["numpy>=1.16.3", "scipy>=1.2.0"], - python_requires=">=3.6", + python_requires=">=3.7", extras_require={"mpi": ["mpi4py>=3.0.3"]}, classifiers=[ "Development Status :: 5 - Production/Stable", @@ -24,9 +24,9 @@ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", ], ) From 2c2b4f38ee52205d9615b586610640dac81052b1 Mon Sep 17 00:00:00 2001 From: Mark Forrer Date: Wed, 12 Oct 2022 16:08:04 -0700 Subject: [PATCH 5/5] Run updated pre-commit hooks on existing code Updates in this commit are auto-generated only using `pre-commit`, except for manually adding a few spaces as required by `flake8`. ``` $ pre-commit run --all-files ``` Then fixed: ``` docs/conf.py:189:5: E265 block comment should start with '# ' docs/conf.py:191:5: E265 block comment should start with '# ' docs/conf.py:193:5: E265 block comment should start with '# ' ``` --- PTMCMCSampler/PTMCMCSampler.py | 2 +- PTMCMCSampler/nutsjump.py | 12 +-- docs/conf.py | 192 ++++++++++++++++----------------- examples/simple.py | 4 +- tests/test_nuts.py | 4 +- tests/test_simple.py | 4 +- 6 files changed, 109 insertions(+), 109 deletions(-) diff --git a/PTMCMCSampler/PTMCMCSampler.py b/PTMCMCSampler/PTMCMCSampler.py index d94cbf9..ef8a705 100755 --- a/PTMCMCSampler/PTMCMCSampler.py +++ b/PTMCMCSampler/PTMCMCSampler.py @@ -705,7 +705,7 @@ def temperatureLadder(self, Tmin, Tmax=None, tstep=None): tstep = np.exp(np.log(Tmax / Tmin) / (self.nchain - 1)) ladder = np.zeros(self.nchain) for ii in range(self.nchain): - ladder[ii] = Tmin * tstep ** ii + ladder[ii] = Tmin * tstep**ii else: ladder = np.array([1]) diff --git a/PTMCMCSampler/nutsjump.py b/PTMCMCSampler/nutsjump.py index 09d195b..a7408e5 100644 --- a/PTMCMCSampler/nutsjump.py +++ b/PTMCMCSampler/nutsjump.py @@ -225,10 +225,10 @@ def __call__(self, x, iter, beta): dist = np.random.randn() # Do the leapfrog - mq0 = q0 + 0.5 * vec * self.cd ** 2 * np.dot(vec, grad0) / 2 / val + mq0 = q0 + 0.5 * vec * self.cd**2 * np.dot(vec, grad0) / 2 / val q1 = mq0 + dist * vec * self.cd / np.sqrt(val) logp1, grad1 = self.func_grad_white(q1) - mq1 = q1 + 0.5 * vec * self.cd ** 2 * np.dot(vec, grad1) / 2 / val + mq1 = q1 + 0.5 * vec * self.cd**2 * np.dot(vec, grad1) / 2 / val qxy = 0.5 * (np.sum((mq0 - q1) ** 2 / val) - np.sum((mq1 - q0) ** 2 / val)) @@ -454,8 +454,8 @@ def find_reasonable_epsilon(self, theta0, grad0, logp0): a = 2.0 * float((acceptprob > 0.5)) - 1.0 # Keep moving epsilon in that direction until acceptprob crosses 0.5. - while (acceptprob ** a) > (2.0 ** (-a)): - epsilon = epsilon * (2.0 ** a) + while (acceptprob**a) > (2.0 ** (-a)): + epsilon = epsilon * (2.0**a) _, rprime, _, logpprime = self.leapfrog(theta0, r0, grad0, epsilon) acceptprob = np.exp(self.loghamiltonian(logpprime, rprime) - self.loghamiltonian(logp0, r0)) @@ -463,7 +463,7 @@ def find_reasonable_epsilon(self, theta0, grad0, logp0): return epsilon def stop_criterion(self, thetaminus, thetaplus, rminus, rplus, force_trajlen, index): - """ Compute the stop condition in the main loop + """Compute the stop condition in the main loop dot(dtheta, rminus) >= 0 & dot(dtheta, rplus >= 0) INPUTS @@ -809,7 +809,7 @@ def __call__(self, x, iter, beta): if iter <= self.nburn: # Still in the burn-in phase. So adjust epsilon self.epsilon = np.exp(self.mu - np.sqrt(self.iter) / self.gamma * self.Hbar) - eta = self.iter ** -self.kappa + eta = self.iter**-self.kappa self.epsilonbar = np.exp((1.0 - eta) * np.log(self.epsilonbar) + eta * np.log(self.epsilon)) else: diff --git a/docs/conf.py b/docs/conf.py index 4f13bca..95b3639 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,229 +12,223 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('../PTMCMCSampler')) +sys.path.insert(0, os.path.abspath("../PTMCMCSampler")) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.viewcode", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'PTMCMCSampler' -copyright = u'2015, Justin A. Ellis' +project = "PTMCMCSampler" +copyright = "2015, Justin A. Ellis" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '' +version = "" # The full version, including alpha/beta/rc tags. -release = '' +release = "" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'PTMCMCSamplerdoc' +htmlhelp_basename = "PTMCMCSamplerdoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'PTMCMCSampler.tex', u'PTMCMCSampler Documentation', - u'Justin A. Ellis', 'manual'), + ("index", "PTMCMCSampler.tex", "PTMCMCSampler Documentation", "Justin A. Ellis", "manual"), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'ptmcmcsampler', u'PTMCMCSampler Documentation', - [u'Justin A. Ellis'], 1) -] +man_pages = [("index", "ptmcmcsampler", "PTMCMCSampler Documentation", ["Justin A. Ellis"], 1)] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -243,89 +237,95 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'PTMCMCSampler', u'PTMCMCSampler Documentation', - u'Justin A. Ellis', 'PTMCMCSampler', 'One line description of project.', - 'Miscellaneous'), + ( + "index", + "PTMCMCSampler", + "PTMCMCSampler Documentation", + "Justin A. Ellis", + "PTMCMCSampler", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # -- Options for Epub output ---------------------------------------------- # Bibliographic Dublin Core info. -epub_title = u'PTMCMCSampler' -epub_author = u'Justin A. Ellis' -epub_publisher = u'Justin A. Ellis' -epub_copyright = u'2015, Justin A. Ellis' +epub_title = "PTMCMCSampler" +epub_author = "Justin A. Ellis" +epub_publisher = "Justin A. Ellis" +epub_copyright = "2015, Justin A. Ellis" # The basename for the epub file. It defaults to the project name. -#epub_basename = u'PTMCMCSampler' +# epub_basename = u'PTMCMCSampler' # The HTML theme for the epub output. Since the default themes are not optimized # for small screen space, using the same theme for HTML and epub output is # usually not wise. This defaults to 'epub', a theme designed to save visual # space. -#epub_theme = 'epub' +# epub_theme = 'epub' # The language of the text. It defaults to the language option # or en if the language is not set. -#epub_language = '' +# epub_language = '' # The scheme of the identifier. Typical schemes are ISBN or URL. -#epub_scheme = '' +# epub_scheme = '' # The unique identifier of the text. This can be a ISBN number # or the project homepage. -#epub_identifier = '' +# epub_identifier = '' # A unique identification for the text. -#epub_uid = '' +# epub_uid = '' # A tuple containing the cover image and cover page html template filenames. -#epub_cover = () +# epub_cover = () # A sequence of (type, uri, title) tuples for the guide element of content.opf. -#epub_guide = () +# epub_guide = () # HTML files that should be inserted before the pages created by sphinx. # The format is a list of tuples containing the path and title. -#epub_pre_files = [] +# epub_pre_files = [] # HTML files shat should be inserted after the pages created by sphinx. # The format is a list of tuples containing the path and title. -#epub_post_files = [] +# epub_post_files = [] # A list of files that should not be packed into the epub file. -epub_exclude_files = ['search.html'] +epub_exclude_files = ["search.html"] # The depth of the table of contents in toc.ncx. -#epub_tocdepth = 3 +# epub_tocdepth = 3 # Allow duplicate toc entries. -#epub_tocdup = True +# epub_tocdup = True # Choose between 'default' and 'includehidden'. -#epub_tocscope = 'default' +# epub_tocscope = 'default' # Fix unsupported image types using the PIL. -#epub_fix_images = False +# epub_fix_images = False # Scale large images. -#epub_max_image_width = 0 +# epub_max_image_width = 0 # How to display URL addresses: 'footnote', 'no', or 'inline'. -#epub_show_urls = 'inline' +# epub_show_urls = 'inline' # If false, no index is generated. -#epub_use_index = True +# epub_use_index = True diff --git a/examples/simple.py b/examples/simple.py index 7a1c7eb..90e9ba7 100644 --- a/examples/simple.py +++ b/examples/simple.py @@ -24,7 +24,7 @@ def __init__(self, ndim=2, pmin=-10, pmax=10): self.mu = np.random.uniform(pmin, pmax, ndim) # ... and a positive definite, non-trivial covariance matrix. - cov = 0.5 - np.random.rand(ndim ** 2).reshape((ndim, ndim)) + cov = 0.5 - np.random.rand(ndim**2).reshape((ndim, ndim)) cov = np.triu(cov) cov += cov.T - np.diag(cov.diagonal()) self.cov = np.dot(cov, cov) @@ -63,7 +63,7 @@ def lnpriorfn(self, x): # Set the start position and the covariance p0 = np.random.uniform(pmin, pmax, ndim) -cov = np.eye(ndim) * 0.1 ** 2 +cov = np.eye(ndim) * 0.1**2 # In[5]: diff --git a/tests/test_nuts.py b/tests/test_nuts.py index 2aee882..1586948 100644 --- a/tests/test_nuts.py +++ b/tests/test_nuts.py @@ -15,10 +15,10 @@ def __init__(self, ndim=2, pmin=-10, pmax=10): self.b = np.ones(ndim) * pmax def lnlikefn(self, x): - return -0.5 * np.sum(x ** 2) - len(x) * 0.5 * np.log(2 * np.pi) + return -0.5 * np.sum(x**2) - len(x) * 0.5 * np.log(2 * np.pi) def lnlikefn_grad(self, x): - ll = -0.5 * np.sum(x ** 2) - len(x) * 0.5 * np.log(2 * np.pi) + ll = -0.5 * np.sum(x**2) - len(x) * 0.5 * np.log(2 * np.pi) ll_grad = -x return ll, ll_grad diff --git a/tests/test_simple.py b/tests/test_simple.py index 9373136..e5719a4 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -19,7 +19,7 @@ def __init__(self, ndim=2, pmin=-10, pmax=10): self.mu = np.random.uniform(pmin, pmax, ndim) # ... and a positive definite, non-trivial covariance matrix. - cov = 0.5 - np.random.rand(ndim ** 2).reshape((ndim, ndim)) + cov = 0.5 - np.random.rand(ndim**2).reshape((ndim, ndim)) cov = np.triu(cov) cov += cov.T - np.diag(cov.diagonal()) self.cov = np.dot(cov, cov) @@ -74,7 +74,7 @@ def test_simple(self): # ## Setup sampler # Set the start position and the covariance p0 = np.random.uniform(pmin, pmax, ndim) - cov = np.eye(ndim) * 0.1 ** 2 + cov = np.eye(ndim) * 0.1**2 sampler = PTMCMCSampler.PTSampler(ndim, glo.lnlikefn, glo.lnpriorfn, np.copy(cov), outDir="./chains")