deepy.layers.Dropout.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from . import NeuralLayer
5
from deepy.utils import global_theano_rand, FLOATX
6
7
class Dropout(NeuralLayer):
8
9
    def __init__(self, p):
10
        super(Dropout, self).__init__("dropout")
11
        self.p = p
12
13
    def output(self, x):
14
        if self.p > 0:
15
            x *= global_theano_rand.binomial(x.shape, p=1-self.p, dtype=FLOATX)
16
        return x
17
18
    def test_output(self, x):
19
        if self.p > 0:
20
            x *= (1.0 - self.p)
21
        return x
22