diff --git a/sknn/ae.py b/sknn/ae.py index 8884b4b..1c16e57 100644 --- a/sknn/ae.py +++ b/sknn/ae.py @@ -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 diff --git a/sknn/mlp.py b/sknn/mlp.py index 2d56e4e..881445a 100644 --- a/sknn/mlp.py +++ b/sknn/mlp.py @@ -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." diff --git a/sknn/nn.py b/sknn/nn.py index e09e9b1..112d15c 100644 --- a/sknn/nn.py +++ b/sknn/nn.py @@ -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: diff --git a/sknn/tests/test_ae.py b/sknn/tests/test_ae.py index 2806fc3..0c7f44b 100644 --- a/sknn/tests/test_ae.py +++ b/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 @@ -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") diff --git a/sknn/tests/test_nn.py b/sknn/tests/test_nn.py new file mode 100644 index 0000000..0af5799 --- /dev/null +++ b/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())