Completed
Push — master ( c8682f...5bbe2a )
by Raphael
01:33
created

deepy.layers.Maxout.prepare()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 5
rs 9.4286
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import theano.tensor as T
5
from . import NeuralLayer
6
7
class Maxout(NeuralLayer):
8
    """
9
    Maxout activation unit.
10
     - http://arxiv.org/pdf/1302.4389.pdf
11
    """
12
    def __init__(self, output_dim, num_pieces=4, init=None):
13
        """
14
        :param num_pieces: pieces of sub maps
15
        """
16
        super(Maxout, self).__init__("maxout")
17
        self.num_pieces = num_pieces
18
        self.output_dim = output_dim
19
        self.init = init
20
21
22
    def prepare(self):
23
        self.W = self.create_weight(shape=(self.num_pieces, self.input_dim, self.output_dim),
24
                                    initializer=self.init, suffix="maxout")
25
        self.B = self.create_bias(shape=(self.num_pieces, self.output_dim), suffix="maxout")
26
        self.register_parameters(self.W, self.B)
27
28
29
    def output(self, x):
30
        return T.max(T.dot(x, self.W) + self.B, axis=1)