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

Commit

Permalink
Re-enabled one missing test, reworked some code for coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjc committed Nov 17, 2015
1 parent 9e561ff commit b673aef
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion sknn/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def __init__(self, _):
# Automatically import the recommended backend if none was manually imported.
def setup():
if name == None:
from . import lasagne
from . import pylearn2
assert name is not None, "No backend for module sknn was imported."
12 changes: 12 additions & 0 deletions sknn/backend/pylearn2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, unicode_literals, print_function)

from ...nn import ansi


import warnings
warnings.warn(ansi.YELLOW + """\n
The PyLearn2 backend is deprecated; the next release will switch to Lasagne by default.
Test the change using the following at the top of your script:
> from sknn.backend import lasagne
""" + ansi.ENDC, category=UserWarning)


from ... import backend
from .mlp import MultiLayerPerceptronBackend
from .ae import AutoEncoderBackend
Expand Down
16 changes: 1 addition & 15 deletions sknn/backend/pylearn2/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _mutate_fn(self, array):
array = self._conv_fn(array)
if self.mutator is not None:
for i in range(array.shape[0]):
self.mutator(array[i])
array[i] = self.mutator(array[i])
return array

@functools.wraps(dataset.Dataset.iterator)
Expand Down Expand Up @@ -160,17 +160,3 @@ def iterator(self, **kwargs):
if self.mutator is not None:
bit._convert[0] = self._conv_fn
return bit

"""
OriginalDatasetIterator = iteration.FiniteDatasetIterator
def create_finite_iterator(*args, **kwargs):
print('create_finite_iterator', kwargs['convert'])
def conv_fn(x):
return x + 0.01
kwargs['convert'] = [conv_fn, None]
return OriginalDatasetIterator(*args, **kwargs)
# convert=convert)
datasets.dense_design_matrix.FiniteDatasetIterator = create_finite_iterator
"""
4 changes: 2 additions & 2 deletions sknn/backend/pylearn2/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ def _train_impl(self, X, y):
X = self.ds.view_converter.topo_view_to_design_mat(X)
self.ds.X, self.ds.y = X, y

self._train_layer(self.trainer, self.mlp, self.ds)
return self._train_layer(self.trainer, self.mlp, self.ds)

def _valid_impl(self, X, y):
self._valid_layer(self.mlp)
return self._valid_layer(self.mlp)

@property
def is_initialized(self):
Expand Down
9 changes: 3 additions & 6 deletions sknn/backend/pylearn2/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ def _train_layer(self, trainer, layer, dataset):
def _valid_layer(self, layer):
layer.monitor.report_epoch()
layer.monitor()


# 'objective' channel is only defined with validation set.
objective = layer.monitor.channels.get('objective', None)
if objective:
return objective.val_shared.get_value()
else:
# 'objective' channel is only defined with validation set.
return None
return objective.val_shared.get_value() if objective else None
4 changes: 2 additions & 2 deletions sknn/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def test_FitHybrid(self):
y = numpy.zeros((8, 4), dtype=numpy.float32)
self.nn._fit(X, y)

def __test_FitMutator(self):
def test_FitMutator(self):
def mutate(x):
x -= 0.5
self.count += 1
return x - 0.5
self.nn.mutator = mutate

for t in SPARSE_TYPES:
Expand Down

0 comments on commit b673aef

Please sign in to comment.