Skip to content

Commit

Permalink
- use the sphinx-gallery extension (https://github.com/sphinx-gallery…
Browse files Browse the repository at this point in the history
…/sphinx-gallery)) in the doc

- make the examples compatible with sphinx-gallery (https://github.com/sphinx-gallery/sphinx-gallery)
- fix a dead link in xkcdify.py
- move examples/pyearth_vs_earth.py to benchmark/
  • Loading branch information
mehdidc committed May 1, 2015
1 parent 3d97777 commit b044586
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 45 deletions.
File renamed without changes.
7 changes: 7 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ help:

clean:
-rm -rf $(BUILDDIR)/*
rm -rf auto_examples/
rm -rf modules/generated/*

html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
Expand Down Expand Up @@ -151,3 +153,8 @@ doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

html-noplot:
$(SPHINXBUILD) -D plot_gallery=0 -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
8 changes: 5 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# Create the figures
import generate_figures

import sphinxgallery

# -- General configuration -----------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand All @@ -35,7 +37,7 @@
extensions = ['sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage',
'sphinx.ext.pngmath', 'sphinx.ext.mathjax', 'sphinx.ext.ifconfig',
'sphinx.ext.viewcode', 'sphinx.ext.autodoc', 'numpydoc', 'sphinx.ext.autosummary',
'sphinxcontrib.bibtex']
'sphinxcontrib.bibtex', 'sphinxgallery.gen_gallery']

autosummary_generate = True
numpydoc_show_class_members = False
Expand Down Expand Up @@ -107,7 +109,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -136,7 +138,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static', sphinxgallery.path_static()]

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
Expand Down
4 changes: 2 additions & 2 deletions doc/generate_figures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


import matplotlib as mpl
mpl.use('Agg')
import numpy
from pyearth import Earth
from matplotlib import pyplot
Expand Down
2 changes: 1 addition & 1 deletion doc/xkcdify.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import os
import urllib2
if not os.path.exists('Humor-Sans.ttf'):
fhandle = urllib2.urlopen('http://antiyawn.com/uploads/Humor-Sans.ttf')
fhandle = urllib2.urlopen('https://github.com/shreyankg/xkcd-desktop/raw/master/Humor-Sans.ttf')
open('Humor-Sans.ttf', 'wb').write(fhandle.read())


Expand Down
1 change: 1 addition & 0 deletions examples/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the gallery of examples.
27 changes: 15 additions & 12 deletions examples/classifier_comp.py → examples/plot_classifier_comp.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
'''
This script recreates the scikit-learn classifier comparison example found at http://scikit-learn.org/dev/auto_examples/plot_classifier_comparison.html.
It has been modified to include an Earth based classifier.
'''
"""
===============================
Plotting sckit-learn classifiers comparison with Earth
===============================
This script recreates the scikit-learn classifier comparison example found at http://scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html.
It has been modified to include an Earth based classifier.
"""
# Code source: Gael Varoqueux
# Andreas Mueller
# Modified for Documentation merge by Jaques Grobler
# License: BSD 3 clause
# Modified to include pyearth by Jason Rudy

import numpy as np
import pylab as pl
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
Expand All @@ -25,10 +28,10 @@

h = .02 # step size in the mesh

from pyearth.earth import Earth
from sklearn.linear_model.logistic import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.pipeline import Pipeline
from pyearth.earth import Earth

np.random.seed(1)

Expand Down Expand Up @@ -60,7 +63,7 @@
linearly_separable
]

figure = pl.figure(figsize=(27, 9))
figure = plt.figure(figsize=(27, 9))
i = 1
# iterate over datasets
for ds in datasets:
Expand All @@ -75,9 +78,9 @@
np.arange(y_min, y_max, h))

# just plot the dataset first
cm = pl.cm.RdBu
cm = plt.cm.RdBu
cm_bright = ListedColormap(['#FF0000', '#0000FF'])
ax = pl.subplot(len(datasets), len(classifiers) + 1, i)
ax = plt.subplot(len(datasets), len(classifiers) + 1, i)
# Plot the training points
ax.scatter(X_train[:, 0], X_train[:, 1], c=y_train, cmap=cm_bright)
# and testing points
Expand All @@ -90,7 +93,7 @@

# iterate over classifiers
for name, clf in zip(names, classifiers):
ax = pl.subplot(len(datasets), len(classifiers) + 1, i)
ax = plt.subplot(len(datasets), len(classifiers) + 1, i)
clf.fit(X_train, y_train)
score = clf.score(X_test, y_test)

Expand Down Expand Up @@ -121,5 +124,5 @@
i += 1

figure.subplots_adjust(left=.02, right=.98)
pl.savefig('classifier_comp.pdf', transparent=True)
pl.show()
plt.savefig('classifier_comp.pdf', transparent=True)
plt.show()
35 changes: 22 additions & 13 deletions examples/derivatives.py → examples/plot_derivatives.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""
===============================
Plotting derivatives of simple sine function
===============================
A simple example plotting a fit of the sine function and
the derivatives computed by Earth.
"""
import numpy
import matplotlib.pyplot as plt

from pyearth import Earth
from matplotlib import pyplot

# Create some fake data
numpy.random.seed(2)
Expand All @@ -9,7 +18,7 @@
X = 20 * numpy.random.uniform(size=(m, n)) - 10
y = 10*numpy.sin(X[:, 6]) + \
0.25*numpy.random.normal(size=m)

# Compute the known true derivative with respect to the predictive variable
y_prime = 10*numpy.cos(X[:, 6])

Expand All @@ -18,20 +27,20 @@
model.fit(X, y)

# Print the model
print model.trace()
print model.summary()
print(model.trace())
print(model.summary())

# Get the predicted values and derivatives
y_hat = model.predict(X)
y_prime_hat = model.predict_deriv(X, 'x6')

# Plot true and predicted function values and derivatives for the predictive variable
pyplot.subplot(211)
pyplot.plot(X[:, 6], y, 'r.')
pyplot.plot(X[:, 6], y_hat, 'b.')
pyplot.ylabel('function')
pyplot.subplot(212)
pyplot.plot(X[:, 6], y_prime, 'r.')
pyplot.plot(X[:, 6], y_prime_hat[:,0], 'b.')
pyplot.ylabel('derivative')
pyplot.show()
plt.subplot(211)
plt.plot(X[:, 6], y, 'r.')
plt.plot(X[:, 6], y_hat, 'b.')
plt.ylabel('function')
plt.subplot(212)
plt.plot(X[:, 6], y_prime, 'r.')
plt.plot(X[:, 6], y_prime_hat[:,0], 'b.')
plt.ylabel('derivative')
plt.show()
20 changes: 13 additions & 7 deletions examples/sine_wave.py → examples/plot_sine_wave.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
"""
===============================
Plotting simple sine function
===============================
A simple example plotting a fit of the sine function.
"""
import numpy
import matplotlib.pyplot as plt

from pyearth import Earth
from matplotlib import pyplot

# Create some fake data
numpy.random.seed(2)
Expand All @@ -17,12 +24,11 @@
model.fit(X, y)

# Print the model
print model.trace()
print model.summary()
print(model.trace())
print(model.summary())

# Plot the model
y_hat = model.predict(X)
pyplot.figure()
pyplot.plot(X[:, 6], y, 'r.')
pyplot.plot(X[:, 6], y_hat, 'b.')
pyplot.show()
plt.plot(X[:, 6], y, 'r.')
plt.plot(X[:, 6], y_hat, 'b.')
plt.show()
21 changes: 14 additions & 7 deletions examples/v_function.py → examples/plot_v_function.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""
===============================
Plotting the absolute value function
===============================
A simple example plotting a fit of the absolute value function.
"""

import numpy
from matplotlib import pyplot
import matplotlib.pyplot as plt

from pyearth import Earth

Expand All @@ -16,12 +23,12 @@
model.fit(X, y)

# Print the model
print model.trace()
print model.summary()
print(model.trace())
print(model.summary())

# Plot the model
y_hat = model.predict(X)
pyplot.figure()
pyplot.plot(X[:, 6], y, 'r.')
pyplot.plot(X[:, 6], y_hat, 'b.')
pyplot.show()
plt.figure()
plt.plot(X[:, 6], y, 'r.')
plt.plot(X[:, 6], y_hat, 'b.')
plt.show()

0 comments on commit b044586

Please sign in to comment.