Skip to content

Commit cb01649

Browse files
authored
Merge pull request #49 from GPflow/notebook_tests
Notebook tests
2 parents a473070 + a159767 commit cb01649

12 files changed

Lines changed: 242 additions & 172 deletions

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sudo: false
1+
sudo: required
22
dist: trusty
33
language: python
44
python:
@@ -9,9 +9,9 @@ cache: pip
99
install:
1010
- pip install -U pip wheel
1111
- pip install tensorflow==1.0.1
12-
- pip install --process-dependency-links .
13-
- pip install .[test]
14-
- pip install codecov
12+
- pip install -U --process-dependency-links .
13+
- pip install -U .[test]
14+
- pip install -U codecov
1515
script:
1616
- nosetests testing
1717
after_success:

GPflowOpt/optim.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def __init__(self, domain, nsamples):
142142
"""
143143
super(MCOptimizer, self).__init__(domain, exclude_gradient=True)
144144
self._nsamples = nsamples
145+
# Clear the initial data points
146+
self.set_initial(np.empty((0, self.domain.size)))
145147

146148
@Optimizer.domain.setter
147149
def domain(self, dom):
@@ -163,9 +165,11 @@ def _optimize(self, objective):
163165

164166
def set_initial(self, initial):
165167
initial = np.atleast_2d(initial)
166-
super(MCOptimizer, self).set_initial(initial)
167168
if initial.size > 0:
168169
warnings.warn("Initial points set in {0} are ignored.".format(self.__class__.__name__), UserWarning)
170+
return
171+
172+
super(MCOptimizer, self).set_initial(initial)
169173

170174

171175
class CandidateOptimizer(MCOptimizer):
@@ -183,8 +187,6 @@ def __init__(self, domain, candidates):
183187
super(CandidateOptimizer, self).__init__(domain, candidates.shape[0])
184188
assert (candidates in domain)
185189
self.candidates = candidates
186-
# Clear the initial data points
187-
self.set_initial(np.empty((0, self.domain.size)))
188190

189191
def _get_eval_points(self):
190192
return self.candidates
@@ -235,11 +237,11 @@ def __init__(self, optimizers):
235237
no_gradient = any(map(lambda opt: not opt.gradient_enabled(), optimizers))
236238
super(StagedOptimizer, self).__init__(optimizers[0].domain, exclude_gradient=no_gradient)
237239
self.optimizers = optimizers
238-
self.set_initial(np.empty((0, self.domain.size)))
240+
del self._initial
239241

240242
@Optimizer.domain.setter
241243
def domain(self, domain):
242-
super(StagedOptimizer, self.__class__).domain.fset(self, domain)
244+
self._domain = domain
243245
for optimizer in self.optimizers:
244246
optimizer.domain = domain
245247

@@ -254,7 +256,6 @@ def optimize(self, objectivefx):
254256
is returned.
255257
"""
256258

257-
self.optimizers[0].set_initial(self.get_initial())
258259
results = []
259260
for current, following in zip(self.optimizers[:-1], self.optimizers[1:]):
260261
result = current.optimize(objectivefx)
@@ -273,3 +274,9 @@ def optimize(self, objectivefx):
273274
if any(r.success for r in results):
274275
result.x, result.fun = self._best_x(results)
275276
return result
277+
278+
def get_initial(self):
279+
return self.optimizers[0].get_initial()
280+
281+
def set_initial(self, initial):
282+
self.optimizers[0].set_initial(initial)

doc/source/notebooks/constrained_bo.ipynb

Lines changed: 36 additions & 29 deletions
Large diffs are not rendered by default.

doc/source/notebooks/hyperopt.ipynb

Lines changed: 34 additions & 28 deletions
Large diffs are not rendered by default.

doc/source/notebooks/multiobjective.ipynb

Lines changed: 68 additions & 68 deletions
Large diffs are not rendered by default.

doc/source/notebooks/new_acquisition.ipynb

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

doc/source/notebooks/structure.ipynb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
{
3737
"cell_type": "code",
38-
"execution_count": 1,
38+
"execution_count": 5,
3939
"metadata": {
4040
"collapsed": true
4141
},
@@ -46,7 +46,7 @@
4646
"def fx(X):\n",
4747
" X = np.atleast_2d(X)\n",
4848
" # Return objective & gradient\n",
49-
" return np.sum(np.square(X), axis=1), 2*X"
49+
" return np.sum(np.square(X), axis=1)[:,None], 2*X"
5050
]
5151
},
5252
{
@@ -59,7 +59,7 @@
5959
},
6060
{
6161
"cell_type": "code",
62-
"execution_count": 2,
62+
"execution_count": 6,
6363
"metadata": {},
6464
"outputs": [
6565
{
@@ -68,10 +68,10 @@
6868
"<table id='domain' width=100%><tr><td>Name</td><td>Type</td><td>Values</td></tr><tr><td>x1</td><td>Continuous</td><td>[-2. 2.]</td></tr><tr><td>x2</td><td>Continuous</td><td>[-1. 2.]</td></tr></table>"
6969
],
7070
"text/plain": [
71-
"<GPflowOpt.domain.Domain at 0x7fcc640c42b0>"
71+
"<GPflowOpt.domain.Domain at 0x7f60e22b2dd8>"
7272
]
7373
},
74-
"execution_count": 2,
74+
"execution_count": 6,
7575
"metadata": {},
7676
"output_type": "execute_result"
7777
}
@@ -93,7 +93,7 @@
9393
},
9494
{
9595
"cell_type": "code",
96-
"execution_count": 3,
96+
"execution_count": 7,
9797
"metadata": {},
9898
"outputs": [
9999
{
@@ -110,7 +110,7 @@
110110
" x: array([[ 0., 0.]])"
111111
]
112112
},
113-
"execution_count": 3,
113+
"execution_count": 7,
114114
"metadata": {},
115115
"output_type": "execute_result"
116116
}
@@ -132,20 +132,20 @@
132132
},
133133
{
134134
"cell_type": "code",
135-
"execution_count": 4,
135+
"execution_count": 8,
136136
"metadata": {},
137137
"outputs": [
138138
{
139139
"data": {
140140
"text/plain": [
141-
" fun: array([[ 0.0330519]])\n",
141+
" fun: array([[ 0.02115951]])\n",
142142
" message: 'OK'\n",
143-
" nfev: 201\n",
143+
" nfev: 200\n",
144144
" success: True\n",
145-
" x: array([[-0.04434619, -0.17631027]])"
145+
" x: array([[ 0.05731395, -0.13369599]])"
146146
]
147147
},
148-
"execution_count": 4,
148+
"execution_count": 8,
149149
"metadata": {},
150150
"output_type": "execute_result"
151151
}
@@ -191,18 +191,18 @@
191191
},
192192
{
193193
"cell_type": "code",
194-
"execution_count": 5,
194+
"execution_count": 9,
195195
"metadata": {},
196196
"outputs": [
197197
{
198198
"name": "stdout",
199199
"output_type": "stream",
200200
"text": [
201-
" fun: array([ 0.0008643])\n",
201+
" fun: array([ 0.17684308])\n",
202202
" message: 'OK'\n",
203203
" nfev: 15\n",
204204
" success: True\n",
205-
" x: array([[ 0. , 0.02939904]])\n"
205+
" x: array([[ 0. , 0.42052714]])\n"
206206
]
207207
}
208208
],
@@ -293,7 +293,7 @@
293293
"language_info": {
294294
"codemirror_mode": {
295295
"name": "ipython",
296-
"version": 3.0
296+
"version": 3
297297
},
298298
"file_extension": ".py",
299299
"mimetype": "text/x-python",
@@ -304,5 +304,5 @@
304304
}
305305
},
306306
"nbformat": 4,
307-
"nbformat_minor": 0
308-
}
307+
"nbformat_minor": 1
308+
}

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
extras_require={'tensorflow': ['tensorflow>=1.0.0'],
4747
'tensorflow with gpu': ['tensorflow-gpu>=1.0.0'],
4848
'docs': ['sphinx', 'sphinx_rtd_theme', 'numpydoc', 'nbsphinx', 'jupyter'],
49-
'test': ['nose', 'coverage', 'six', 'parameterized']},
49+
'test': ['nose', 'coverage', 'six', 'parameterized', 'nbconvert', 'nbformat','jupyter',
50+
'jupyter_client', 'matplotlib']
51+
},
5052
dependency_links=['https://github.com/GPflow/GPflow/tarball/master#egg=GPflow-0.3.5'],
5153
classifiers=['License :: OSI Approved :: Apache Software License',
5254
'Natural Language :: English',

testing/test_acquisition.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
def parabola2d(X):
1010
return np.atleast_2d(np.sum(X ** 2, axis=1)).T
1111

12-
1312
def plane(X):
1413
return X[:, [0]] - 0.5
1514

@@ -125,7 +124,6 @@ def test_enable_scaling(self):
125124
self.assertFalse(
126125
any(m.wrapped.X.value in GPflowOpt.domain.UnitCube(self.domain.size) for m in self.acquisition.models))
127126
self.acquisition.enable_scaling(self.domain)
128-
print(self.acquisition.models[0].wrapped.X.value)
129127
self.assertTrue(
130128
all(m.wrapped.X.value in GPflowOpt.domain.UnitCube(self.domain.size) for m in self.acquisition.models))
131129

testing/test_datascaler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,4 @@ def test_predict_scaling(self):
103103
Yt = parabola2d(Xt) #+ np.random.rand(20, 1) * 0.05
104104
fr = m.predict_density(Xt, Yt)
105105
fs = n.predict_density(Xt, Yt)
106-
print(fr)
107-
print(fs)
108106
np.testing.assert_allclose(fr, fs, rtol=1e-3)

0 commit comments

Comments
 (0)