Skip to content

Commit

Permalink
Speed up notebooks (GPflow#789)
Browse files Browse the repository at this point in the history
Notebooks are slow to execute. Additional utility functions help to detect where notebook are run and control number of iterations (optimization, standard loops and cetera), therefore minimizing spent time on running notebook integration tests.
  • Loading branch information
st-- authored and awav committed Jun 19, 2018
1 parent bb08f22 commit 61088fd
Show file tree
Hide file tree
Showing 27 changed files with 2,591 additions and 1,573 deletions.
271 changes: 204 additions & 67 deletions doc/source/notebooks/FITCvsVFE.ipynb

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions doc/source/notebooks/FITCvsVFE.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import print_function
import gpflow
from gpflow.test_util import notebook_niter
import tensorflow as tf
import os
import numpy as np
import cProfile
import csv

tol=1e-11
nRepeats = 50
nRepeats = notebook_niter(50)

predict_limits = [-4., 4.]
inducing_points_limits = [-1., 9]
Expand Down Expand Up @@ -75,9 +75,9 @@ def getSparseModel(X,Y,isFITC=False):
return m

def printModelParameters(model):
print("Likelihood variance ", model.likelihood.variance, "\n")
print("Kernel variance ", model.kern.variance, "\n")
print("Kernel lengthscale ", model.kern.lengthscales, "\n")
print("Likelihood variance ", model.likelihood.variance.value, "\n")
print("Kernel variance ", model.kern.variance.value, "\n")
print("Kernel lengthscale ", model.kern.lengthscales.value, "\n")

def plotPredictions(ax, model, color, label):
xtest = np.sort(readCsvFile('data/snelson_test_inputs'))
Expand All @@ -92,9 +92,10 @@ def trainSparseModel(xtrain,ytrain,exact_model,isFITC, xtest, ytest):
sparse_model.kern.lengthscales = exact_model.kern.lengthscales.read_value().copy()
sparse_model.kern.variance = exact_model.kern.variance.read_value().copy()
callback = cb(sparse_model, xtest, ytest)
opt = gpflow.train.ScipyOptimizer()
for repeatIndex in range(nRepeats):
print("repeatIndex ",repeatIndex)
sparse_model.optimize(disp=False, maxiter= 2000, tol=tol, callback=callback)
print("repeatIndex ", repeatIndex)
opt.minimize(sparse_model, disp=False, maxiter=notebook_niter(2000), step_callback=callback)
return sparse_model, callback

def plotComparisonFigure(xtrain, sparse_model,exact_model, ax_predictions, ax_inducing_points, ax_optimization, iterations, log_likelihoods,hold_out_likelihood, title):
Expand Down Expand Up @@ -149,7 +150,8 @@ def snelsonDemo():

#run exact inference on training data.
exact_model = getRegressionModel(xtrain,ytrain)
exact_model.optimize(maxiter= 2000000, tol=tol)
opt = gpflow.train.ScipyOptimizer()
opt.minimize(exact_model, maxiter=notebook_niter(2000000))

figA, axes = plt.subplots(1,1)
inds = np.argsort(xtrain.flatten())
Expand Down
302 changes: 213 additions & 89 deletions doc/source/notebooks/GPLVM.ipynb

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions doc/source/notebooks/SGPR_notes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"Substituting $\\mathbf K_{uu} = {\\mathbf {L L}^\\top}$:\n",
"$$\n",
Expand Down Expand Up @@ -268,9 +266,9 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [py35]",
"display_name": "Python 3",
"language": "python",
"name": "Python [py35]"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -282,9 +280,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions doc/source/notebooks/Sanity_check.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3"
"version": "3.6.4"
},
"widgets": {
"state": {},
"version": "1.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 2
}
153 changes: 55 additions & 98 deletions doc/source/notebooks/classification.ipynb

Large diffs are not rendered by default.

150 changes: 72 additions & 78 deletions doc/source/notebooks/coreg_demo.ipynb

Large diffs are not rendered by default.

Binary file not shown.
14 changes: 5 additions & 9 deletions doc/source/notebooks/kernels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"### Kernel choices\n",
"GPflow comes with lots of standard kernels. There are a couple of very simple kernels which produce constant functions, linear functions and white noise functions: \n",
Expand Down Expand Up @@ -346,9 +344,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"When combining kernels, it's often helpful to have bits of the kernel working on different dimensions. For example, to model a function that is linear in the first dimension and smooth in the second, we could use a combination of Linear and Matern52 kernels, one for each dimension. \n",
"\n",
Expand Down Expand Up @@ -560,7 +556,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -574,9 +570,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 2
}
281 changes: 115 additions & 166 deletions doc/source/notebooks/mcmc.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions doc/source/notebooks/models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -1152,13 +1152,13 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
"version": "3.6.4"
},
"widgets": {
"state": {},
"version": "1.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 2
}
Loading

0 comments on commit 61088fd

Please sign in to comment.