'Aux function.'

def _fit(self, data, max_pca_components, fit_type):

    random_state = check_random_state(self.random_state)
    if (not check_version('sklearn', '0.18')):
        from sklearn.decomposition import RandomizedPCA
        pca = RandomizedPCA(n_components=max_pca_components, whiten=True, copy=True, random_state=random_state)
    else:
        from sklearn.decomposition import PCA
        pca = PCA(n_components=max_pca_components, copy=True, whiten=True, svd_solver='randomized', random_state=random_state)
    if isinstance(self.n_components, float):
        full_var = np.var(data, axis=1).sum()
    data = pca.fit_transform(data.T)
    if isinstance(self.n_components, float):
        explained_variance_ratio_ = (pca.explained_variance_ / full_var)
        n_components_ = np.sum((explained_variance_ratio_.cumsum() <= self.n_components))
        if (n_components_ < 1):
            raise RuntimeError('One    PCA    component    captures    most    of    the    explained    variance,    your    threshold    results    in    0    components.    You    should    select    a    higher    value.')
        logger.info(('Selection    by    explained    variance:    %i    components' % n_components_))
        sel = slice(n_components_)
    elif (self.n_components is not None):
        sel = slice(self.n_components)
        logger.info(('Selection    by    number:    %i    components' % self.n_components))
    else:
        logger.info(('Using    all    PCA    components:    %i' % len(pca.components_)))
        sel = slice(len(pca.components_))
    self.pca_mean_ = pca.mean_
    self.pca_components_ = pca.components_
    self.pca_explained_variance_ = exp_var = pca.explained_variance_
    if (not check_version('sklearn', '0.18')):
        self.pca_components_ *= np.sqrt(exp_var[:, None])
    del pca
    self.n_components_ = sel.stop
    if (self.n_pca_components is not None):
        if (self.n_pca_components > len(self.pca_components_)):
            self.n_pca_components = len(self.pca_components_)
    if (self.method == 'fastica'):
        from sklearn.decomposition import FastICA
        ica = FastICA(whiten=False, random_state=random_state, **self.fit_params)
        ica.fit(data[:, sel])
        self.unmixing_matrix_ = getattr(ica, 'components_', 'unmixing_matrix_')
    elif (self.method in ('infomax', 'extended-infomax')):
        self.unmixing_matrix_ = infomax(data[:, sel], random_state=random_state, **self.fit_params)
    self.unmixing_matrix_ /= np.sqrt(exp_var[sel])[None, :]
    self.mixing_matrix_ = linalg.pinv(self.unmixing_matrix_)
    self.current_fit = fit_type
