Skip to content

Commit

Permalink
Applied Formatting using Black Command on 13 files
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash1256 committed Sep 28, 2020
1 parent df61dd3 commit 3410f4d
Show file tree
Hide file tree
Showing 14 changed files with 661 additions and 572 deletions.
335 changes: 232 additions & 103 deletions benchmarks/benchmarks/benchmarks.py

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
("Books + Videos", "learn"),
("API", "api"),
("Developer Guide", "developer_guide"),
("About PyMC3", "about")
("About PyMC3", "about"),
],
# "fixed_sidebar": "false",
# "description": "Probabilistic Programming in Python: Bayesian Modeling and Probabilistic Machine Learning with Theano"
Expand Down Expand Up @@ -264,9 +264,7 @@
# 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 = [
(master_doc, "pymc3.tex", "PyMC3 Documentation", "PyMC developers", "manual")
]
latex_documents = [(master_doc, "pymc3.tex", "PyMC3 Documentation", "PyMC developers", "manual")]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
Expand Down Expand Up @@ -330,7 +328,5 @@


def setup(app):
app.add_css_file(
"https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css"
)
app.add_css_file("https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css")
app.add_css_file("default.css")
33 changes: 12 additions & 21 deletions docs/source/sphinxext/gallery_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
from matplotlib import image

DOC_SRC = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEFAULT_IMG_LOC = os.path.join(
os.path.dirname(DOC_SRC), "logos", "PyMC3.png"
)
DEFAULT_IMG_LOC = os.path.join(os.path.dirname(DOC_SRC), "logos", "PyMC3.png")
TABLE_OF_CONTENTS_FILENAME = "table_of_contents_{}.js"

INDEX_TEMPLATE = """
Expand Down Expand Up @@ -69,13 +67,9 @@ class NotebookGenerator:
def __init__(self, filename, target_dir):
self.basename = os.path.basename(filename)
self.stripped_name = os.path.splitext(self.basename)[0]
self.output_html = os.path.join(
"..", "notebooks", f"{self.stripped_name}.html"
)
self.output_html = os.path.join("..", "notebooks", f"{self.stripped_name}.html")
self.image_dir = os.path.join(target_dir, "_images")
self.png_path = os.path.join(
self.image_dir, f"{self.stripped_name}.png"
)
self.png_path = os.path.join(self.image_dir, f"{self.stripped_name}.png")
with open(filename) as fid:
self.json_source = json.load(fid)
self.pagetitle = self.extract_title()
Expand Down Expand Up @@ -141,8 +135,7 @@ def build_gallery(srcdir, gallery):
source_dir = os.path.abspath(
os.path.join(os.path.dirname(os.path.dirname(srcdir)), "notebooks")
)
table_of_contents_file = os.path.join(
source_dir, TABLE_OF_CONTENTS_FILENAME.format(gallery))
table_of_contents_file = os.path.join(source_dir, TABLE_OF_CONTENTS_FILENAME.format(gallery))
tocjs = TableOfContentsJS()
tocjs.load(table_of_contents_file)

Expand All @@ -157,7 +150,7 @@ def build_gallery(srcdir, gallery):

if not os.path.exists(source_dir):
os.makedirs(source_dir)

# Create default image
default_png_path = os.path.join(os.path.join(target_dir, "_images"), "default.png")
shutil.copy(DEFAULT_IMG_LOC, default_png_path)
Expand All @@ -178,27 +171,25 @@ def build_gallery(srcdir, gallery):
filename = basename.split(".")[0]
data[basename] = {
"title": " ".join(filename.split("_")),
"url": os.path.join(os.sep, gallery, "../"+filename+".html"),
"url": os.path.join(os.sep, gallery, "../" + filename + ".html"),
"thumb": os.path.basename(default_png_path),
}

js_file = os.path.join(image_dir, f"gallery_{gallery}_contents.js")
with open(table_of_contents_file) as toc:
table_of_contents = toc.read()

js_contents = "Gallery.examples = {}\n{}".format(
json.dumps(data), table_of_contents
)
js_contents = "Gallery.examples = {}\n{}".format(json.dumps(data), table_of_contents)

with open(js_file, "w") as js:
js.write(js_contents)

with open(os.path.join(target_dir, "index.rst"), "w") as index:
index.write(INDEX_TEMPLATE.format(
sphinx_tag="notebook_gallery",
gallery=gallery,
Gallery=gallery.title().rstrip("s")
))
index.write(
INDEX_TEMPLATE.format(
sphinx_tag="notebook_gallery", gallery=gallery, Gallery=gallery.title().rstrip("s")
)
)

os.chdir(working_dir)

Expand Down
61 changes: 22 additions & 39 deletions pymc3/gp/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ def full(self, X, Xs):

def _slice(self, X, Xs):
if self.input_dim != X.shape[-1]:
warnings.warn(f"Only {self.input_dim} column(s) out of {X.shape[-1]} are"
" being used to compute the covariance function. If this"
" is not intended, increase 'input_dim' parameter to"
" the number of columns to use. Ignore otherwise.", UserWarning)
warnings.warn(
f"Only {self.input_dim} column(s) out of {X.shape[-1]} are"
" being used to compute the covariance function. If this"
" is not intended, increase 'input_dim' parameter to"
" the number of columns to use. Ignore otherwise.",
UserWarning,
)
X = tt.as_tensor_variable(X[:, self.active_dims])
if Xs is not None:
Xs = tt.as_tensor_variable(Xs[:, self.active_dims])
Expand All @@ -109,9 +112,9 @@ def __rmul__(self, other):
return self.__mul__(other)

def __pow__(self, other):
if(
isinstance(other, theano.compile.SharedVariable) and
other.get_value().squeeze().shape == ()
if (
isinstance(other, theano.compile.SharedVariable)
and other.get_value().squeeze().shape == ()
):
other = tt.squeeze(other)
return Exponentiated(self, other)
Expand All @@ -123,7 +126,6 @@ def __pow__(self, other):

raise ValueError("A covariance function can only be exponentiated by a scalar value")


def __array_wrap__(self, result):
"""
Required to allow radd/rmul by numpy arrays.
Expand All @@ -132,7 +134,9 @@ def __array_wrap__(self, result):
if len(result.shape) <= 1:
result = result.reshape(1, 1)
elif len(result.shape) > 2:
raise ValueError(f"cannot combine a covariance function with array of shape {result.shape}")
raise ValueError(
f"cannot combine a covariance function with array of shape {result.shape}"
)
r, c = result.shape
A = np.zeros((r, c))
for i in range(r):
Expand All @@ -149,11 +153,7 @@ def __array_wrap__(self, result):
class Combination(Covariance):
def __init__(self, factor_list):
input_dim = max(
[
factor.input_dim
for factor in factor_list
if isinstance(factor, Covariance)
]
[factor.input_dim for factor in factor_list if isinstance(factor, Covariance)]
)
super().__init__(input_dim=input_dim)
self.factor_list = []
Expand Down Expand Up @@ -205,10 +205,7 @@ class Exponentiated(Covariance):
def __init__(self, kernel, power):
self.kernel = kernel
self.power = power
super().__init__(
input_dim=self.kernel.input_dim,
active_dims=self.kernel.active_dims
)
super().__init__(input_dim=self.kernel.input_dim, active_dims=self.kernel.active_dims)

def __call__(self, X, Xs=None, diag=False):
return self.kernel(X, Xs, diag=diag) ** self.power
Expand Down Expand Up @@ -247,9 +244,7 @@ def _split(self, X, Xs):

def __call__(self, X, Xs=None, diag=False):
X_split, Xs_split = self._split(X, Xs)
covs = [
cov(x, xs, diag) for cov, x, xs in zip(self.factor_list, X_split, Xs_split)
]
covs = [cov(x, xs, diag) for cov, x, xs in zip(self.factor_list, X_split, Xs_split)]
return reduce(mul, covs)


Expand Down Expand Up @@ -431,9 +426,7 @@ class Matern52(Stationary):
def full(self, X, Xs=None):
X, Xs = self._slice(X, Xs)
r = self.euclidean_dist(X, Xs)
return (1.0 + np.sqrt(5.0) * r + 5.0 / 3.0 * tt.square(r)) * tt.exp(
-1.0 * np.sqrt(5.0) * r
)
return (1.0 + np.sqrt(5.0) * r + 5.0 / 3.0 * tt.square(r)) * tt.exp(-1.0 * np.sqrt(5.0) * r)


class Matern32(Stationary):
Expand Down Expand Up @@ -605,14 +598,10 @@ def __init__(self, input_dim, lengthscale_func, args=None, active_dims=None):
super().__init__(input_dim, active_dims)
if active_dims is not None:
if len(active_dims) > 1:
raise NotImplementedError(
("Higher dimensional inputs ", "are untested")
)
raise NotImplementedError(("Higher dimensional inputs ", "are untested"))
else:
if input_dim != 1:
raise NotImplementedError(
("Higher dimensional inputs ", "are untested")
)
raise NotImplementedError(("Higher dimensional inputs ", "are untested"))
if not callable(lengthscale_func):
raise TypeError("lengthscale_func must be callable")
self.lfunc = handle_args(lengthscale_func, args)
Expand Down Expand Up @@ -642,9 +631,7 @@ def full(self, X, Xs=None):
r2 = self.square_dist(X, Xs)
rx2 = tt.reshape(tt.square(rx), (-1, 1))
rz2 = tt.reshape(tt.square(rz), (1, -1))
return tt.sqrt((2.0 * tt.outer(rx, rz)) / (rx2 + rz2)) * tt.exp(
-1.0 * r2 / (rx2 + rz2)
)
return tt.sqrt((2.0 * tt.outer(rx, rz)) / (rx2 + rz2)) * tt.exp(-1.0 * r2 / (rx2 + rz2))

def diag(self, X):
return tt.alloc(1.0, X.shape[0])
Expand Down Expand Up @@ -734,19 +721,15 @@ def __init__(self, input_dim, W=None, kappa=None, B=None, active_dims=None):
raise ValueError("Coregion requires exactly one dimension to be active")
make_B = W is not None or kappa is not None
if make_B and B is not None:
raise ValueError(
"Exactly one of (W, kappa) and B must be provided to Coregion"
)
raise ValueError("Exactly one of (W, kappa) and B must be provided to Coregion")
if make_B:
self.W = tt.as_tensor_variable(W)
self.kappa = tt.as_tensor_variable(kappa)
self.B = tt.dot(self.W, self.W.T) + tt.diag(self.kappa)
elif B is not None:
self.B = tt.as_tensor_variable(B)
else:
raise ValueError(
"Exactly one of (W, kappa) and B must be provided to Coregion"
)
raise ValueError("Exactly one of (W, kappa) and B must be provided to Coregion")

def full(self, X, Xs=None):
X, Xs = self._slice(X, Xs)
Expand Down
3 changes: 2 additions & 1 deletion pymc3/gp/mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import theano.tensor as tt

__all__ = ['Zero', 'Constant', 'Linear']
__all__ = ["Zero", "Constant", "Linear"]


class Mean:
Expand Down Expand Up @@ -48,6 +48,7 @@ class Zero(Mean):
def __call__(self, X):
return tt.alloc(0.0, X.shape[0])


class Constant(Mean):
R"""
Constant mean function for Gaussian process.
Expand Down
Loading

0 comments on commit 3410f4d

Please sign in to comment.