Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 1db48f3a735eb0fba06a7d503f080a7ead512604 authored by Artem Artemev on 11 July 2018, 12:50:44 UTC, committed by GitHub on 11 July 2018, 12:50:44 UTC
Update version.py file to 1.2.0 (#812)
1 parent 707b195
  • Files
  • Changes
  • 2109064
  • /
  • doc
  • /
  • source
  • /
  • notebooks
  • /
  • settings.ipynb
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:1db48f3a735eb0fba06a7d503f080a7ead512604
directory badge
swh:1:dir:5e7ecf0b802d3e60cfac66660aeb4416a50ef469
content badge
swh:1:cnt:56f4ea12a9ed54ee96d3ba7e91f1c55247474858

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
settings.ipynb
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Settings\n",
    "GPflow has a config file, `gpflowrc` which allows the user to change the default behavious in GPflow. GPflow searches for the file in the following order:\n",
    "1. In the working directory\n",
    "2. In the user's home directory\n",
    "3. In the GPflow directory (revert to default)\n",
    "\n",
    "You can also make `gpflowrc` a hidden file, if you don't want it clutting your home directory, by renaming as `.gpflowrc`. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By default, the configuration looks like this:\n",
    "```\n",
    "[verbosity]\n",
    "tf_compile_verb = False\n",
    "hmc_verb = True\n",
    "optimisation_verb = False\n",
    "\n",
    "[dtypes]\n",
    "float_type = float64\n",
    "int_type = int32\n",
    "\n",
    "[numerics]\n",
    "jitter_level = 1e-6\n",
    "\n",
    "[profiling]\n",
    "dump_timeline = False\n",
    "dump_tensorboard = False\n",
    "\n",
    "[session]\n",
    "intra_op_parallelism_threads = 0\n",
    "inter_op_parallelism_threads = 0\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Accessing settings\n",
    "You can access the settings as `gpflow.settings`, and the different options are nested under the headings in the file. For example, to see how much jitter is added before attempting Cholesky decomposition:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1e-06\n"
     ]
    }
   ],
   "source": [
    "import gpflow\n",
    "print(gpflow.settings.jitter)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Modifying settings\n",
    "Settings can be modified for an entire session, or for a limited set of statements, using a Python context manager. It is recommeded to use the context manager, as this prevents the change of state unintentionally spilling into other parts of the program."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example\n",
    "By default, verbose compiling is switched off:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import numpy.random as rnd\n",
    "X = rnd.randn(100, 1)\n",
    "Y = np.sin(X) + np.sin(1.5*X) + 0.3 * rnd.randn(*X.shape)\n",
    "\n",
    "m = gpflow.models.SGPR(X, Y, gpflow.kernels.RBF(1), Z=X.copy())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This can be switched on. First make a copy of the current settings using `get_settings()`, then modify and set using the context manager `temp_settings`. Finally, we see the compilation message showing up."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Optimization terminated with:\n",
      "  Message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'\n",
      "  Objective function value: 27.154970\n",
      "  Number of iterations: 14\n",
      "  Number of functions evaluations: 19\n"
     ]
    }
   ],
   "source": [
    "custom_config = gpflow.settings.get_settings()\n",
    "custom_config.verbosity.tf_compile_verb = True\n",
    "opt = gpflow.train.ScipyOptimizer()\n",
    "with gpflow.settings.temp_settings(custom_config), gpflow.session_manager.get_session().as_default():\n",
    "    m = gpflow.models.SGPR(X, Y, gpflow.kernels.RBF(1), Z=X.copy())\n",
    "    opt.minimize(m)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Change TensorFlow session settings\n",
    "GPflow may create multiple tensorflow sessions for a single model; for example a separate session is created for each autoflow method. To control the session parameters change the [session] section of the settings. This section may contain any valid [TensorFlow ConfigProto](https://www.tensorflow.org/api_docs/python/tf/ConfigProto) setting. \n",
    "\n",
    "For instance to ensure all tensorflow graphs are run serially set\n",
    "```\n",
    "[session]\n",
    "intra_op_parallelism_threads = 1\n",
    "inter_op_parallelism_threads = 1\n",
    "```\n",
    "As per the TensorFlow documentation, a setting of 0 means the system picks an appropriate number of cores to use.\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Notes\n",
    "It's important to note that for some cases, a re-compilation of the model is necessary. For example, if we change the jitter level and optimise, the hyperparameters won't change unless we explicitly recompile the model. Additionally, state defined inside the context manager will be carried over to outside the context manager, until the next recompile.\n",
    "\n",
    "Essentially, to be safe, **if a model is to be used inside a context manager, everything should be done within the context manager**.\n",
    "\n",
    "### Example\n",
    "We first look at the kernel hyperparameters from the previous optimisation. Those inside the context manager will be the same, despite the drastically increased jitter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(1.231800598892151)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.kern.lengthscales.read_value()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Optimization terminated with:\n",
      "  Message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'\n",
      "  Objective function value: 27.154962\n",
      "  Number of iterations: 8\n",
      "  Number of functions evaluations: 10\n",
      "1.2315556419374536\n"
     ]
    }
   ],
   "source": [
    "custom_config.numerics.jitter_level = 10e-0\n",
    "with gpflow.settings.temp_settings(custom_config):\n",
    "    opt.minimize(m)\n",
    "    print(m.kern.lengthscales.read_value())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When the model is re-compiled, the modified jitter is taken into account in the TensorFlow graph, and the resulting hyperparameters are very different."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Optimization terminated with:\n",
      "  Message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'\n",
      "  Objective function value: 93.107377\n",
      "  Number of iterations: 167\n",
      "  Number of functions evaluations: 184\n",
      "1.0021331815790675\n"
     ]
    }
   ],
   "source": [
    "m.clear()\n",
    "with gpflow.settings.temp_settings(custom_config), gpflow.session_manager.get_session().as_default():\n",
    "    m.compile()\n",
    "    opt.minimize(m)\n",
    "    print(m.kern.lengthscales.read_value())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API