deepy.layers.Dropout   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 15
Duplicated Lines 0 %
Metric Value
dl 0
loc 15
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A output() 0 4 2
A test_output() 0 4 2
A __init__() 0 3 1
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