def _update_w(self, data_align, data_sup, labels, w, s, theta, bias):
        """

        Parameters
        ----------
        data_align : list of 2D arrays, element i has shape=[voxels_i, n_align]
            Each element in the list contains the fMRI data for alignment of
            one subject. There are n_align samples for each subject.

        data_sup : list of 2D arrays, element i has shape=[voxels_i, samples_i]
            Each element in the list contains the fMRI data of one subject for
            the classification task.

        labels : list of arrays of int, element i has shape=[samples_i]
            Each element in the list contains the labels for the data samples
            in data_sup.

        w : list of array, element i has shape=[voxels_i, features]
            The orthogonal transforms (mappings) :math:`W_i` for each subject.

        s : array, shape=[features, samples]
            The shared response.

        theta : array, shape=[classes, features]
            The MLR class plane parameters.

        bias : array, shape=[classes]
            The MLR class biases.

        Returns
        -------

        w : list of 2D array, element i has shape=[voxels_i, features]
            The updated orthogonal transforms (mappings).
        """
        subjects = len(data_align)

        s_th = S.shared(s.astype(theano.config.floatX))
        theta_th = S.shared(theta.T.astype(theano.config.floatX))
        bias_th = S.shared(bias.T.astype(theano.config.floatX),
                           broadcastable=(True, False))

        for subject in range(subjects):
            logger.info('Subject Wi %d' % subject)
            # Solve for subject i
            # Create the theano function
            w_th = T.matrix(name='W', dtype=theano.config.floatX)
            data_srm_subject = \
                S.shared(data_align[subject].astype(theano.config.floatX))
            constf1 = \
                S.shared((1 - self.alpha) * 0.5 / data_align[subject].shape[1],
                         allow_downcast=True)
            f1 = constf1 * T.sum((data_srm_subject - w_th.dot(s_th))**2)

            if data_sup[subject] is not None:
                lr_samples_S = S.shared(data_sup[subject].shape[1])
                data_sup_subject = \
                    S.shared(data_sup[subject].astype(theano.config.floatX))
                labels_S = S.shared(labels[subject])
                constf2 = S.shared(-self.alpha / self.gamma
                                   / data_sup[subject].shape[1],
                                   allow_downcast=True)

                log_p_y_given_x = T.log(T.nnet.softmax((theta_th.dot(
                    w_th.T.dot(data_sup_subject))).T + bias_th))
                f2 = constf2 * T.sum(
                    log_p_y_given_x[T.arange(lr_samples_S), labels_S])
                f = f1 + f2
            else:
                f = f1

            # Define the problem and solve
            f_subject = self._objective_function_subject(data_align[subject],
                                                         data_sup[subject],
                                                         labels[subject],
                                                         w[subject],
                                                         s, theta, bias)
            minstep = np.amin(((10**-np.floor(np.log10(f_subject))), 1e-1))
            manifold = Stiefel(w[subject].shape[0], w[subject].shape[1])
            problem = Problem(manifold=manifold, cost=f, arg=w_th, verbosity=0)
            solver = ConjugateGradient(mingradnorm=1e-2, minstepsize=minstep)
            w[subject] = np.array(solver.solve(
                problem, x=w[subject].astype(theano.config.floatX)))
            if data_sup[subject] is not None:
                del f2
                del log_p_y_given_x
                del data_sup_subject
                del labels_S
            del solver
            del problem
            del manifold
            del f
            del f1
            del data_srm_subject
            del w_th
        del theta_th
        del bias_th
        del s_th

        # Run garbage collector to avoid filling up the memory
        gc.collect()
        return w
def _update_w ( self , data_align , data_sup , labels , w , s , theta , bias ) : subjects = len ( data_align ) s_th = S . shared ( s . astype ( theano . config . floatX ) ) theta_th = S . shared ( theta . T . astype ( theano . config . floatX ) ) bias_th = S . shared ( bias . T . astype ( theano . config . floatX ) , broadcastable = ( True , False ) ) for subject in range ( subjects ) : logger . info ( 'Subject Wi %d' % subject ) w_th = T . matrix ( name = 'W' , dtype = theano . config . floatX ) data_srm_subject = S . shared ( data_align [ subject ] . astype ( theano . config . floatX ) ) constf1 = S . shared ( ( 1 - self . alpha ) * 0.5 / data_align [ subject ] . shape [ 1 ] , allow_downcast = True ) f1 = constf1 * T . sum ( ( data_srm_subject - w_th . dot ( s_th ) ) ** 2 ) if data_sup [ subject ] is not None : lr_samples_S = S . shared ( data_sup [ subject ] . shape [ 1 ] ) data_sup_subject = S . shared ( data_sup [ subject ] . astype ( theano . config . floatX ) ) labels_S = S . shared ( labels [ subject ] ) constf2 = S . shared ( - self . alpha / self . gamma / data_sup [ subject ] . shape [ 1 ] , allow_downcast = True ) log_p_y_given_x = T . log ( T . nnet . softmax ( ( theta_th . dot ( w_th . T . dot ( data_sup_subject ) ) ) . T + bias_th ) ) f2 = constf2 * T . sum ( log_p_y_given_x [ T . arange ( lr_samples_S ) , labels_S ] ) f = f1 + f2 else : f = f1 f_subject = self . _objective_function_subject ( data_align [ subject ] , data_sup [ subject ] , labels [ subject ] , w [ subject ] , s , theta , bias ) minstep = np . amin ( ( ( 10 ** - np . floor ( np . log10 ( f_subject ) ) ) , 1e-1 ) ) manifold = Stiefel ( w [ subject ] . shape [ 0 ] , w [ subject ] . shape [ 1 ] ) problem = Problem ( manifold = manifold , cost = f , arg = w_th , verbosity = 0 ) solver = ConjugateGradient ( mingradnorm = 1e-2 , minstepsize = minstep ) w [ subject ] = np . array ( solver . solve ( problem , x = w [ subject ] . astype ( theano . config . floatX ) ) ) if data_sup [ subject ] is not None : del f2 del log_p_y_given_x del data_sup_subject del labels_S del solver del problem del manifold del f del f1 del data_srm_subject del w_th del theta_th del bias_th del s_th gc . collect ( ) return w
Parameters
        ----------
        data_align : list of 2D arrays, element i has shape=[voxels_i, n_align]
            Each element in the list contains the fMRI data for alignment of
            one subject. There are n_align samples for each subject.

        data_sup : list of 2D arrays, element i has shape=[voxels_i, samples_i]
            Each element in the list contains the fMRI data of one subject for
            the classification task.

        labels : list of arrays of int, element i has shape=[samples_i]
            Each element in the list contains the labels for the data samples
            in data_sup.

        w : list of array, element i has shape=[voxels_i, features]
            The orthogonal transforms (mappings) :math:`W_i` for each subject.

        s : array, shape=[features, samples]
            The shared response.

        theta : array, shape=[classes, features]
            The MLR class plane parameters.

        bias : array, shape=[classes]
            The MLR class biases.

        Returns
        -------

        w : list of 2D array, element i has shape=[voxels_i, features]
            The updated orthogonal transforms (mappings).