Skip to content

Commit

Permalink
starting to switch to ipynb tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Oct 5, 2017
1 parent 059c8df commit e711c6d
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2010-2016 Daniel Foreman-Mackey & contributors.
Copyright (c) 2010-2017 Daniel Foreman-Mackey & contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -52,7 +52,7 @@ The BibTeX entry for the paper is::
License
-------

Copyright 2010-2016 Dan Foreman-Mackey and contributors.
Copyright 2010-2017 Dan Foreman-Mackey and contributors.

emcee is free software made available under the MIT License. For details see
the LICENSE file.
8 changes: 7 additions & 1 deletion docs/Makefile
Expand Up @@ -16,6 +16,12 @@ I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext

default: dirhtml
TUTORIALS = tutorials/quickstart.rst

tutorials/%.rst: _static/notebooks/%.ipynb tutorials/tutorial_rst.tpl
jupyter nbconvert --template tutorials/tutorial_rst --to rst $< --output-dir tutorials

help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
Expand Down Expand Up @@ -46,7 +52,7 @@ html:
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

dirhtml:
dirhtml: $(TUTORIALS)
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
Expand Down
136 changes: 136 additions & 0 deletions docs/_static/notebooks/quickstart.ipynb
@@ -0,0 +1,136 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%config InlineBackend.figure_format = \"retina\"\n",
"\n",
"from __future__ import print_function\n",
"\n",
"from matplotlib import rcParams\n",
"rcParams[\"savefig.dpi\"] = 100\n",
"rcParams[\"figure.dpi\"] = 100\n",
"rcParams[\"font.size\"] = 20"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Quickstart \n",
"\n",
"This notebook was made with the following version of emcee:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'3.0.0.dev0'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import emcee\n",
"emcee.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The easiest way to get started with using emcee is to use it for a project. To get you started, here’s an annotated, fully-functional example that demonstrates a standard usage pattern.\n",
"\n",
"## How to sample a multi-dimensional Gaussian\n",
"\n",
"We’re going to demonstrate how you might draw samples from the multivariate Gaussian density given by:\n",
"\n",
"$$\n",
"p(\\vec{x}) \\propto \\exp \\left [ - \\frac{1}{2} (\\vec{x} -\n",
" \\vec{\\mu})^\\mathrm{T} \\, \\Sigma ^{-1} \\, (\\vec{x} - \\vec{\\mu})\n",
" \\right ]\n",
"$$\n",
"\n",
"where $\\vec{\\mu}$ is an $N$-dimensional vector position of the mean of the density and $\\Sigma$ is the square N-by-N covariance matrix.\n",
"\n",
"The first thing that we need to do is import the necessary modules:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import emcee"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, we’ll code up a Python function that returns the density $p(\\vec{x})$ for specific values of $\\vec{x}$, $\\vec{\\mu}$ and $\\Sigma^{-1}$. In fact, emcee actually requires the logarithm of $p$. We’ll call it `log_prob`:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def log_prob(x, mu, icov):\n",
" diff = x - mu\n",
" return -0.5*np.dot(diff,np.dot(icov,diff))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
5 changes: 0 additions & 5 deletions docs/_themes/dfm/layout.html
Expand Up @@ -19,11 +19,6 @@
<div class="footer">
&copy; Copyright {{ copyright }}.
</div>
<a href="https://github.com/dfm/emcee" class="github">
<img style="position: absolute; top: 0; right: 0; border: 0;"
src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"
alt="Fork me on GitHub" class="github"/>
</a>

<script type="text/javascript">
var _gaq = _gaq || [];
Expand Down
5 changes: 3 additions & 2 deletions docs/_themes/dfm/static/flasky.css_t
Expand Up @@ -198,7 +198,8 @@ div.body p, div.body dd, div.body li {
}

div.highlight {
background-color: white;
background: #eee;
padding-left: 10px;
}

dt:target, .highlight {
Expand Down Expand Up @@ -343,7 +344,7 @@ ul, ol {
}

pre {
background: #eee;
/*background: #eee;*/
padding: 7px 30px;
margin: 15px -30px;
line-height: 1.3em;
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -44,7 +44,7 @@

# General information about the project.
project = u'emcee'
copyright = u'2012–2013, Dan Foreman-Mackey & contributors'
copyright = u'2012-2017, Dan Foreman-Mackey & contributors'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Expand Up @@ -52,7 +52,7 @@ User Guide
:maxdepth: 2

user/install
user/quickstart
tutorials/quickstart
user/line
user/advanced
user/pt
Expand Down
67 changes: 67 additions & 0 deletions docs/tutorials/quickstart.rst
@@ -0,0 +1,67 @@

.. module:: george

**Note:** This tutorial was generated from an IPython notebook that can be
downloaded `here <../../_static/notebooks/quickstart.ipynb>`_.

.. _quickstart:


Quickstart
==========

This notebook was made with the following version of emcee:

.. code:: python
import emcee
emcee.__version__
.. parsed-literal::
'3.0.0.dev0'
The easiest way to get started with using emcee is to use it for a
project. To get you started, here’s an annotated, fully-functional
example that demonstrates a standard usage pattern.

How to sample a multi-dimensional Gaussian
------------------------------------------

We’re going to demonstrate how you might draw samples from the
multivariate Gaussian density given by:

.. math::
p(\vec{x}) \propto \exp \left [ - \frac{1}{2} (\vec{x} -
\vec{\mu})^\mathrm{T} \, \Sigma ^{-1} \, (\vec{x} - \vec{\mu})
\right ]
where :math:`\vec{\mu}` is an :math:`N`-dimensional vector position of
the mean of the density and :math:`\Sigma` is the square N-by-N
covariance matrix.

The first thing that we need to do is import the necessary modules:

.. code:: python
import numpy as np
import emcee
Then, we’ll code up a Python function that returns the density
:math:`p(\vec{x})` for specific values of :math:`\vec{x}`,
:math:`\vec{\mu}` and :math:`\Sigma^{-1}`. In fact, emcee actually
requires the logarithm of :math:`p`. We’ll call it ``log_prob``:

.. code:: python
def log_prob(x, mu, icov):
diff = x - mu
return -0.5*np.dot(diff,np.dot(icov,diff))
94 changes: 94 additions & 0 deletions docs/tutorials/tutorial_rst.tpl
@@ -0,0 +1,94 @@
{%- extends 'display_priority.tpl' -%}

{% block header %}
.. module:: george

**Note:** This tutorial was generated from an IPython notebook that can be
downloaded `here <../../_static/notebooks/{{ resources.metadata.name }}.ipynb>`_.

.. _{{resources.metadata.name}}:
{% endblock %}

{% block in_prompt %}
{% endblock in_prompt %}

{% block output_prompt %}
{% endblock output_prompt %}

{% block input %}
{%- if cell.source.strip() and not cell.source.startswith("%") -%}
.. code:: python

{{ cell.source | indent}}
{% endif -%}
{% endblock input %}

{% block error %}
::

{{ super() }}
{% endblock error %}

{% block traceback_line %}
{{ line | indent | strip_ansi }}
{% endblock traceback_line %}

{% block execute_result %}
{% block data_priority scoped %}
{{ super() }}
{% endblock %}
{% endblock execute_result %}

{% block stream %}
.. parsed-literal::

{{ output.text | indent }}
{% endblock stream %}

{% block data_svg %}
.. image:: {{ output.metadata.filenames['image/svg+xml'] | urlencode }}
{% endblock data_svg %}

{% block data_png %}
.. image:: {{ output.metadata.filenames['image/png'] | urlencode }}
{% endblock data_png %}

{% block data_jpg %}
.. image:: {{ output.metadata.filenames['image/jpeg'] | urlencode }}
{% endblock data_jpg %}

{% block data_latex %}
.. math::

{{ output.data['text/latex'] | strip_dollars | indent }}
{% endblock data_latex %}

{% block data_text scoped %}
.. parsed-literal::

{{ output.data['text/plain'] | indent }}
{% endblock data_text %}

{% block data_html scoped %}
.. raw:: html

{{ output.data['text/html'] | indent }}
{% endblock data_html %}

{% block markdowncell scoped %}
{{ cell.source | markdown2rst }}
{% endblock markdowncell %}

{%- block rawcell scoped -%}
{%- if cell.metadata.get('raw_mimetype', '').lower() in resources.get('raw_mimetypes', ['']) %}
{{cell.source}}
{% endif -%}
{%- endblock rawcell -%}

{% block headingcell scoped %}
{{ ("#" * cell.level + cell.source) | replace('\n', ' ') | markdown2rst }}
{% endblock headingcell %}

{% block unknowncell scoped %}
unknown type {{cell.type}}
{% endblock unknowncell %}
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -26,7 +26,8 @@
packages=["emcee", "emcee.moves"],
url="http://emcee.readthedocs.io",
license="MIT",
description="Ensemble MCMC sampling toolkit",
description=("The Python ensemble sampling toolkit for affine-invariant "
"MCMC"),
long_description=open("README.rst").read(),
package_data={"": ["LICENSE", "AUTHORS.rst"]},
include_package_data=True,
Expand Down

0 comments on commit e711c6d

Please sign in to comment.