Beispiel #1
0
Datei: nn.py Projekt: EdsterG/cgt
def dropout(x, p=0):
    if p==0: 
        return x
    else:
        mask = cgt.greater(cgt.rand(*cgt.shape(x)), p)
        x = x * mask
        x = x /(1.0-p)
        return x
Beispiel #2
0
Datei: nn.py Projekt: x724/cgt
def dropout(x, p=0):
    if p == 0:
        return x
    else:
        mask = cgt.greater(cgt.rand(*cgt.shape(x)), p)
        x = x * mask
        x = x / (1.0 - p)
        return x
Beispiel #3
0
 def sample(self, p, shape=None, numeric=False):
     """ Element-wise sampling for each component of p """
     # TODO_TZ  maybe cgt has mechanism to eval an expr
     if not numeric:
         p = core.as_node(p)
         shape = shape or cgt.shape(p)
         return cgt.rand(*shape) <= p
     else:
         assert isinstance(p, np.ndarray)
         return np.array(nr.rand(*p.shape) <= p, dtype="i2")
Beispiel #4
0
 def sample(self, p, shape=None):
     p = core.as_node(p)
     shape = shape or cgt.shape(p)
     return cgt.rand(*shape) <= p
Beispiel #5
0
def uniform(size=(), low=0.0, high=1.0, ndim=None):
    return cgt.rand(*size) * (high - low) + low
Beispiel #6
0
def binomial(size=(), n=1, p=0.5, ndim=None, dtype='int64'):
    return cgt.less(cgt.rand(*size), p)
Beispiel #7
0
 def sample(self, p, shape=None):
     p = core.as_node(p)
     shape = shape or cgt.shape(p)
     return cgt.rand(*shape) <= p