Exemplo n.º 1
0
Arquivo: base.py Projeto: 0rchard/CUV
    def __init__(self, layer1, layer2, cfg, layernum):
        self.mat = cp.dev_tensor_float_cm([layer1.size, layer2.size])
        cp.fill(self.mat, 0)
        cp.add_rnd_normal(self.mat)
        fact = 1.0
        if layer2.unit_type == UnitType.binary or layer1.unit_type == UnitType.binary:
            # the 0.5 stems from the fact that our upper layer has activation 0.5 on average, not 0, if we use binary hidden units.
            fact = 0.5

        self.mat *= fact / math.sqrt(max(layer1.size, layer2.size))
        self.allocBias(layer1, layer2)
Exemplo n.º 2
0
    def __init__(self, layer1, layer2, cfg, layernum):
        self.mat = cp.dev_tensor_float_cm([layer1.size, layer2.size])
        cp.fill(self.mat, 0)
        cp.add_rnd_normal(self.mat)
        fact = 1.0
        if layer2.unit_type == UnitType.binary or layer1.unit_type == UnitType.binary:
            # the 0.5 stems from the fact that our upper layer has activation 0.5 on average, not 0, if we use binary hidden units.
            fact = 0.5

        self.mat *= fact / math.sqrt(max(layer1.size, layer2.size))
        self.allocBias(layer1, layer2)
Exemplo n.º 3
0
 def setMiniBatch(self, mb, dst_layer):
     self.sampleset_ = mb
     self.sampleset  = cp.dev_tensor_uc_cm(self.sampleset_.copy('F'))
     shift = np.random.randint(-self.maxmov,self.maxmov+1, 2).astype('int32')
     cp.image_move(dst_layer,self.sampleset,self.src_size, self.dst_size, self.src_num_maps, shift[0],shift[1])
     if self.noise_std != 0:
         cp.add_rnd_normal(dst_layer,self.noise_std)
     if self.norm:
         self.norm(dst_layer)
     self.sampleset.dealloc()
     self.sampleset = dst_layer.copy()
Exemplo n.º 4
0
 def setMiniBatch(self, mb, dst_layer):
     self.sampleset_ = mb
     self.sampleset = cp.dev_tensor_uc_cm(self.sampleset_.copy('F'))
     shift = np.random.randint(-self.maxmov, self.maxmov + 1,
                               2).astype('int32')
     cp.image_move(dst_layer, self.sampleset, self.src_size, self.dst_size,
                   self.src_num_maps, shift[0], shift[1])
     if self.noise_std != 0:
         cp.add_rnd_normal(dst_layer, self.noise_std)
     if self.norm:
         self.norm(dst_layer)
     self.sampleset.dealloc()
     self.sampleset = dst_layer.copy()
Exemplo n.º 5
0
Arquivo: base.py Projeto: 0rchard/CUV
 def sample(self):
     if self.unit_type ==  UnitType.gaussian or self.unit_type ==  UnitType.cont:
         cp.add_rnd_normal(self.act)
     elif self.unit_type ==  UnitType.binary:
         cp.rnd_binarize(self.act)
Exemplo n.º 6
0
 def sample(self):
     if self.unit_type == UnitType.gaussian or self.unit_type == UnitType.cont:
         cp.add_rnd_normal(self.act)
     elif self.unit_type == UnitType.binary:
         cp.rnd_binarize(self.act)