Ejemplo n.º 1
0
class MLPClassifier(Theanifiable):
    def __init__(self, D, H, C, n_layers):
        super(MLPClassifier, self).__init__()
        self.mlp = MultilayerPerceptron("mlp", D, H, C, n_layers=n_layers)
        self.compile_method("errors")

    @theanify(T.matrix("X"), T.ivector("y"))
    def cost(self, X, y):
        ypred = self.mlp.forward(X)
        return T.nnet.categorical_crossentropy(ypred, y).mean()

    @theanify(T.matrix("X"), T.ivector("y"))
    def errors(self, X, y):
        y_pred = self.mlp.forward(X).argmax(axis=1)
        return T.mean(T.neq(y_pred, y))

    def get_parameters(self):
        return self.mlp.get_parameters()
Ejemplo n.º 2
0
 def __init__(self, D, H, C, n_layers):
     super(MLPClassifier, self).__init__()
     self.mlp = MultilayerPerceptron("mlp", D, H, C, n_layers=n_layers)
     self.compile_method("errors")