(self, X, shuffle=True, display_step=5)
return self
Training cycle.

        Parameters
        ----------
        X : ndarray, shape (n_samples, n_features)
            Matrix containing the data to be learned.

        Returns
        -------
        self : object
            Returns self.
Training cycle.
Training cycle .
def fit(self, X, shuffle=True, display_step=5):
        """Training cycle.

        Parameters
        ----------
        X : ndarray, shape (n_samples, n_features)
            Matrix containing the data to be learned.

        Returns
        -------
        self : object
            Returns self.
        """
        if display_step is None:
            display_step = self.log_every
        n_samples = X.shape[0]

        # Pretrain the discriminator.
        if self.d_pretrain:
            num_pretrain_steps = 1000
            for step in xrange(num_pretrain_steps):
                d = np.empty([self.batch_size, self.net_arch['n_input']])
                for i in range(self.net_arch['n_input']):
                    d[:, i] = (self.random_state.random_sample(
                        self.batch_size) - 0.5) * 10.0
                labels = np.empty([self.batch_size, self.net_arch['n_input']])
                for i in range(self.net_arch['n_input']):
                    labels[:, i] = self.random_state.uniform(
                        low=0.0, high=1.0, size=d.shape[0])
                pretrain_loss, _ = self.sess.run([self.pre_loss, self.pre_opt], {
                    self.pre_input: np.reshape(d, (self.batch_size, -1)),
                    self.pre_labels: np.reshape(
                        labels, (self.batch_size, self.net_arch['n_input']))
                })
            self.weightsD = self.sess.run(self.d_pre_vars)
            # Copy the weights from pre-training over to the new discriminator
            # network.
            for i, v in enumerate(self.d_vars):
                self.sess.run(v.assign(self.weightsD[i]))

        for epoch in range(self.num_epochs):
            if shuffle:
                indices = np.arange(len(X))
                self.random_state.shuffle(indices)
            # Loop over all batches.
            start_idxs = range(
                0, len(X) - self.batch_size + 1, self.batch_size)
            for start_idx in start_idxs:
                if shuffle:
                    excerpt = indices[start_idx:start_idx + self.batch_size]
                else:
                    excerpt = slice(start_idx, start_idx + self.batch_size)
                batch_x = np.array(X[excerpt])
                batch_z = self.gen.sample(self.batch_size)

                # Fit training using batch data.
                cost_d, cost_g = self.partial_fit(batch_x, batch_z)

            if len(start_idxs) > 0:
                if display_step and epoch % display_step == 0:
                    print("Epoch: {:d}".format(epoch + 1),
                          "loss_d_real: {:.4f}".format(
                              self.loss_d_real.eval({self.x: batch_x})),
                          "loss_d_fake: {:.4f}".format(
                              self.loss_d_fake.eval({self.z: batch_z})),
                          "loss_g: {:.4f}".format(
                              self.loss_g.eval({self.z: batch_z})))

        return self
def fit ( self , X , shuffle = True , display_step = 5 ) : if display_step is None : display_step = self . log_every n_samples = X . shape [ 0 ] # Pretrain the discriminator. if self . d_pretrain : num_pretrain_steps = 1000 for step in xrange ( num_pretrain_steps ) : d = np . empty ( [ self . batch_size , self . net_arch [ 'n_input' ] ] ) for i in range ( self . net_arch [ 'n_input' ] ) : d [ : , i ] = ( self . random_state . random_sample ( self . batch_size ) - 0.5 ) * 10.0 labels = np . empty ( [ self . batch_size , self . net_arch [ 'n_input' ] ] ) for i in range ( self . net_arch [ 'n_input' ] ) : labels [ : , i ] = self . random_state . uniform ( low = 0.0 , high = 1.0 , size = d . shape [ 0 ] ) pretrain_loss , _ = self . sess . run ( [ self . pre_loss , self . pre_opt ] , { self . pre_input : np . reshape ( d , ( self . batch_size , - 1 ) ) , self . pre_labels : np . reshape ( labels , ( self . batch_size , self . net_arch [ 'n_input' ] ) ) } ) self . weightsD = self . sess . run ( self . d_pre_vars ) # Copy the weights from pre-training over to the new discriminator # network. for i , v in enumerate ( self . d_vars ) : self . sess . run ( v . assign ( self . weightsD [ i ] ) ) for epoch in range ( self . num_epochs ) : if shuffle : indices = np . arange ( len ( X ) ) self . random_state . shuffle ( indices ) # Loop over all batches. start_idxs = range ( 0 , len ( X ) - self . batch_size + 1 , self . batch_size ) for start_idx in start_idxs : if shuffle : excerpt = indices [ start_idx : start_idx + self . batch_size ] else : excerpt = slice ( start_idx , start_idx + self . batch_size ) batch_x = np . array ( X [ excerpt ] ) batch_z = self . gen . sample ( self . batch_size ) # Fit training using batch data. cost_d , cost_g = self . partial_fit ( batch_x , batch_z ) if len ( start_idxs ) > 0 : if display_step and epoch % display_step == 0 : print ( "Epoch: {:d}" . format ( epoch + 1 ) , "loss_d_real: {:.4f}" . format ( self . loss_d_real . eval ( { self . x : batch_x } ) ) , "loss_d_fake: {:.4f}" . format ( self . loss_d_fake . eval ( { self . z : batch_z } ) ) , "loss_g: {:.4f}" . format ( self . loss_g . eval ( { self . z : batch_z } ) ) ) return self