Exemplo n.º 1
0
    def __init__(self, threshold, nb_inp, nb_hid, layer_id='', W=None):
        base.__init__(self, layer_id, W=W)

        # Hyperparameters
        self.threshold = threshold
        self.nb_inp = nb_inp
        self.nb_hid = nb_hid

        # Set optimizable parameter dictionary
        init = uniform(low=-1, high=1,
                       size=(nb_inp, nb_hid)).astype(th.config.floatX)
        init = init / np.sqrt((init**2).sum(0))[None, :]
        self.W = W if W else th.shared(init, name='W' + self.layer_id)
Exemplo n.º 2
0
    def __init__(self,
                 act,
                 nb_inp,
                 nb_hid,
                 init='gaussian',
                 normalize=True,
                 layer_id=None,
                 W=None,
                 b_enc=None,
                 b_opp=None):
        base.__init__(self, layer_id, W=W, b_enc=b_enc, b_opp=b_opp)

        # Hyperparameters
        self.act = act
        self.nb_inp = nb_inp
        self.nb_hid = nb_hid

        # Parameters
        if not self.W:
            if init == 'gaussian':
                w = np.random.normal(0, 0.1, (nb_inp, nb_hid))
            elif init == 'uniform':
                w = np.random.uniform(-6 / sqrt(nb_inp + nb_hid),
                                      6 / sqrt(nb_inp + nb_hid),
                                      (nb_inp, nb_hid))

            if normalize:
                w /= np.sqrt((w**2).sum(0))[None, :]

            self.W = shared_x(w, name='W' + self.layer_id)

        self.scale = shared_x(1, name='scale' + self.layer_id)

        if not self.b_enc:
            self.b_enc = shared_x(np.zeros(nb_hid),
                                  name='b_enc' + self.layer_id)

        if not self.b_opp:
            self.b_opp = shared_x(np.zeros(nb_hid),
                                  name='b_opp' + self.layer_id)

        # For debug
        self.__init_W = shared_x(self.W.get_value())
Exemplo n.º 3
0
    def __init__(self,
                 act,
                 nb_inp,
                 nb_hid,
                 init='gaussian',
                 normalize='True',
                 layer_id=None,
                 scale=None,
                 W=None,
                 b=None,
                 b_dec=None):
        base.__init__(self, layer_id, b=b, b_dec=b_dec, scale=scale)

        # Hyperparameters
        self.act = act
        self.nb_inp = nb_inp
        self.nb_hid = nb_hid

        # Parameters
        if not W:
            if init == 'gaussian':
                w = np.random.normal(0, 0.1, (nb_inp, nb_hid))
            elif init == 'uniform':
                w = np.random.uniform(-6 / sqrt(nb_inp + nb_hid),
                                      6 / sqrt(nb_inp + nb_hid),
                                      (nb_inp, nb_hid))
            if normalize:
                w /= np.sqrt((w**2).sum(0))[None, :]
            self.W = shared_x(w, name='W' + self.layer_id)

        if not self.scale:
            self.scale = shared_x(1, name='scale' + self.layer_id)

        if not self.b:
            self.b = shared_x(np.zeros(nb_hid), name='b' + self.layer_id)

        if not self.b_dec:
            self.b_dec = shared_x(np.zeros(nb_inp),
                                  name='b_dec' + self.layer_id)
Exemplo n.º 4
0
    def __init__(self,
                 dae_act,
                 gdae_act,
                 nb_inp,
                 nb_hid,
                 nb_fac,
                 nb_map,
                 shared,
                 divide,
                 layer_id='',
                 W=None,
                 B=None,
                 FACX=None,
                 FACY=None,
                 M_enc=None,
                 M_dec=None,
                 B_map=None,
                 B_dec=None):
        base.__init__(self,
                      layer_id,
                      W=W,
                      B=B,
                      FACX=FACX,
                      FACY=FACY,
                      M_enc=M_enc,
                      B_map=B_map,
                      B_dec=B_dec)

        # Hyperparameters
        self.nb_inp = nb_inp
        self.nb_hid = nb_hid
        self.nb_fac = nb_fac
        self.nb_map = nb_map
        self.shared = shared
        self.divide = divide
        self.dae_act = dae_act
        self.gdae_act = gdae_act

        # Pre-calculation for conciseness
        daef = 4. if dae_act == T.nnet.sigmoid else 1.
        gdaef = 4. if gdae_act == T.nnet.sigmoid else 1.

        if W == None and nb_hid > 0:
            self.W = shared_x(uniform(-daef * sqrt(6. / nb_inp),
                                      daef * sqrt(6. / nb_inp),
                                      size=(nb_inp, nb_hid)),
                              name='W{}'.format(layer_id))

        if B == None and nb_hid > 0:
            self.B = shared_x(np.zeros(nb_hid), name='B{}'.format(layer_id))

        if FACX is None and nb_fac > 0:
            self.FAC_X = shared_x(uniform(-gdaef * sqrt(6. /
                                                        (nb_inp + nb_fac)),
                                          gdaef * sqrt(6. / (nb_inp + nb_fac)),
                                          size=(nb_inp, nb_fac)),
                                  name='FACX{}'.format(layer_id))

        if FACY is None and nb_fac > 0:
            self.FAC_Y = self.FAC_X if shared else shared_x(
                uniform(-gdaef * sqrt(6. / (nb_inp + nb_fac)),
                        gdaef * sqrt(6. / (nb_inp + nb_fac)),
                        size=(nb_inp, nb_fac)),
                name='FACX{}'.format(layer_id))

        if M_enc is None and nb_fac > 0 and nb_map > 0:
            self.M_enc = shared_x(uniform(-gdaef * sqrt(6. /
                                                        (nb_fac + nb_map)),
                                          gdaef * sqrt(6. / (nb_fac + nb_map)),
                                          size=(nb_fac, nb_map)),
                                  name='M_enc{}'.format(layer_id))
            self.M_dec = shared_x(uniform(-gdaef * sqrt(6. /
                                                        (nb_fac + nb_map)),
                                          gdaef * sqrt(6. / (nb_fac + nb_map)),
                                          size=(nb_map, nb_fac)),
                                  name='M_dec{}'.format(layer_id))
            self.BMAP = th.shared(
                np.zeros(nb_map, dtype=th.config.floatX),
                borrow=True,
                name='mapping_unit_biases{}'.format(layer_id))

        self.BVIS = th.shared(np.zeros(nb_inp, dtype=th.config.floatX),
                              borrow=True,
                              name='decoder_unit_biases{}'.format(layer_id))