Skip to content

Commit 4ec65a0

Browse files
committed
gp: rename sampling methods
* docstrings for gp subpackage incoming
1 parent 3949cbf commit 4ec65a0

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

UncertainSCI/gp/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def k_posterior(self, x1: np.ndarray, x2: np.ndarray | None = None):
6565
self.k(x1, self.x_obs) @ self.inv @ \
6666
(self.k(self.x_obs, x1) if x2 is None else self.k(self.x_obs, x2))
6767

68-
def prior(self, x: np.ndarray, n: int = 1) -> np.ndarray:
68+
def sample_prior(self, x: np.ndarray, n: int = 1) -> np.ndarray:
6969
ell = np.linalg.cholesky(self.k(x) + NUGGET * np.eye(len(x)))
7070
return (self.mu(x)[:, None] if n > 1 else self.mu(x)) + \
7171
ell @ np.random.normal(0, 1, (len(x), n) if n > 1 else len(x))
7272

73-
def posterior(self, x: np.ndarray, n: int = 1) -> tuple[np.ndarray, np.ndarray]:
73+
def sample_posterior(self, x: np.ndarray, n: int = 1) -> tuple[np.ndarray, np.ndarray]:
7474
ell = np.linalg.cholesky(self.k_posterior(x) + NUGGET * np.eye(len(x)))
7575
return (self.mu_posterior(x)[:, None] if n > 1 else self.mu_posterior(x)) + \
7676
ell @ np.random.normal(0, 1, (len(x), n) if n > 1 else len(x))
@@ -139,7 +139,7 @@ def k_posterior(self, x1: np.ndarray, x2: np.ndarray | None = None):
139139
return (self.k(x1) if x2 is None else self.k(x1, x2)) - \
140140
self.k(x1, self.x_obs) @ self.inv @ (self.k(self.x_obs, x1) if x2 is None else self.k(self.x_obs, x2))
141141

142-
def prior(self, x: np.ndarray, n: int = 1) -> np.ndarray:
142+
def sample_prior(self, x: np.ndarray, n: int = 1) -> np.ndarray:
143143
if n > 1:
144144
sn = (len(x) * self.cdim, n)
145145
sr = (len(x), self.cdim, n)
@@ -152,7 +152,7 @@ def prior(self, x: np.ndarray, n: int = 1) -> np.ndarray:
152152
(ell @ np.random.normal(0, 1, sn)).reshape(sr)
153153
return y
154154

155-
def posterior(self, x: np.ndarray, n: int = 1) -> tuple[np.ndarray, np.ndarray]:
155+
def sample_posterior(self, x: np.ndarray, n: int = 1) -> tuple[np.ndarray, np.ndarray]:
156156
if n > 1:
157157
sn = (len(x) * self.cdim, n)
158158
sr = (len(x), self.cdim, n)

demos/gp-2d.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
"outputs": [],
215215
"source": [
216216
"X = np.stack((E1MG, E2MG), axis=-1).reshape((-1, 2))\n",
217-
"y = g.prior(X).reshape((E2_PTS, E1_PTS))\n",
217+
"y = g.sample_prior(X).reshape((E2_PTS, E1_PTS))\n",
218218
"\n",
219219
"\n",
220220
"fig, ax = plt.subplots(1, 1, figsize=FIGSIZE)\n",

demos/gp-adaptive.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
" ax.plot(X, g.mu_posterior(X), color='black')\n",
8282
" ax.plot(X, g.mu_posterior(X) + np.sqrt(np.diag(g.k_posterior(X))), color='black')\n",
8383
" ax.plot(X, g.mu_posterior(X) - np.sqrt(np.diag(g.k_posterior(X))), color='black')\n",
84-
" ax.plot(X, g.posterior(X, 5), alpha=ALPHA)\n",
84+
" ax.plot(X, g.sample_posterior(X, 5), alpha=ALPHA)\n",
8585
"\n",
8686
" ax.set_xlim(*XLIM)\n",
8787
" ax.set_ylim(*YLIM)\n"
@@ -176,7 +176,7 @@
176176
"metadata": {},
177177
"outputs": [],
178178
"source": [
179-
"plt.plot(X, g.prior(X, 5))\n",
179+
"plt.plot(X, g.sample_prior(X, 5))\n",
180180
"plt.xlim(*XLIM)\n",
181181
"plt.ylim(*YLIM)\n",
182182
"plt.show()\n"

demos/gp-vector.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
"outputs": [],
217217
"source": [
218218
"X = np.stack((E1MG, E2MG), axis=-1).reshape((-1, 2))\n",
219-
"y = g.prior(X).reshape((E2_PTS, E1_PTS, -1))\n",
219+
"y = g.sample_prior(X).reshape((E2_PTS, E1_PTS, -1))\n",
220220
"\n",
221221
"\n",
222222
"fig, ax = plt.subplots(1, 1, figsize=FIGSIZE)\n",

0 commit comments

Comments
 (0)