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
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
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")
def sample(self, p, shape=None): p = core.as_node(p) shape = shape or cgt.shape(p) return cgt.rand(*shape) <= p
def uniform(size=(), low=0.0, high=1.0, ndim=None): return cgt.rand(*size) * (high - low) + low
def binomial(size=(), n=1, p=0.5, ndim=None, dtype='int64'): return cgt.less(cgt.rand(*size), p)