Пример #1
0
    def _init_exprs(self):
        self.exprs = {
            'inpt_mean': T.matrix('inpt_mean'),
            'target': T.matrix('target')
        }
        P = self.parameters

        hidden_to_hiddens = [
            getattr(P, 'hidden_to_hidden_%i' % i)
            for i in range(len(self.n_hiddens) - 1)
        ]
        hidden_biases = [
            getattr(P, 'hidden_bias_%i' % i)
            for i in range(len(self.n_hiddens))
        ]
        inpt_var = T.zeros_like(self.exprs['inpt_mean']) + self.inpt_var

        self.exprs.update(
            varprop_mlp.exprs(self.exprs['inpt_mean'], inpt_var,
                              P.in_to_hidden, hidden_to_hiddens,
                              P.hidden_to_out, hidden_biases,
                              [1 for _ in hidden_biases], P.out_bias, 1,
                              self.hidden_transfers, self.out_transfer,
                              self.p_dropout_inpt, self.p_dropout_hiddens))

        self.exprs['inpt'] = self.exprs['inpt_mean']

        self.exprs.update(
            varprop_supervised_loss(self.exprs['target'], self.exprs['output'],
                                    self.loss))
Пример #2
0
    def _init_exprs(self):
        self.exprs = {
            'inpt_mean': T.matrix('inpt_mean'),
            'target': T.matrix('target')}
        P = self.parameters

        hidden_to_hiddens = [getattr(P, 'hidden_to_hidden_%i' % i)
                             for i in range(len(self.n_hiddens) - 1)]
        hidden_biases = [getattr(P, 'hidden_bias_%i' % i)
                         for i in range(len(self.n_hiddens))]
        inpt_var = T.zeros_like(self.exprs['inpt_mean']) + self.inpt_var

        self.exprs.update(varprop_mlp.exprs(
            self.exprs['inpt_mean'], inpt_var, self.exprs['target'],
            P.in_to_hidden,
            hidden_to_hiddens,
            P.hidden_to_out,
            hidden_biases,
            [1 for _ in hidden_biases],
            P.out_bias,
            1,
            self.hidden_transfers, self.out_transfer,
            self.p_dropout_inpt, self.p_dropout_hiddens))

        self.exprs['inpt'] = self.exprs['inpt_mean']

        self.exprs.update(varprop_supervised_loss(
            self.exprs['target'], self.exprs['output'], self.loss))
Пример #3
0
    def _gen_exprs(self, inpt):
        """Return the expression of the generating model."""
        P = self.parameters.gen

        n_layers = len(self.n_hiddens_gen)
        hidden_to_hiddens = [
            getattr(P, 'hidden_to_hidden_%i' % i) for i in range(n_layers - 1)
        ]
        hidden_biases = [
            getattr(P, 'hidden_bias_%i' % i) for i in range(n_layers)
        ]

        exprs = vpmlp.exprs(
            inpt,
            T.zeros_like(inpt),
            P.in_to_hidden,
            hidden_to_hiddens,
            P.hidden_to_out,
            hidden_biases,
            [1 for _ in hidden_biases],
            P.out_bias,
            1,
            self.gen_transfers,
            self.assumptions.statify_visible,
            self.p_dropout_inpt,
            self.p_dropout_hiddens,
        )

        return exprs
Пример #4
0
    def _recog_exprs(self, inpt):
        """Return the exprssions of the recognition model."""
        P = self.parameters.recog

        n_layers = len(self.n_hiddens_recog)
        hidden_to_hiddens = [
            getattr(P, 'hidden_to_hidden_%i' % i) for i in range(n_layers - 1)
        ]
        hidden_biases = [
            getattr(P, 'hidden_bias_%i' % i) for i in range(n_layers)
        ]

        scale_to_interval = lambda x: T.nnet.sigmoid(x) * 0.49 + 0.01

        exprs = vpmlp.exprs(
            inpt,
            T.zeros_like(inpt),
            P.in_to_hidden,
            hidden_to_hiddens,
            P.hidden_to_out,
            hidden_biases,
            [1 for _ in hidden_biases],
            P.out_bias,
            1,
            self.recog_transfers,
            self.assumptions.statify_latent,
            scale_to_interval(P.p_dropout.inpt),
            [scale_to_interval(i) for i in P.p_dropout.hiddens],
        )

        return exprs
Пример #5
0
    def _gen_exprs(self, inpt):
        """Return the expression of the generating model."""
        P = self.parameters.gen

        n_layers = len(self.n_hiddens_gen)
        hidden_to_hiddens = [getattr(P, 'hidden_to_hidden_%i' % i)
                             for i in range(n_layers - 1)]
        hidden_biases = [getattr(P, 'hidden_bias_%i' % i)
                         for i in range(n_layers)]

        exprs = vpmlp.exprs(
            inpt, T.zeros_like(inpt), P.in_to_hidden, hidden_to_hiddens, P.hidden_to_out,
            hidden_biases, [1 for _ in hidden_biases], P.out_bias, 1,
            self.gen_transfers, self.assumptions.statify_visible,
            self.p_dropout_inpt, self.p_dropout_hiddens,
            )

        return exprs
Пример #6
0
    def _recog_exprs(self, inpt):
        """Return the exprssions of the recognition model."""
        P = self.parameters.recog

        n_layers = len(self.n_hiddens_recog)
        hidden_to_hiddens = [getattr(P, 'hidden_to_hidden_%i' % i)
                             for i in range(n_layers - 1)]
        hidden_biases = [getattr(P, 'hidden_bias_%i' % i)
                         for i in range(n_layers)]

        scale_to_interval = lambda x: T.nnet.sigmoid(x) * 0.49 + 0.01

        exprs = vpmlp.exprs(
            inpt, T.zeros_like(inpt), P.in_to_hidden, hidden_to_hiddens, P.hidden_to_out,
            hidden_biases, [1 for _ in hidden_biases], P.out_bias, 1,
            self.recog_transfers, self.assumptions.statify_latent,
            scale_to_interval(P.p_dropout.inpt),
            [scale_to_interval(i) for i in P.p_dropout.hiddens],
            )

        return exprs