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

Commit

Permalink
Merge pull request #19 from aigamedev/params
Browse files Browse the repository at this point in the history
Construction from Layer specification objects.
  • Loading branch information
ssamot committed Apr 27, 2015
2 parents c638eef + fcc28a5 commit e0e2b89
Show file tree
Hide file tree
Showing 15 changed files with 411 additions and 160 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ The library supports both regressors (to estimate continuous outputs) and classi

.. code:: python
import sknn.mlp
from sknn import mlp
nn = sknn.mlp.MultiLayerPerceptronClassifier(
layers=[("Rectifier", 100), ("Linear",)],
nn = mlp.Classifier(
layers=[mlp.Layer("Rectifier", units=100), mlp.Layer("Linear")],
learning_rate=0.02,
n_iter=10)
nn.fit(X_train, y_train)
nn.predict(X_test)
nn.predict(X_valid)
nn.score(X_valid, y_valid)
nn.score(X_test, y_test)
We currently recommend reading ``sknn/mlp.py`` for more information about the parameters. There's also `generated documentation <http://scikit-neuralnetwork.readthedocs.org/>`_ as a standalone page.

Expand Down
10 changes: 5 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ The library supports both regressors (to estimate continuous outputs) and classi

.. code:: python
import sknn.mlp
from sknn import mlp
nn = sknn.mlp.MultiLayerPerceptronClassifier(
layers=[("Rectifier", 100), ("Linear",)],
nn = mlp.Classifier(
layers=[mlp.Layer("Rectifier", units=100), mlp.Layer("Linear")],
learning_rate=0.02,
n_iter=10)
nn.fit(X_train, y_train)
nn.predict(X_test)
nn.predict(X_valid)
nn.score(X_valid, y_valid)
nn.score(X_test, y_test)
You can also use a ``MultiLayerPerceptronRegressor`` in the exact same way. See the documentation in :mod:`sknn.mlp` for details about the construction parameters.

Expand Down
20 changes: 14 additions & 6 deletions examples/bench_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
import numpy as np

def load(name):
with open(name, 'rb') as f:
return cPickle.load(f)
try:
with open(name, 'rb') as f:
return cPickle.load(f)
except IOError:
import gzip
with gzip.open(name+'.gz', 'rb') as f:
return cPickle.load(f)

dataset1 = load('data_batch_1')
dataset2 = load('data_batch_2')
Expand All @@ -24,12 +29,15 @@ def load(name):
import logging
logging.basicConfig(format="%(message)s", level=logging.DEBUG, stream=sys.stdout)

from sknn.mlp import MultiLayerPerceptronClassifier
net = MultiLayerPerceptronClassifier(
[("Rectifier", n_feat*2/3), ("Rectifier", n_feat*1/3), ("Linear", n_targets)],
from sknn import mlp
net = mlp.Classifier(
layers=[
mlp.Layer("Rectifier", units=n_feat*2/3),
mlp.Layer("Rectifier", units=n_feat*1/3),
mlp.Layer("Softmax", units=n_targets)],
n_iter=50,
n_stable=10,
learning_rate=0.005,
learning_rate=0.001,
valid_size=0.1,
verbose=1)
net.fit(data_train, labels_train)
Expand Down
6 changes: 3 additions & 3 deletions examples/bench_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
classifiers.append(('nolearn.dbn', clf))

if 'sknn' in sys.argv:
from sknn.mlp import MultiLayerPerceptronClassifier
from sknn import mlp

clf = MultiLayerPerceptronClassifier(
layers=[("Rectifier", 300), ("Softmax",)],
clf = mlp.Classifier(
layers=[mlp.Layer("Rectifier", units=300), mlp.Layer("Softmax")],
learning_rate=0.02,
learning_rule='momentum',
batch_size=25,
Expand Down
14 changes: 10 additions & 4 deletions examples/plot_mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import sys
import time
import logging
import argparse
import itertools
import numpy as np
Expand All @@ -19,15 +20,19 @@
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_moons, make_circles, make_classification

from sknn.mlp import MultiLayerPerceptronClassifier
# The neural network uses the `sknn` logger to output its information.
import logging
logging.basicConfig(format="%(message)s", level=logging.WARNING, stream=sys.stdout)

from sknn import mlp

# All possible parameter options that can be plotted, separately or combined.
PARAMETERS = {
'activation': ['Rectifier', 'Tanh', 'Sigmoid', 'Maxout'],
'alpha': [0.001, 0.005, 0.01, 0.05, 0.1, 0.2],
'dropout': [False, True],
'iterations': [100, 200, 500, 1000],
'output': ['Linear', 'Softmax', 'LinearGaussian'],
'output': ['Softmax', 'Linear', 'Gaussian'],
'rules': ['sgd', 'momentum', 'nesterov', 'adadelta', 'rmsprop'],
'units': [16, 64, 128, 256],
}
Expand All @@ -53,8 +58,9 @@
names = []
classifiers = []
for (activation, alpha, dropout, iterations, output, rule, units) in itertools.product(*params):
classifiers.append(MultiLayerPerceptronClassifier(
layers=[(activation, units, 2), (output,)], random_state=1,
params = {'pieces': 2} if activation == "Maxout" else {}
classifiers.append(mlp.Classifier(
layers=[mlp.Layer(activation, units=units, **params), mlp.Layer(output)], random_state=1,
n_iter=iterations, n_stable=iterations,
dropout=dropout, learning_rule=rule, learning_rate=alpha),)

Expand Down

0 comments on commit e0e2b89

Please sign in to comment.