Skip to content
This repository was archived by the owner on Jul 10, 2021. It is now read-only.

Commit 8e4ab8d

Browse files
author
Team AiGameDev.com
committed
Restructuring the documentation to make beginner and advanced examples more obvious in TOC, adding details about GridSearch usage.
1 parent 5199aa1 commit 8e4ab8d

File tree

5 files changed

+114
-85
lines changed

5 files changed

+114
-85
lines changed

docs/guide_advanced.rst

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Advanced Usage
2+
==============
3+
4+
The examples in this section help you get more out of ``scikit-neuralnetwork`` via integration or configuration of the other libraries it works with, such as Theano or scikit-learn.
5+
6+
7+
GPU Backend
8+
-----------
9+
10+
To setup the library to use your GPU or CPU explicitly in 32-bit or 64-bit mode, you can use the ``backend`` pseudo-module. It's a syntactic helper to setup ``THEANO_FLAGS`` in a Pythonic way, for example:
11+
12+
.. code:: python
13+
14+
# Use the GPU in 32-bit mode, falling back otherwise.
15+
from sknn.backend import gpu32
16+
17+
# Use the CPU in 64-bit mode.
18+
from sknn.backend import cpu64
19+
20+
21+
WARNING: This will only work if your program has not yet imported the ``theano`` module, due to the way the library is designed. If ``THEANO_FLAGS`` are set on the command-line, they are not overwridden.
22+
23+
24+
25+
Pipeline
26+
--------
27+
28+
Typically, neural networks perform better when their inputs have been normalized or standardized. Using a scikit-learn's `pipeline <http://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html>`_ support is an obvious choice to do this.
29+
30+
Here's how to setup such a pipeline with a multi-layer perceptron as a classifier:
31+
32+
.. code:: python
33+
34+
from sknn.mlp improt Classifier, Layer
35+
36+
from sklearn.pipeline import Pipeline
37+
from sklearn.preprocessing import MinMaxScaler
38+
39+
pipeline = Pipeline([
40+
('min/max scaler', MinMaxScaler(feature_range=(0.0, 1.0))),
41+
('neural network', Classifier(layers=[Layer("Softmax")], n_iter=25))])
42+
pipeline.fit(X_train, y_train)
43+
44+
You can then use the pipeline as you would the neural network, or any other standard API from scikit-learn.
45+
46+
47+
48+
Grid Search
49+
-----------
50+
51+
In scikit-learn, you can use a ``GridSearchCV`` to optimize your neural network's parameters automatically, both the top-level parameters and the parameters within the layers. For example, assuming you have your MLP constructed as in the :ref:`Regression` example in the local variable called ``nn``, the layers are named automatically so you can refer to them as follows:
52+
53+
* ``hidden0``
54+
* ``hidden1``
55+
* ...
56+
* ``output2``
57+
58+
Keep in mind you can manually specify the ``name`` of any ``Layer`` in the constructor if you don't want the automatically assigned name. Then, you can use sklearn's hierarchical parameters to perform a grid search over those nested parameters too:
59+
60+
.. code:: python
61+
62+
from sklearn.grid_search import GridSearchCV
63+
64+
gs = GridSearchCV(nn, param_grid={
65+
learning_rate: [0.05, 0.01, 0.005, 0.001],
66+
'hidden0__units': [4, 8, 12],
67+
'hidden0__type': ["Rectifier", "Sigmoid", "Tanh"]})
68+
gs.fit(a_in, a_out)
69+
70+
This will search through the listed ``learning_rate`` values, the number of hidden units and the activation type for that layer too, and find the best combination of parameters.

docs/guide.rst renamed to docs/guide_beginners.rst

+2-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
User Guide
2-
==========
1+
Simple Examples
2+
===============
33

44
Regression
55
----------
@@ -106,42 +106,3 @@ Working with images as inputs in 2D (as greyscale) or 3D (as RGB) images stored
106106
nn.fit(X_train, y_train)
107107
108108
The neural network here is trained with eight kernels of shared weights in a ``3x3`` matrix, each outputting to its own channel. The rest of the code remains the same, but see the :class:`sknn.mlp.Layer` documentation for supported convolution layer types and parameters.
109-
110-
111-
Pipeline
112-
--------
113-
114-
Typically, neural networks perform better when their inputs have been normalized or standardized. Using a scikit-learn's `pipeline <http://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html>`_ support is an obvious choice to do this.
115-
116-
Here's how to setup such a pipeline with a multi-layer perceptron as a classifier:
117-
118-
.. code:: python
119-
120-
from sknn.mlp improt Classifier, Layer
121-
122-
from sklearn.pipeline import Pipeline
123-
from sklearn.preprocessing import MinMaxScaler
124-
125-
pipeline = Pipeline([
126-
('min/max scaler', MinMaxScaler(feature_range=(0.0, 1.0))),
127-
('neural network', Classifier(layers=[Layer("Softmax")], n_iter=25))])
128-
pipeline.fit(X_train, y_train)
129-
130-
You can thes use the pipeline as you would the neural network, or any other standard API from scikit-learn.
131-
132-
133-
GPU Backend
134-
-----------
135-
136-
To setup the library to use your GPU or CPU explicitly in 32-bit or 64-bit mode, you can use the ``backend`` pseudo-module. It's a syntactic helper to setup ``THEANO_FLAGS`` in a Pythonic way, for example:
137-
138-
.. code:: python
139-
140-
# Use the GPU in 32-bit mode, falling back otherwise.
141-
from sknn.backend import gpu32
142-
143-
# Use the CPU in 64-bit mode.
144-
from sknn.backend import cpu64
145-
146-
147-
WARNING: This will only work if your program has not yet imported the ``theano`` module, due to the way the library is designed. If ``THEANO_FLAGS`` are set on the command-line, they are not overwridden.

docs/guide_start.rst

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Installation
2+
============
3+
4+
Downloading Package
5+
-------------------
6+
7+
To download and setup the last officially released package, you can do so from PYPI directly::
8+
9+
> pip install scikit-neuralnetwork
10+
11+
This contains its own packaged version of ``pylearn2`` from the date of the release (and tag) but will use any globally installed version if available.
12+
13+
If you want to install the very latest from source, please visit the `Project Page <https://github.com/aigamedev/scikit-neuralnetwork>`_ on GitHub for details.
14+
15+
16+
Running Tests
17+
-------------
18+
19+
We encourage you to launch the tests to check everything is working using the following commands::
20+
21+
> pip install nose
22+
> nosetests -v sknn
23+
24+
Use the additional command-line parameters in the test runner ``--processes=8`` and ``--process-timeout=60`` to speed things up on powerful machines. The result should look as follows in your terminal.
25+
26+
.. image:: console_tests.png
27+
28+
We strive to maintain 100% test coverage for all code-paths, to ensure that rapid changes in the underlying ``pylearn2`` library are caught automatically.
29+

docs/index.rst

+10-41
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ Welcome to sknn's documentation!
33

44
Deep neural network implementation without the learning cliff! This library implements multi-layer perceptrons as a wrapper for the powerful ``pylearn2`` library that's compatible with ``scikit-learn`` for a more user-friendly and Pythonic interface.
55

6-
|Build Status| |Documentation Status| |Code Coverage| |License Type| |Source Code|
6+
|Build Status| |Code Coverage| |License Type| |Source Code|
77

88
----
99

10+
.. image:: plot_activation.png
11+
12+
1013
Module Reference
1114
----------------
1215

@@ -16,46 +19,15 @@ Module Reference
1619
mlp
1720

1821

19-
Installation
20-
------------
21-
22-
You'll need to first install some dependencies manually. Unfortunately, ``pylearn2`` isn't yet installable via PyPI and recommends an editable (``pip -e``) installation::
23-
24-
> pip install numpy scipy theano
25-
> pip install -e git+https://github.com/lisa-lab/pylearn2.git#egg=Package
26-
27-
Once that's done, you can grab this repository and install from ``setup.py`` in the exact same way::
28-
29-
> git clone https://github.com/aigamedev/scikit-neuralnetwork.git
30-
> cd scikit-neuralnetwork; python setup.py develop
31-
32-
Then, you can run the samples and benchmarks available in the ``examples/`` folder.
33-
34-
35-
Running Tests
36-
-------------
37-
38-
We encourage you to launch the tests to check everything is working using the following commands::
39-
40-
> pip install nose
41-
> nosetests -v sknn
42-
43-
Use the additional command-line parameters in the test runner ``--processes=8`` and ``--process-timeout=60`` to speed things up on powerful machines. The result should look as follows in your terminal.
44-
45-
.. image:: console_tests.png
46-
47-
We strive to maintain 100% test coverage for all code-paths, to ensure that rapid changes in the underlying ``pylearn2`` library are caught automatically.
48-
49-
50-
Getting Started
51-
---------------
22+
User Guide
23+
----------
5224

5325
.. toctree::
5426
:maxdepth: 2
5527

56-
guide
57-
58-
.. image:: plot_activation.png
28+
guide_start
29+
guide_beginners
30+
guide_advanced
5931

6032

6133
Indices & Search
@@ -67,14 +39,11 @@ Indices & Search
6739

6840
----
6941

70-
|Build Status| |Documentation Status| |Code Coverage| |License Type| |Source Code|
42+
|Build Status| |Code Coverage| |License Type| |Source Code|
7143

7244
.. |Build Status| image:: https://travis-ci.org/aigamedev/scikit-neuralnetwork.svg?branch=master
7345
:target: https://travis-ci.org/aigamedev/scikit-neuralnetwork
7446

75-
.. |Documentation Status| image:: https://readthedocs.org/projects/scikit-neuralnetwork/badge/?version=latest
76-
:target: http://scikit-neuralnetwork.readthedocs.org/
77-
7847
.. |Code Coverage| image:: https://coveralls.io/repos/aigamedev/scikit-neuralnetwork/badge.svg?branch=master
7948
:target: https://coveralls.io/r/aigamedev/scikit-neuralnetwork?branch=master
8049

docs/pypi.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ Thanks to the underlying ``pylearn2`` implementation, this library supports the
2525
If a feature you need is missing, consider opening a `GitHub Issue <https://github.com/aigamedev/scikit-neuralnetwork/issues>`_ with a detailed explanation about the use case and we'll see what we can do.
2626

2727

28-
Installation & Testing
29-
----------------------
28+
Installation
29+
------------
3030

3131
To download and setup the latest official release, you can do so from PYPI directly::
3232

3333
> pip install scikit-neuralnetwork
3434

3535
This contains its own packaged version of ``pylearn2`` from the date of the release (and tag) but will use any globally installed version if available.
3636

37-
Then, you can run the samples and benchmarks available in the ``examples/`` folder.
37+
Then, you can run the tests using ``nosetests -v sknn``, and other samples or benchmarks are available in the ``examples/`` folder.
3838

3939

4040
Getting Started

0 commit comments

Comments
 (0)