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

Commit

Permalink
Cleaning up the code, adding tests for coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjc committed May 17, 2015
1 parent de28eb1 commit 37717b7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sknn/ae.py
Expand Up @@ -33,7 +33,7 @@ def __init__(self,
if type not in ['denoising', 'autoencoder']:
raise NotImplementedError("AutoEncoder layer type `%s` is not implemented." % type)
if cost not in ['msre', 'mbce']:
raise NotImplementedError("Error type '%s' is not implemented." % self.cost)
raise NotImplementedError("Error type '%s' is not implemented." % cost)

self.name = name
self.type = type
Expand Down
6 changes: 0 additions & 6 deletions sknn/mlp.py
Expand Up @@ -302,12 +302,6 @@ def is_initialized(self):
"""
return not (self.mlp is None or self.f is None)

@property
def is_convolution(self):
"""Check whether this neural network includes convolution layers.
"""
return isinstance(self.layers[0], Convolution)

def __getstate__(self):
assert self.mlp is not None,\
"The neural network has not been initialized."
Expand Down
9 changes: 5 additions & 4 deletions sknn/nn.py
Expand Up @@ -410,20 +410,21 @@ def __init__(
self._setup()

def _setup(self):
raise NotImplementedError("MultiLayerPerceptron is an abstract class; "
"use the Classifier or Regressor instead.")
raise NotImplementedError("NeuralNetwork is an abstract class; "
"use the mlp.Classifier or mlp.Regressor instead.")

@property
def is_initialized(self):
"""Check if the neural network was setup already.
"""
return None # not (self.mlp is None or self.f is None)
raise NotImplementedError("NeuralNetwork is an abstract class; "
"use the mlp.Classifier or mlp.Regressor instead.")

@property
def is_convolution(self):
"""Check whether this neural network includes convolution layers.
"""
return False
return isinstance(self.layers[0], Convolution)

def _create_matrix_input(self, X, y=None):
if self.is_convolution:
Expand Down
20 changes: 18 additions & 2 deletions sknn/tests/test_ae.py
@@ -1,6 +1,5 @@
import unittest
from nose.tools import (assert_false, assert_raises, assert_true,
assert_equal, assert_in)
from nose.tools import (assert_raises)

import numpy

Expand All @@ -17,3 +16,20 @@ def test_FitData(self):
X = numpy.zeros((8,4))
ae = AE(layers=[L("Sigmoid", units=8)], n_iter=1)
ae.fit(X)


class TestParameters(unittest.TestCase):

def test_CostFunctions(self):
for t in ['msre', 'mbce']:
AE(layers=[L("Sigmoid", units=8, cost=t)])

def test_LayerTypes(self):
for l in ['autoencoder', 'denoising']:
AE(layers=[L("Sigmoid", type=l, units=8)])

def test_UnknownCostFunction(self):
assert_raises(NotImplementedError, L, "Sigmoid", cost="unknown")

def test_UnknownType(self):
assert_raises(NotImplementedError, L, "Sigmoid", type="unknown")
13 changes: 13 additions & 0 deletions sknn/tests/test_nn.py
@@ -0,0 +1,13 @@
import unittest
from nose.tools import (assert_raises)

from sknn.nn import NeuralNetwork as NN


class TestAbstractNeuralNetwork(unittest.TestCase):

def test_SetupRaisesException(self):
assert_raises(NotImplementedError, NN, layers=[])

def test_IsInitializedRaisesExecption(self):
assert_raises(NotImplementedError, NN.is_initialized.fget, object())

0 comments on commit 37717b7

Please sign in to comment.