Skip to content

Commit

Permalink
fix some string syntax issues in docs, and apply isort
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed May 27, 2024
1 parent 7b01abe commit dacc8dc
Show file tree
Hide file tree
Showing 20 changed files with 641 additions and 178 deletions.
348 changes: 293 additions & 55 deletions docs/example-line.ipynb

Large diffs are not rendered by default.

306 changes: 250 additions & 56 deletions docs/example-warmstart.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ultranest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .integrator import NestedSampler, ReactiveNestedSampler, read_file
from .utils import vectorize


__author__ = """Johannes Buchner"""
__email__ = '[email protected]'
__version__ = '4.3.1'
4 changes: 3 additions & 1 deletion ultranest/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
---------------------------
"""

import os

import numpy as np

from ultranest.integrator import ReactiveNestedSampler
import os


def _substitute_log_dir(init_args, nsteps):
Expand Down
6 changes: 4 additions & 2 deletions ultranest/dychmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
Uses gradient to reflect at nested sampling boundaries.
"""

from __future__ import print_function, division
import numpy as np
from __future__ import division, print_function

import matplotlib.pyplot as plt
import numpy as np


def stop_criterion(thetaminus, thetaplus, rminus, rplus):
"""Compute the stop condition in the main loop
Expand Down
2 changes: 1 addition & 1 deletion ultranest/dyhmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
A helper surface is created using the live points.
"""

import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import scipy.special
import scipy.stats

Expand Down
3 changes: 2 additions & 1 deletion ultranest/flatnuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
"""


import matplotlib.pyplot as plt
import numpy as np
from numpy.linalg import norm
import matplotlib.pyplot as plt

from .samplingpath import angle, extrapolate_ahead


Expand Down
3 changes: 2 additions & 1 deletion ultranest/hotstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

import numpy as np
import scipy.stats
from .utils import vectorize, resample_equal

from .utils import resample_equal, vectorize


def get_auxiliary_problem(loglike, transform, ctr, invcov, enlargement_factor, df=1):
Expand Down
44 changes: 27 additions & 17 deletions ultranest/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,36 @@
# Some parts are from the Nestle library by Kyle Barbary (https://github.com/kbarbary/nestle)
# Some parts are from the nnest library by Adam Moss (https://github.com/adammoss/nnest)

from __future__ import print_function, division
from __future__ import division, print_function

import os
import sys
import csv
import json
import operator
import os
import sys
import time
import warnings

from numpy import log, exp, logaddexp
import numpy as np
from numpy import exp, log, logaddexp

from .utils import create_logger, make_run_dir, resample_equal, vol_prefactor, vectorize, listify as _listify
from .utils import is_affine_transform, normalised_kendall_tau_distance, distributed_work_chunk_size
from ultranest.mlfriends import MLFriends, AffineLayer, LocalAffineLayer, ScalingLayer, find_nearby, WrappingEllipsoid, RobustEllipsoidRegion
from .store import HDF5PointStore, TextPointStore, NullPointStore
from .viz import get_default_viz_callback
from .ordertest import UniformOrderAccumulator
from .netiter import PointPile, SingleCounter, MultiCounter, BreadthFirstIterator, TreeNode, count_tree_between, find_nodes_before, logz_sequence
from .netiter import dump_tree, combine_results
from .hotstart import get_auxiliary_contbox_parameterization
from ultranest.mlfriends import (AffineLayer, LocalAffineLayer, MLFriends,
RobustEllipsoidRegion, ScalingLayer,
WrappingEllipsoid, find_nearby)

from .hotstart import get_auxiliary_contbox_parameterization
from .netiter import (BreadthFirstIterator, MultiCounter, PointPile,
SingleCounter, TreeNode, combine_results,
count_tree_between, dump_tree, find_nodes_before,
logz_sequence)
from .ordertest import UniformOrderAccumulator
from .store import HDF5PointStore, NullPointStore, TextPointStore
from .utils import (create_logger, distributed_work_chunk_size,
is_affine_transform)
from .utils import listify as _listify
from .utils import (make_run_dir, normalised_kendall_tau_distance,
resample_equal, vectorize, vol_prefactor)
from .viz import get_default_viz_callback

__all__ = ['ReactiveNestedSampler', 'NestedSampler', 'read_file', 'warmstart_from_similar_file']

Expand Down Expand Up @@ -914,8 +921,8 @@ def print_results(self):
def plot(self):
"""Make corner plot."""
if self.log_to_disk:
import matplotlib.pyplot as plt
import corner
import matplotlib.pyplot as plt
data = np.array(self.results['weighted_samples']['points'])
weights = np.array(self.results['weighted_samples']['weights'])
cumsumweights = np.cumsum(weights)
Expand Down Expand Up @@ -2989,8 +2996,9 @@ def plot_corner(self):
cornerplot(results)
"""
from .plot import cornerplot
import matplotlib.pyplot as plt

from .plot import cornerplot
if self.log:
self.logger.debug('Making corner plot ...')
cornerplot(self.results, logger=self.logger if self.log else None)
Expand All @@ -3011,8 +3019,9 @@ def plot_trace(self):
traceplot(results=results, labels=paramnames + derivedparamnames)
"""
from .plot import traceplot
import matplotlib.pyplot as plt

from .plot import traceplot
if self.log:
self.logger.debug('Making trace plot ... ')
paramnames = self.paramnames + self.derivedparamnames
Expand All @@ -3035,8 +3044,9 @@ def plot_run(self):
runplot(results=results)
"""
from .plot import runplot
import matplotlib.pyplot as plt

from .plot import runplot
if self.log:
self.logger.debug('Making run plot ... ')
# get dynesty-compatible sequences
Expand Down
8 changes: 5 additions & 3 deletions ultranest/netiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
can ignore the rootids it does not know about.
"""

import numpy as np
from numpy import log, log1p, exp, logaddexp
import math
import sys
from .utils import resample_equal

import numpy as np
from numpy import exp, log, log1p, logaddexp

from .ordertest import UniformOrderAccumulator
from .utils import resample_equal


class TreeNode(object):
Expand Down
2 changes: 1 addition & 1 deletion ultranest/ordertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

from __future__ import print_function, division
from __future__ import division, print_function

__all__ = ['infinite_U_zscore', 'UniformOrderAccumulator']

Expand Down
17 changes: 9 additions & 8 deletions ultranest/pathsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
These features are experimental.
"""

import numpy as np

import matplotlib.pyplot as plt
import numpy as np

from ultranest.samplingpath import SamplingPath, ContourSamplingPath, extrapolate_ahead
from ultranest.stepsampler import StepSampler
from ultranest.stepsampler import generate_region_oriented_direction, generate_region_random_direction, generate_random_direction

from ultranest.flatnuts import ClockedStepSampler, ClockedBisectSampler, ClockedNUTSSampler
from ultranest.flatnuts import SingleJumper, DirectJumper, IntervalJumper
from ultranest.flatnuts import (ClockedBisectSampler, ClockedNUTSSampler,
ClockedStepSampler, DirectJumper,
IntervalJumper, SingleJumper)
from ultranest.samplingpath import (ContourSamplingPath, SamplingPath,
extrapolate_ahead)
from ultranest.stepsampler import (StepSampler, generate_random_direction,
generate_region_oriented_direction,
generate_region_random_direction)


class SamplingPathSliceSampler(StepSampler):
Expand Down
20 changes: 10 additions & 10 deletions ultranest/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
"""

from __future__ import (print_function, division)
from six.moves import range
from __future__ import division, print_function

import logging
import types
import warnings

import numpy as np
import matplotlib.pyplot as pl
from matplotlib.ticker import MaxNLocator, NullLocator
# from matplotlib.colors import LinearSegmentedColormap, colorConverter
from matplotlib.ticker import ScalarFormatter

import scipy.stats
import matplotlib.pyplot as plt
import numpy
import numpy as np
import scipy.stats
# from matplotlib.colors import LinearSegmentedColormap, colorConverter
from matplotlib.ticker import MaxNLocator, NullLocator, ScalarFormatter
from six.moves import range

from .utils import resample_equal
from .utils import quantile as _quantile
from .utils import resample_equal

try:
str_type = types.StringTypes
Expand Down Expand Up @@ -183,8 +181,8 @@ def highest_density_interval_from_samples(xsamples, xlo=None, xhi=None, probabil
>>> print('x = %.1f + %.2f - %.2f' % hdi)
x = 0.0 + 1.02 - 0.96
"""
from getdist.mcsamples import MCSamples
import getdist.chains
from getdist.mcsamples import MCSamples
getdist.chains.print_load_details = False
samples = MCSamples(
samples=xsamples, names=['x'], ranges={'x':[xlo,xhi]},
Expand Down Expand Up @@ -431,6 +429,7 @@ def runplot(results, span=None, logplot=False, kde=True, nkde=1000,
try:
# from scipy.ndimage import gaussian_filter as norm_kde
from scipy.stats import gaussian_kde

# Derive kernel density estimate.
wt_kde = gaussian_kde(resample_equal(-logvol, weights)) # KDE
logvol_new = np.linspace(logvol[0], logvol[-1], nkde) # resample
Expand Down Expand Up @@ -723,6 +722,7 @@ def traceplot(results, span=None, quantiles=[0.025, 0.5, 0.975], smooth=0.02,
try:
from scipy.ndimage import gaussian_filter as norm_kde
from scipy.stats import gaussian_kde

# Derive kernel density estimate.
wt_kde = gaussian_kde(resample_equal(-logvol, weights)) # KDE
logvol_grid = np.linspace(logvol[0], logvol[-1], nkde) # resample
Expand Down
15 changes: 10 additions & 5 deletions ultranest/popstepsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
"""

import numpy as np
from ultranest.utils import submasks
from ultranest.stepfuncs import evolve, step_back, update_vectorised_slice_sampler
from ultranest.stepfuncs import generate_cube_oriented_direction, generate_cube_oriented_direction_scaled
from ultranest.stepfuncs import generate_random_direction, generate_region_oriented_direction, generate_region_random_direction
from ultranest.stepfuncs import generate_differential_direction, generate_mixture_random_direction
import scipy.stats

from ultranest.stepfuncs import (evolve, generate_cube_oriented_direction,
generate_cube_oriented_direction_scaled,
generate_differential_direction,
generate_mixture_random_direction,
generate_random_direction,
generate_region_oriented_direction,
generate_region_random_direction, step_back,
update_vectorised_slice_sampler)
from ultranest.utils import submasks

int_t = int


Expand Down
2 changes: 1 addition & 1 deletion ultranest/samplingpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"""


import matplotlib.pyplot as plt
import numpy as np
from numpy.linalg import norm
import matplotlib.pyplot as plt


def nearest_box_intersection_line(ray_origin, ray_direction, fwd=True):
Expand Down
3 changes: 2 additions & 1 deletion ultranest/solvecompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"""


import numpy as np
import string

import numpy as np

from .integrator import ReactiveNestedSampler
from .stepsampler import SliceSampler, generate_mixture_random_direction

Expand Down
9 changes: 6 additions & 3 deletions ultranest/stepsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
even if they do not terminate at the same number of iterations.
"""

from __future__ import print_function, division
import numpy as np
from __future__ import division, print_function

from warnings import warn

import matplotlib.pyplot as plt
import numpy as np

from .utils import listify as _listify
from warnings import warn


def generate_random_direction(ui, region, scale=1):
Expand Down
8 changes: 5 additions & 3 deletions ultranest/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"""

from __future__ import print_function, division
import numpy as np
import warnings
from __future__ import division, print_function

import os
import warnings

import numpy as np


class NullPointStore(object):
Expand Down
8 changes: 5 additions & 3 deletions ultranest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
--------------------------------------------
"""

from __future__ import print_function, division
from __future__ import division, print_function

import errno
import logging
import sys
import os
import sys

import numpy as np
from numpy import pi
import errno


def create_logger(module_name, log_dir=None, level=logging.INFO):
Expand Down
Loading

0 comments on commit dacc8dc

Please sign in to comment.