From f439f777084690ecbf54bcd8d67dadc883fffa31 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Fri, 2 Dec 2016 12:49:38 +0100 Subject: [PATCH] first attempt to support sphinx-gallery --- docs/source/conf.py | 30 +++++++++++++------ docs/source/index.rst | 2 +- examples/{demo_OTDA_2D.py => plot_OTDA_2D.py} | 3 ++ ...o_OTDA_classes.py => plot_OTDA_classes.py} | 3 ++ ...or_images.py => plot_OTDA_color_images.py} | 2 ++ ...o_OTDA_mapping.py => plot_OTDA_mapping.py} | 7 ++--- ...s.py => plot_OTDA_mapping_color_images.py} | 3 +- examples/{demo_OT_1D.py => plot_OT_1D.py} | 2 ++ ...OT_2D_samples.py => plot_OT_2D_samples.py} | 2 -- ...barycenter_1D.py => plot_barycenter_1D.py} | 0 ...emo_optim_OTreg.py => plot_optim_OTreg.py} | 0 requirements.txt | 1 + 12 files changed, 37 insertions(+), 18 deletions(-) rename examples/{demo_OTDA_2D.py => plot_OTDA_2D.py} (96%) rename examples/{demo_OTDA_classes.py => plot_OTDA_classes.py} (96%) rename examples/{demo_OTDA_color_images.py => plot_OTDA_color_images.py} (93%) rename examples/{demo_OTDA_mapping.py => plot_OTDA_mapping.py} (96%) rename examples/{demo_OTDA_mapping_color_images.py => plot_OTDA_mapping_color_images.py} (93%) rename examples/{demo_OT_1D.py => plot_OT_1D.py} (93%) rename examples/{demo_OT_2D_samples.py => plot_OT_2D_samples.py} (99%) rename examples/{demo_barycenter_1D.py => plot_barycenter_1D.py} (100%) rename examples/{demo_optim_OTreg.py => plot_optim_OTreg.py} (100%) diff --git a/docs/source/conf.py b/docs/source/conf.py index f48a868c0..61505cc4a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -15,23 +15,25 @@ import sys import os import re +import sphinx_gallery + #try: -from unittest.mock import MagicMock +# from unittest.mock import MagicMock #except ImportError: # from mock import MagicMock -sys.path.insert(0, os.path.abspath("../..")) +# sys.path.insert(0, os.path.abspath("../..")) #sys.setrecursionlimit(1500) -class Mock(MagicMock): - @classmethod - def __getattr__(cls, name): - return Mock() +# class Mock(MagicMock): +# @classmethod +# def __getattr__(cls, name): +# return Mock() -MOCK_MODULES = [ 'emd','ot.lp.emd'] -sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) +# MOCK_MODULES = [ 'emd','ot.lp.emd'] +# sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -54,7 +56,9 @@ def __getattr__(cls, name): 'sphinx.ext.coverage', 'sphinx.ext.mathjax', 'sphinx.ext.ifconfig', - 'sphinx.ext.viewcode', 'sphinx.ext.napoleon' + 'sphinx.ext.viewcode', + 'sphinx.ext.napoleon', + 'sphinx_gallery.gen_gallery', ] # Add any paths that contain templates here, relative to this directory. @@ -316,3 +320,11 @@ def __getattr__(cls, name): # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'https://docs.python.org/': None} + +sphinx_gallery_conf = { + 'examples_dirs': '../../examples', + 'gallery_dirs': 'auto_examples', + 'reference_url': { + 'numpy': 'http://docs.scipy.org/doc/numpy-1.9.1', + 'scipy': 'http://docs.scipy.org/doc/scipy-0.17.0/reference'} +} diff --git a/docs/source/index.rst b/docs/source/index.rst index 024c4e9f4..e3c4d3643 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -14,7 +14,7 @@ Contents self all - examples + auto_examples .. include:: readme.rst :start-line: 6 diff --git a/examples/demo_OTDA_2D.py b/examples/plot_OTDA_2D.py similarity index 96% rename from examples/demo_OTDA_2D.py rename to examples/plot_OTDA_2D.py index fbaf56d6e..db04c5ea7 100644 --- a/examples/demo_OTDA_2D.py +++ b/examples/plot_OTDA_2D.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- """ +=============================================== demo of Optimal transport for domain adaptation +=============================================== + """ import numpy as np diff --git a/examples/demo_OTDA_classes.py b/examples/plot_OTDA_classes.py similarity index 96% rename from examples/demo_OTDA_classes.py rename to examples/plot_OTDA_classes.py index b2da7dead..999be5367 100644 --- a/examples/demo_OTDA_classes.py +++ b/examples/plot_OTDA_classes.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- """ +=============================================== demo of Optimal transport for domain adaptation +=============================================== + """ import matplotlib.pylab as pl diff --git a/examples/demo_OTDA_color_images.py b/examples/plot_OTDA_color_images.py similarity index 93% rename from examples/demo_OTDA_color_images.py rename to examples/plot_OTDA_color_images.py index 715707d0f..7ddaa2b37 100644 --- a/examples/demo_OTDA_color_images.py +++ b/examples/plot_OTDA_color_images.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """ +===================================================================================== Demo of Optimal transport for domain adaptation with image color adaptation as in [6] +===================================================================================== [6] Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882. """ diff --git a/examples/demo_OTDA_mapping.py b/examples/plot_OTDA_mapping.py similarity index 96% rename from examples/demo_OTDA_mapping.py rename to examples/plot_OTDA_mapping.py index 50c1df2b1..779fa765f 100644 --- a/examples/demo_OTDA_mapping.py +++ b/examples/plot_OTDA_mapping.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """ +======================================================= Demo of OT mapping estimation for domain adaptation [8] +======================================================= [8] M. Perrot, N. Courty, R. Flamary, A. Habrard, "Mapping estimation for discrete optimal transport", Neural Information Processing Systems (NIPS), 2016. @@ -106,8 +108,3 @@ pl.scatter(xt[:,0],xt[:,1],c=yt,marker='o',label='Target samples',alpha=.2) pl.scatter(xst_kernel[:,0],xst_kernel[:,1],c=ys,marker='+',label='Learned mapping') pl.title("Estim. mapping (kernel)") - - - - - diff --git a/examples/demo_OTDA_mapping_color_images.py b/examples/plot_OTDA_mapping_color_images.py similarity index 93% rename from examples/demo_OTDA_mapping_color_images.py rename to examples/plot_OTDA_mapping_color_images.py index 2744f6cbf..0cd6c9cb8 100644 --- a/examples/demo_OTDA_mapping_color_images.py +++ b/examples/plot_OTDA_mapping_color_images.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- """ +====================================================================================================================== Demo of Optimal transport for domain adaptation with image color adaptation as in [6] with mapping estimation from [8] +====================================================================================================================== [6] Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882. [8] M. Perrot, N. Courty, R. Flamary, A. Habrard, "Mapping estimation for discrete optimal transport", Neural Information Processing Systems (NIPS), 2016. - """ import numpy as np diff --git a/examples/demo_OT_1D.py b/examples/plot_OT_1D.py similarity index 93% rename from examples/demo_OT_1D.py rename to examples/plot_OT_1D.py index df65a60d2..a8bbbd6de 100644 --- a/examples/demo_OT_1D.py +++ b/examples/plot_OT_1D.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """ +============================= Demo for 1D optimal transport +============================= @author: rflamary """ diff --git a/examples/demo_OT_2D_samples.py b/examples/plot_OT_2D_samples.py similarity index 99% rename from examples/demo_OT_2D_samples.py rename to examples/plot_OT_2D_samples.py index e9ec78a38..e55eff8c4 100644 --- a/examples/demo_OT_2D_samples.py +++ b/examples/plot_OT_2D_samples.py @@ -74,5 +74,3 @@ pl.plot(xt[:,0],xt[:,1],'xr',label='Target samples') pl.legend(loc=0) pl.title('OT matrix Sinkhorn with samples') - - diff --git a/examples/demo_barycenter_1D.py b/examples/plot_barycenter_1D.py similarity index 100% rename from examples/demo_barycenter_1D.py rename to examples/plot_barycenter_1D.py diff --git a/examples/demo_optim_OTreg.py b/examples/plot_optim_OTreg.py similarity index 100% rename from examples/demo_optim_OTreg.py rename to examples/plot_optim_OTreg.py diff --git a/requirements.txt b/requirements.txt index d7b38b039..319f5e17d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ numpy scipy cython matplotlib +sphinx-gallery