Example #1
0
name_train = np.genfromtxt(ivec.get_name_path(None), dtype=str)

I_test = F.MmapData(path=ivec.get_i_path(name='test'), read_only=True)
F_test = F.MmapData(path=ivec.get_f_path(name='test'), read_only=True)
name_test = np.genfromtxt(ivec.get_name_path(name='test'), dtype=str)
# ===========================================================================
# I-vector
# ===========================================================================
X_train = I_train
X_test = I_test
# ====== cosine scoring ====== #
print(ctext("==== '%s'" % "Ivec cosine-scoring", 'cyan'))
scorer = ml.Scorer(centering=True, wccn=True, lda=True, method='cosine')
scorer.fit(X=X_train, y=y_train)
scorer.evaluate(X_test, y_test, labels=labels)
# ====== plda scoring ====== #
print(ctext("==== '%s'" % "Ivec PLDA-scoring", 'cyan'))
scorer = ml.PLDA(n_phi=100,
                 n_iter=12,
                 centering=True,
                 wccn=True,
                 unit_length=True,
                 random_state=1234)
scorer.fit(X=X_train, y=y_train)
scorer.evaluate(X_test, y_test, labels=labels)
# ====== svm scoring ====== #
print(ctext("==== '%s'" % "Ivec SVM-scoring", 'cyan'))
scorer = ml.Scorer(wccn=True, lda=True, method='svm')
scorer.fit(X=X_train, y=y_train)
scorer.evaluate(X_test, y_test, labels=labels)
Example #2
0
 # ====== GMM scoring ====== #
 print(ctext("==== '%s'" % "Ivec GMM-scoring-all", 'cyan'))
 scorer = ml.GMMclassifier(strategy="all",
                           covariance_type='full',
                           centering=True,
                           wccn=True,
                           unit_length=True,
                           lda=False,
                           concat=False)
 scorer.fit(X=X_train, y=y_true['train'])
 scorer.evaluate(X_test, y_true['test'], labels=labels)
 # ====== plda scoring ====== #
 print(ctext("==== '%s'" % "Ivec PLDA-scoring", 'cyan'))
 scorer = ml.PLDA(n_phi=TV_DIM // 2,
                  n_iter=12,
                  centering=True,
                  wccn=True,
                  unit_length=True,
                  random_state=5218)
 scorer.fit(X=X_train, y=y_true['train'])
 scorer.evaluate(X_test, y_true['test'], labels=labels)
 # ====== svm scoring ====== #
 print(ctext("==== '%s'" % "Ivec SVM-scoring", 'cyan'))
 scorer = ml.Scorer(wccn=True, lda=True, method='svm')
 scorer.fit(X=X_train, y=y_true['train'])
 scorer.evaluate(X_test, y_true['test'], labels=labels)
 # ===========================================================================
 # Super-vector
 # ===========================================================================
 X_train = stats['train'][1]
 X_test = stats['test'][1]
 X_train, X_test = ml.fast_pca(X_train,
Example #3
0
def compare_methods(X, y, dim, title, n_iter='auto', verbose=0, plda=False):
    print(title, ':', dim)
    #
    pca = PCA(n_components=dim, random_state=random_state)
    pca.fit(X)
    X_pca = pca.transform(X)
    #
    if plda:
        plda = ml.PLDA(n_phi=dim, verbose=verbose)
        plda.fit(X=X_iris, y=y_iris)
        X_plda = plda.transform(X_iris)
        n_col = 5
    else:
        plda = None
        X_plda = None
        n_col = 4
    #
    ppca = ml.PPCA(n_components=dim,
                   verbose=verbose,
                   n_iter=n_iter,
                   random_state=random_state)
    ppca.fit(X)
    X_ppca = ppca.transform(X)
    #
    sppca1 = ml.SupervisedPPCA(n_components=dim,
                               verbose=verbose,
                               extractor='supervised',
                               n_iter=n_iter,
                               random_state=random_state)
    sppca1.fit(X, y)
    X_sppca1 = sppca1.transform(X)
    #
    sppca2 = ml.SupervisedPPCA(n_components=dim,
                               verbose=verbose,
                               extractor='unsupervised',
                               n_iter=n_iter,
                               random_state=random_state)
    sppca2.fit(X, y)
    X_sppca2 = sppca2.transform(X)
    # T-SNE if necessary
    if dim > 2:
        X_pca = ml.fast_tsne(X_pca, n_components=2)
        X_ppca = ml.fast_tsne(X_ppca, n_components=2)
        X_sppca1 = ml.fast_tsne(X_sppca1, n_components=2)
        X_sppca2 = ml.fast_tsne(X_sppca2, n_components=2)
        if X_plda is not None:
            X_plda = ml.fast_tsne(X_plda, n_components=2)
    # Plotting
    V.plot_figure(nrow=4, ncol=18)
    plt.subplot(1, n_col, 1)
    plt.scatter(x=X_pca[:, 0], y=X_pca[:, 1], c=y, marker='o', alpha=0.5, s=1)
    plt.xticks([], [])
    plt.yticks([], [])
    plt.title("PCA")

    plt.subplot(1, n_col, 2)
    plt.scatter(x=X_ppca[:, 0],
                y=X_ppca[:, 1],
                c=y,
                marker='o',
                alpha=0.5,
                s=1)
    plt.xticks([], [])
    plt.yticks([], [])
    plt.title("PPCA")

    plt.subplot(1, n_col, 3)
    plt.scatter(x=X_sppca1[:, 0],
                y=X_sppca1[:, 1],
                c=y,
                marker='o',
                alpha=0.5,
                s=1)
    plt.xticks([], [])
    plt.yticks([], [])
    plt.title("S-PPCA (supervised extractor)")

    plt.subplot(1, n_col, 4)
    plt.scatter(x=X_sppca2[:, 0],
                y=X_sppca2[:, 1],
                c=y,
                marker='o',
                alpha=0.5,
                s=1)
    plt.xticks([], [])
    plt.yticks([], [])
    plt.title("S-PPCA (unsupervised extractor")

    if plda is not None:
        plt.subplot(1, n_col, 5)
        plt.scatter(x=X_plda[:, 0],
                    y=X_plda[:, 1],
                    c=y,
                    marker='o',
                    alpha=0.5,
                    s=1)
        plt.xticks([], [])
        plt.yticks([], [])
        plt.title("PLDA")

    plt.suptitle('[%d]%s' % (dim, title))