Skip to content

Commit

Permalink
Merge branch 'master' into 3.2rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
fonnesbeck committed Oct 4, 2017
2 parents 1de0f86 + c7c86a0 commit 6324129
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
18 changes: 9 additions & 9 deletions docs/source/notebooks/GP-MeansAndCovs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1045,22 +1045,22 @@
}
],
"source": [
"def tanh_func(x, x1, x2, w, x0):\n",
"def tanh_func(x, ls1, ls2, w, x0):\n",
" \"\"\"\n",
" l1: Left saturation value\n",
" l2: Right saturation value\n",
" lw: Transition width\n",
" x0: Transition location.\n",
" ls1: left saturation value\n",
" ls2: right saturation value\n",
" w: transition width\n",
" x0: transition location.\n",
" \"\"\"\n",
" return (x1 + x2) / 2.0 - (x1 - x2) / 2.0 * tt.tanh((x - x0) / w)\n",
" return (ls1 + ls2) / 2.0 - (ls1 - ls2) / 2.0 * tt.tanh((x - x0) / w)\n",
"\n",
"ls1 = 0.05\n",
"ls2 = 0.6\n",
"lw = 0.3\n",
"w = 0.3\n",
"x0 = 1.0\n",
"cov = pm.gp.cov.Gibbs(1, tanh_func, args=(ls1, ls2, lw, x0))\n",
"cov = pm.gp.cov.Gibbs(1, tanh_func, args=(ls1, ls2, w, x0))\n",
" \n",
"wf = theano.function([], tanh_func(X, ls1, ls2, lw, x0))()\n",
"wf = theano.function([], tanh_func(X, ls1, ls2, w, x0))()\n",
"plt.plot(X, wf); plt.ylabel(\"tanh_func(X)\"); plt.xlabel(\"X\"); plt.title(\"Lengthscale as a function of X\");\n",
"\n",
"K = cov(X).eval()\n",
Expand Down
11 changes: 6 additions & 5 deletions pymc3/gp/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,16 @@ def square_dist(self, X, Xs=None):
return tt.clip(sqd, 0.0, np.inf)

def full(self, X, Xs=None):
X, Xs = self._slice(X, Xs)
rx = self.lfunc(X, self.args)
rx2 = tt.reshape(tt.square(rx), (-1, 1))
rx = self.lfunc(tt.as_tensor_variable(X), self.args)
if Xs is None:
rz = self.lfunc(tt.as_tensor_variable(X), self.args)
X, Xs = self._slice(X, Xs)
r2 = self.square_dist(X, X)
rz = self.lfunc(X, self.args)
else:
rz = self.lfunc(tt.as_tensor_variable(Xs), self.args)
X, Xs = self._slice(X, Xs)
r2 = self.square_dist(X, Xs)
rz = self.lfunc(Xs, self.args)
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)))
Expand Down

0 comments on commit 6324129

Please sign in to comment.