示例#1
0
文件: nn.py 项目: 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
示例#2
0
文件: nn.py 项目: 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
示例#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")
示例#4
0
文件: distributions.py 项目: zxie/cgt
 def sample(self, p, shape=None):
     p = core.as_node(p)
     shape = shape or cgt.shape(p)
     return cgt.rand(*shape) <= p
示例#5
0
def uniform(size=(), low=0.0, high=1.0, ndim=None):
    return cgt.rand(*size) * (high - low) + low
示例#6
0
def binomial(size=(), n=1, p=0.5, ndim=None, dtype='int64'):
    return cgt.less(cgt.rand(*size), p)
示例#7
0
 def sample(self, p, shape=None):
     p = core.as_node(p)
     shape = shape or cgt.shape(p)
     return cgt.rand(*shape) <= p