Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env.yml for binder #25

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject

# Jupiter Notebooks
.ipynb_checkpoints/

# generated plots
*.eps
*.pdf
*.png
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
ThinkBayes
==========

Launch now and run interactively by clicking this badge,
then navigate to the \notebooks directory and open the
notebook corresponding to the chapter you want to read:
[![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/rlabbe/ThinkBayes)


This material was adapted from Allen Downey's Think Bayes
Github repository by Roger Labbe.

Mostly I took his code and tex file and converted them into
a series of Jupyter notebooks. This was sometimes problamatic.
Allen uses a lot of Python classes, and his exposition splits
the code across multiple paragraphs. It's a great pedagogical
technique, but does not cleanly work in notebooks, where you have
to specify the entire class in one cell. Furthermore, most of
his code is in .py files.

I made this work as best I could, but sometimes there were
authorial decisions that I do not feel comfortable making.
The code just doesn't run in those spots. Sometimes I left
the code in markdown cells rather than putting it in code
cells, and then imported the class from the .py file. I kind
of figured this out as I proceeded, so perhaps there are
stylistic differences in the back vs the front of the book.

He generates many graphs, but does not supply the source code.
Maybe the code is in the /code subdirectory? In a few places
I took the liberty of supplying the Python, but in many places
I did not. Maybe somebody else will feel like doing that;
I don't really have time right now. Pull requests accepted!

There are several places in the text where it was not clear
to me where he got his datasets. Rather than making something
up, I just let the code cells fail to execute. I hope Allen
will help me rectify these situations. If not, and there is
enough interest, we can make some decisions and get the cells
working.

I put his code in a /code subdirectory. I did not fix the references
in the book, which specify going to his home page to get the code.
Again, I wanted to make as few editorial decisions as possible.

I did alter most of the code to work with Python 3. Mainly by using

from __future__ import print_function

but in a few places I had to fix things like removing `xrange` or
`iterkeys()`. I only did just enough work to get it working.


His original README is:

https://github.com/AllenDowney/ThinkBayes

Code repository for Think Bayes: Bayesian Statistics Made Simple
by Allen B. Downey

Expand Down
47 changes: 47 additions & 0 deletions code/538.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"lines.linewidth": 2.0,
"patch.linewidth": 0.5,
"legend.fancybox": true,
"axes.color_cycle": [
"#6d904f",
"#013afe",
"#202020",
"#fc4f30",
"#e5ae38",
"#A60628",
"#30a2da",
"#008080",
"#7A68A6",
"#CF4457",
"#188487",
"#E24A33"
],
"axes.facecolor": "#ffffff",
"axes.labelsize": "large",
"axes.axisbelow": true,
"axes.grid": true,
"patch.edgecolor": "#f0f0f0",
"axes.titlesize": "x-large",
"examples.directory": "",
"figure.facecolor": "#ffffff",
"grid.linestyle": "-",
"grid.linewidth": 2.0,
"grid.color": "#cbcbcb",
"axes.edgecolor":"#f0f0f0",
"xtick.major.size": 0,
"xtick.minor.size": 0,
"ytick.major.size": 0,
"ytick.minor.size": 0,
"axes.linewidth": 3.0,
"font.size":14.0,
"lines.linewidth": 3,
"lines.solid_capstyle": "butt",
"savefig.edgecolor": "#f0f0f0",
"savefig.facecolor": "#f0f0f0",
"figure.subplot.left" : 0.08,
"figure.subplot.right" : 0.95,
"figure.subplot.bottom" : 0.07,
"figure.subplot.hspace" : 0.5,
"legend.scatterpoints" : 1
}

99 changes: 99 additions & 0 deletions code/book_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
# -*- coding: utf-8 -*-

"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)

from contextlib import contextmanager
from IPython.core.display import HTML
import json
import matplotlib.pylab as pylab
import matplotlib.pyplot as plt
import numpy as np
import os.path
import sys
import warnings

# recent matplotlibs are raising deprecation warnings that
# we don't worry about.
warnings.filterwarnings("ignore")


sys.path.insert(0, './code') # allow us to import book_format


def equal_axis():
pylab.rcParams['figure.figsize'] = 10,10
plt.axis('equal')


def reset_axis():
pylab.rcParams['figure.figsize'] = 11, 4

def set_figsize(x=11, y=4):
pylab.rcParams['figure.figsize'] = x, y


@contextmanager
def figsize(x=11, y=4):
"""Temporarily set the figure size using 'with figsize(a,b):'"""

size = pylab.rcParams['figure.figsize']
set_figsize(x, y)
yield
pylab.rcParams['figure.figsize'] = size

@contextmanager
def numpy_precision(precision):
old = np.get_printoptions()['precision']
np.set_printoptions(precision=precision)
yield
np.set_printoptions(old)

@contextmanager
def printoptions(*args, **kwargs):
original = np.get_printoptions()
np.set_printoptions(*args, **kwargs)
yield
np.set_printoptions(**original)

def _decode_list(data):
rv = []
for item in data:
if isinstance(item, unicode):
item = item.encode('utf-8')
elif isinstance(item, list):
item = _decode_list(item)
elif isinstance(item, dict):
item = _decode_dict(item)
rv.append(item)
return rv

def _decode_dict(data):
rv = {}
for key, value in data.iteritems():
if isinstance(key, unicode):
key = key.encode('utf-8')
if isinstance(value, unicode):
value = value.encode('utf-8')
elif isinstance(value, list):
value = _decode_list(value)
elif isinstance(value, dict):
value = _decode_dict(value)
rv[key] = value
return rv


def load_style(directory = '.', name='custom.css'):
if sys.version_info[0] >= 3:
s = json.load(open(os.path.join(directory, "538.json")))
else:
s = json.load(open(directory + "538.json"), object_hook=_decode_dict)
plt.rcParams.update(s)
reset_axis ()
np.set_printoptions(suppress=True)

styles = open(os.path.join(directory, name), 'r').read()
return HTML(styles)
4 changes: 3 additions & 1 deletion code/columns.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

"""This file contains code related to "Think Stats",
by Allen B. Downey, available from greenteapress.com

Expand Down Expand Up @@ -47,7 +49,7 @@ def print_cols(cols):
cols: list of columns
"""
for i, col in enumerate(cols):
print i, col[0], col[1]
print(i, col[0], col[1])


def make_col_dict(cols, names):
Expand Down
Loading