Ejemplo n.º 1
0
    def _create_custom_gmm(self, means, covs, weigths):

        n_comps = len(means)

        gmm = BayesianGaussianMixture(n_comps)
        gmm.means_ = np.array(means).reshape(-1, 1)
        gmm.covariances_ = np.array(covs).reshape(-1, 1, 1)
        gmm.weights_ = np.array(weigths)
        gmm._check_is_fitted = lambda: True

        return gmm
Ejemplo n.º 2
0
def copy_fit(bgm, method='bgm'):
    n_clusters = bgm.n_components
    covartype = bgm.covariance_type
    n_init = bgm.n_init
    max_iter = bgm.max_iter
    tol = bgm.tol
    verbose = True
    if method == 'bgm':
        wcpt = bgm.weight_concentration_prior_type
        reg_covar = bgm.reg_covar
        init_params = bgm.init_params
        tol = bgm.tol
        copy = BGM(n_components=n_clusters,
                   covariance_type=covartype,
                   n_init=n_init,
                   weight_concentration_prior_type=wcpt,
                   init_params=init_params,
                   max_iter=max_iter,
                   verbose=verbose,
                   reg_covar=reg_covar,
                   tol=tol)
        copy.weight_concentration_prior_ = bgm.weight_concentration_prior_
        copy.weight_concentration_ = bgm.weight_concentration_
        copy.mean_precision_prior = bgm.mean_precision_prior
        copy.mean_prior_ = bgm.mean_prior_
        copy.mean_precision_ = bgm.mean_precision_
        copy.covariance_prior_ = bgm.covariance_prior_
        copy.degrees_of_freedom_prior_ = bgm.degrees_of_freedom_prior_
        copy.degrees_of_freedom_ = bgm.degrees_of_freedom_
    if method == 'gmm':
        copy = GMM(n_components=n_clusters,
                   random_state=42,
                   covariance_type=covartype,
                   max_iter=max_iter,
                   n_init=n_init,
                   tol=tol,
                   verbose=verbose)
    copy.means_ = bgm.means_
    copy.covariances_ = bgm.covariances_
    copy.weights_ = bgm.weights_
    copy.precisions_ = bgm.precisions_
    copy.precisions_cholesky_ = bgm.precisions_cholesky_
    copy.converged_ = bgm.converged_
    copy.n_iter_ = bgm.n_iter_
    copy.lower_bound_ = bgm.lower_bound_
    return copy