Example #1
0
    def buildRest(self):

        self.ind_de_obj = debuilder(
            self.numpy_rng,
            self.theano_rng,
            input=self.ind_en_obj.sigmoid_layers[-1].output,
            en_list=self.ind_en_obj.dA_layers,
        )

        self.col_de_obj = debuilder(
            self.numpy_rng,
            self.theano_rng,
            input=self.col_en_obj.sigmoid_layers[-1].output,
            en_list=self.col_en_obj.dA_layers,
        )

        # Split Decode Comp
        self.splt_de_obj = split_de_train(
            self.numpy_rng,
            self.theano_rng,
            output=self.x,
            ihid=self.ind_de_obj.sigmoid_layers[-1].output,
            chid=self.col_de_obj.sigmoid_layers[-1].output,
            iW_prime=theano.shared(self.splt_en_obj.iW.get_value().T, name='iW_de',borrow=False),
            cW_prime=theano.shared(self.splt_en_obj.cW.get_value().T, name='cW_de',borrow=False),
            bvis=self.splt_en_obj.b_vis,
        )

        # Collective Error
        self.col_error_obj = HiddenLayer(
            self.numpy_rng,
            input = self.col_de_obj.sigmoid_layers[-1].output,
            n_in = 100,
            n_out = 10,
            activation=T.nnet.sigmoid
        )

        # Errors backprop
        self.err_ind = self.splt_de_obj.get_cost()
        self.err_col = - T.sum(self.y * T.log(self.col_error_obj.output) + (1 - self.y) * T.log(1 - self.col_error_obj.output))
        # self.err_col = T.mean((self.y - self.col_error_obj.output)**2)

        # Add params together
        self.params.extend(self.ind_de_obj.params)
        self.params.extend(self.col_de_obj.params)
        self.params.extend(self.splt_de_obj.params)

        self.params_col.extend([self.splt_en_obj.cW, self.splt_en_obj.b_chid])
        self.params_col.extend(self.col_en_obj.params)
        self.params_col.extend(self.col_de_obj.params)
        self.params_col.extend(self.col_error_obj.params)
Example #2
0
    def __init__(
            self,
            numpy_rng,
            theano_rng=None,
            corruption_levels=[0.1, 0.1],
            input=None,
            output=None,
            batch_size=500,
            maxepoch=100,
            learning_rate=0.01
    ):
        self.params_col = []
        self.params = []
        self.numpy_rng = numpy_rng
        self.theano_rng = theano_rng
        self.batch_size = batch_size
        self.maxepoch = maxepoch
        self.corruption_levels = corruption_levels
        self.learning_rate = learning_rate

        # For input init
        if input is None:
            self.x = T.dmatrix(name='input')
        else:
            self.x = input
        # For output init
        if output is None:
            self.y = T.dvector(name='output')
        else:
            self.y = output

        ##############################
        # BUILD FULL MODEL
        #
        ##############################


        # Split Encode Comp
        self.splt_en_obj = split_en_train(
            numpy_rng=self.numpy_rng,
            theano_rng=self.theano_rng,
            input=self.x,
            n_vis=28 * 28,
            n_ihid=100,
            n_chid=100,
        )
        ind, col = self.splt_en_obj.get_encoder(self.x)


        # Individual Comp
        self.ind_en_obj = enbuilder(
            self.numpy_rng,
            self.theano_rng,
            input = ind,
            n_ins=self.splt_en_obj.n_ihid,
            hidden_layers_sizes=[100, 100],
            corruption_levels=[0.1, 0.1]
        )

        self.ind_de_obj = debuilder(
            self.numpy_rng,
            self.theano_rng,
            input=self.ind_en_obj.sigmoid_layers[-1].output,
            en_list=self.ind_en_obj.dA_layers,
        )


        # Collective Comp
        self.col_en_obj = enbuilder(
            self.numpy_rng,
            self.theano_rng,
            input = col,
            n_ins=self.splt_en_obj.n_chid,
            hidden_layers_sizes=[100, 100],
            corruption_levels=[0.1, 0.1]
        )

        self.col_de_obj = debuilder(
            self.numpy_rng,
            self.theano_rng,
            input=self.col_en_obj.sigmoid_layers[-1].output,
            en_list=self.col_en_obj.dA_layers,
        )

        # Split Decode Comp
        self.splt_de_obj = split_de_train(
            self.numpy_rng,
            self.theano_rng,
            output=self.x,
            ihid=self.ind_de_obj.sigmoid_layers[-1].output,
            chid=self.col_de_obj.sigmoid_layers[-1].output,
            iW_prime=theano.shared(self.splt_en_obj.iW.get_value().T, borrow=False),
            cW_prime=theano.shared(self.splt_en_obj.cW.get_value().T, borrow=False),
            bvis=self.splt_en_obj.b_vis,
        )

        # Collective Error
        self.col_error_obj = HiddenLayer(
            self.numpy_rng,
            input = self.col_de_obj.sigmoid_layers[-1].output,
            n_in = 100,
            n_out = 10,
            activation=T.nnet.sigmoid
        )

        # Errors backprop
        self.err_ind = self.splt_de_obj.get_cost()
        self.err_col = - T.sum(self.y * T.log(self.col_error_obj.output) + (1 - self.y) * T.log(1 - self.col_error_obj.output))
        # self.err_col = T.mean((self.y - self.col_error_obj.output)**2)

        # Add params together

        self.params.extend(self.splt_en_obj.params)
        self.params.extend(self.ind_en_obj.params)
        self.params.extend(self.ind_de_obj.params)
        self.params.extend(self.col_en_obj.params)
        self.params.extend(self.col_de_obj.params)
        self.params.extend(self.splt_de_obj.params)

        self.params_col.extend([self.splt_en_obj.cW, self.splt_en_obj.b_chid])
        self.params_col.extend(self.col_en_obj.params)
        self.params_col.extend(self.col_de_obj.params)
        self.params_col.extend(self.col_error_obj.params)