Skip to content

Commit

Permalink
Switch to PyTorch
Browse files Browse the repository at this point in the history
  • Loading branch information
anassinator committed Jul 7, 2018
1 parent 0ac0161 commit 8570d3d
Show file tree
Hide file tree
Showing 13 changed files with 639 additions and 825 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ python:
- "3.5"
- "3.6"
install:
- pip install pipenv yapf
- pipenv install
- pipenv run python setup.py install
- pip install yapf==0.22.0
- python setup.py install
script:
- yapf --diff --recursive .
13 changes: 3 additions & 10 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]

numpy = "==1.14.2"
scipy = "==1.0.0"
six = "==1.11.0"
theano = "==1.0.1"

torch = "==0.4.0"

[dev-packages]
yapf = "==0.22.0"



[requires]

[requires]
54 changes: 20 additions & 34 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 13 additions & 32 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gaussian Process

This is a *differentiable* `Gaussian Process
<https://en.wikipedia.org/wiki/Gaussian_process>`_ implementation for
`Theano <http://deeplearning.net/software/theano/>`_.
`PyTorch <https://pytorch.org>`_.

The code is based off of the
`Gaussian Processes for Machine Learning <http://www.gaussianprocess.org/gpml/>`_
Expand Down Expand Up @@ -35,42 +35,24 @@ After installation, :code:`import` and use as follows:
.. code-block:: python
from gp import GaussianProcess
from gp.kernels import RBFKernel, WhiteNoiseKernel
gp = GaussianProcess()
gp.fit(X, Y)
k = RBFKernel() + WhiteNoiseKernel()
gp = GaussianProcess(k, X, Y)
gp.fit()
where :code:`X` and :code:`Y` are your training data's inputs and outputs as
:code:`theano.SharedVariable`.
:code:`torch.Tensor`.

You can then use the Gaussian Process's estimates as a tensor in your own
graphs:

.. code-block:: python
mu = gp.mean
sigma = gp.standard_deviation
sigma_squared = gp.variance
log_likelihood = gp.log_likelihood
You can also differentiate any of these tensors with respect to any other
tensor variables:

.. code-block:: python
import theano.tensor as T
loss = -gp.log_likelihood
loss_wrt_hyperparameters = T.grad(loss, gp.hyperparameters)
Alternatively, you can use it standalone and compile its tensors into
functions:

.. code-block:: python
gp.compile()
mu = gp.compute_mean(x)
sigma = gp.compute_standard_deviation(x)
sigma_squared = gp.compute_variance(x)
mean = gp(x)
mean, std = gp(x, return_std=True)
mean, covar = gp(x, return_covar=True)
mean, covar, std = gp(x, return_covar=True, return_std=True)
The following is an example of what this Gaussian Process was able to estimate
with a few randomly sampled points (in blue) of a noisy :code:`sin` function.
Expand All @@ -85,12 +67,11 @@ You can see the `examples <examples/>`_ directory for some
`Jupyter <https://jupyter.org>`_ notebooks with more detailed examples. You can
also play with the *secret* functions that the Gaussian Process is attempting
to learn and see how well it performs. Depending on the complexity and nature
of the function, you might need to sample more data or lower the noise applied
to the system.
of the function, you might need to sample more data.

Finally, you can also use a custom kernel function instead of the default
Finally, you can also use a custom kernel function instead of the included
Radial-Basis Function (RBF) kernel by implementing your own :code:`Kernel`
class as in `kernel.py <gp/kernel.py>`_.
class as in `kernels.py <gp/kernels.py>`_.

Contributing
------------
Expand Down
150 changes: 70 additions & 80 deletions examples/sin_x.ipynb

Large diffs are not rendered by default.

144 changes: 59 additions & 85 deletions examples/sin_x_y.ipynb

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions gp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
"""Gaussian Process implementation for Theano."""
"""Gaussian Process implementation."""

__version__ = "0.1.0"

from .kernel import Kernel, RBFKernel
from .gaussian_process import GaussianProcess, MultiGaussianProcess
import kernels
from .models import GaussianProcess, MultiGaussianProcess

__all__ = ["GaussianProcess", "Kernel", "MultiGaussianProcess", "RBFKernel"]
__all__ = ["GaussianProcess", "MultiGaussianProcess", "kernels"]
Loading

0 comments on commit 8570d3d

Please sign in to comment.