### Tidy up docs and plots

parent aec805cc
 ... ... @@ -15,7 +15,7 @@ static auto GMMMachine_doc = bob::extension::ClassDoc( BOB_EXT_MODULE_PREFIX ".GMMMachine", "This class implements the statistical model for multivariate diagonal mixture Gaussian distribution (GMM)." "This class implements the statistical model for multivariate diagonal mixture Gaussian distribution (GMM). " "A GMM is defined as :math:\\sum_{c=0}^{C} \\omega_c \\mathcal{N}(x | \\mu_c, \\sigma_c), where :math:C is the number of Gaussian components :math:\\mu_c, :math:\\sigma_c and :math:\\omega_c are respectively the the mean, variance and the weight of each gaussian component :math:c.", "See Section 2.3.9 of Bishop, \"Pattern recognition and machine learning\", 2006" ).add_constructor( ... ...
 ... ... @@ -15,7 +15,7 @@ static auto IVectorMachine_doc = bob::extension::ClassDoc( BOB_EXT_MODULE_PREFIX ".IVectorMachine", "Statistical model for the Total Variability training (see iVectors in the user guide)" "Statistical model for the Total Variability training for more information and explanation see the user guide in documentation (:ref:iVectors )" // this documentation text is intentionally written to be long! "", "" ).add_constructor( ... ...
This diff is collapsed.
 .. vim: set fileencoding=utf-8 : .. Tiago de Freitas Pereira .. Tue 17 Feb 2015 13:50:06 CET .. .. Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland .. _bob.learn.em: ... ... @@ -10,13 +6,9 @@ Expectation Maximization Machine Learning Tools ================================================ The EM algorithm is an iterative method that estimates parameters for statistical models, where the model depends on unobserved latent variables. The EM iteration alternates between performing an expectation (E) step, which creates a function for the expectation of the log-likelihood evaluated using the current estimate for the parameters, and a maximization (M) step, which computes parameters maximizing the expected log-likelihood found on the E step. These parameter-estimates are then used to determine the distribution of the latent variables in the next E step [WikiEM]_. This package is a part of Bob_. It implements a general EM algorithm and includes implementations of the following algorithms: The package includes the machine definition per se and a selection of different trainers for specialized purposes: - K-Means - Maximum Likelihood (ML) - Maximum a Posteriori (MAP) ... ... @@ -35,7 +27,7 @@ Documentation guide py_api References ----------- ... ...
 ... ... @@ -12,6 +12,7 @@ .. _blitz++: http://www.oonumerics.org/blitz .. _bob's idiap guide: https://gitlab.idiap.ch/bob/bob/wikis/Using-Bob-at-Idiap .. _bob's website: https://www.idiap.ch/software/bob .. _bob: https://www.idiap.ch/software/bob .. _boost: http://www.boost.org .. _buildbot: http://trac.buildbot.net .. _buildout: http://pypi.python.org/pypi/zc.buildout/ ... ...
 import bob.db.iris import numpy numpy.random.seed(2) # FIXING A SEED import bob.learn.linear import bob.learn.em import bob.learn.linear import matplotlib.pyplot as plt import numpy numpy.random.seed(2) # FIXING A SEED def train_ubm(features, n_gaussians): ... ... @@ -14,11 +12,14 @@ def train_ubm(features, n_gaussians): kmeans_machine = bob.learn.em.KMeansMachine(int(n_gaussians), input_size) ubm = bob.learn.em.GMMMachine(int(n_gaussians), input_size) # The K-means clustering is firstly used to used to estimate the initial means, the final variances and the final weights for each gaussian component # The K-means clustering is firstly used to used to estimate the initial # means, the final variances and the final weights for each gaussian # component kmeans_trainer = bob.learn.em.KMeansTrainer('RANDOM_NO_DUPLICATE') bob.learn.em.train(kmeans_trainer, kmeans_machine, features) # Getting the means, weights and the variances for each cluster. This is a very good estimator for the ML # Getting the means, weights and the variances for each cluster. This is a # very good estimator for the ML (variances, weights) = kmeans_machine.get_variances_and_weights_for_each_cluster(features) means = kmeans_machine.means ... ... @@ -28,7 +29,8 @@ def train_ubm(features, n_gaussians): ubm.weights = weights # Creating the ML Trainer. We will adapt only the means trainer = bob.learn.em.ML_GMMTrainer(update_means=True, update_variances=False, update_weights=False) trainer = bob.learn.em.ML_GMMTrainer( update_means=True, update_variances=False, update_weights=False) bob.learn.em.train(trainer, ubm, features) return ubm ... ... @@ -36,7 +38,8 @@ def train_ubm(features, n_gaussians): def isv_train(features, ubm): """ Features com lista de listas [ [data_point_1_user_1,data_point_2_user_1], [data_point_1_user_2,data_point_2_user_2] ] Features com lista de listas [ [data_point_1_user_1,data_point_2_user_1], [data_point_1_user_2,data_point_2_user_2] ] """ stats = [] ... ... @@ -59,11 +62,14 @@ def isv_train(features, ubm): return isvbase ### GENERATING DATA # GENERATING DATA data_per_class = bob.db.iris.data() setosa = numpy.column_stack((data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack((data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack((data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) setosa = numpy.column_stack( (data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack( (data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack( (data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) data = numpy.vstack((setosa, versicolor, virginica)) # TRAINING THE PRIOR ... ... @@ -77,24 +83,34 @@ u2 = isvbase.u[4:6, 0] / numpy.linalg.norm(isvbase.u[4:6, 0]) figure, ax = plt.subplots() plt.scatter(setosa[:, 0], setosa[:, 1], c="darkcyan", label="setosa") plt.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") plt.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") plt.scatter(virginica[:, 0], virginica[:, 1], c="dimgrey", label="virginica") plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", marker="x", label="centroids - mle") #plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", marker=".", label="within class varibility", s=0.01) ax.arrow(ubm.means[0, 0], ubm.means[0, 1], u0[0], u0[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[1, 0], ubm.means[1, 1], u1[0], u1[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[2, 0], ubm.means[2, 1], u2[0], u2[1], fc="k", ec="k", head_width=0.05, head_length=0.1) plt.text(ubm.means[0, 0] + u0[0], ubm.means[0, 1] + u0[1] - 0.1, r'$\mathbf{U}_1$', fontsize=15) plt.text(ubm.means[1, 0] + u1[0], ubm.means[1, 1] + u1[1] - 0.1, r'$\mathbf{U}_2$', fontsize=15) plt.text(ubm.means[2, 0] + u2[0], ubm.means[2, 1] + u2[1] - 0.1, r'$\mathbf{U}_3$', fontsize=15) ax.set_xticklabels("" for item in ax.get_xticklabels()) ax.set_yticklabels("" for item in ax.get_yticklabels()) plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", marker="x", label="centroids - mle") # plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", # marker=".", label="within class varibility", s=0.01) ax.arrow(ubm.means[0, 0], ubm.means[0, 1], u0[0], u0[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[1, 0], ubm.means[1, 1], u1[0], u1[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[2, 0], ubm.means[2, 1], u2[0], u2[1], fc="k", ec="k", head_width=0.05, head_length=0.1) plt.text(ubm.means[0, 0] + u0[0], ubm.means[0, 1] + u0[1] - 0.1, r'$\mathbf{U}_1$', fontsize=15) plt.text(ubm.means[1, 0] + u1[0], ubm.means[1, 1] + u1[1] - 0.1, r'$\mathbf{U}_2$', fontsize=15) plt.text(ubm.means[2, 0] + u2[0], ubm.means[2, 1] + u2[1] - 0.1, r'$\mathbf{U}_3$', fontsize=15) plt.xticks([], []) plt.yticks([], []) # plt.grid(True) plt.xlabel('Sepal length') plt.ylabel('Petal width') plt.legend() plt.tight_layout() plt.show()
 import bob.db.iris import numpy numpy.random.seed(2) # FIXING A SEED import bob.learn.linear import bob.learn.em import bob.learn.linear import matplotlib.pyplot as plt import numpy numpy.random.seed(2) # FIXING A SEED def train_ubm(features, n_gaussians): ... ... @@ -14,11 +12,14 @@ def train_ubm(features, n_gaussians): kmeans_machine = bob.learn.em.KMeansMachine(int(n_gaussians), input_size) ubm = bob.learn.em.GMMMachine(int(n_gaussians), input_size) # The K-means clustering is firstly used to used to estimate the initial means, the final variances and the final weights for each gaussian component # The K-means clustering is firstly used to used to estimate the initial # means, the final variances and the final weights for each gaussian # component kmeans_trainer = bob.learn.em.KMeansTrainer('RANDOM_NO_DUPLICATE') bob.learn.em.train(kmeans_trainer, kmeans_machine, features) # Getting the means, weights and the variances for each cluster. This is a very good estimator for the ML # Getting the means, weights and the variances for each cluster. This is a # very good estimator for the ML (variances, weights) = kmeans_machine.get_variances_and_weights_for_each_cluster(features) means = kmeans_machine.means ... ... @@ -28,7 +29,8 @@ def train_ubm(features, n_gaussians): ubm.weights = weights # Creating the ML Trainer. We will adapt only the means trainer = bob.learn.em.ML_GMMTrainer(update_means=True, update_variances=False, update_weights=False) trainer = bob.learn.em.ML_GMMTrainer( update_means=True, update_variances=False, update_weights=False) bob.learn.em.train(trainer, ubm, features) return ubm ... ... @@ -36,7 +38,7 @@ def train_ubm(features, n_gaussians): def jfa_train(features, ubm): """ Features com lista de listas [ [data_point_1_user_1,data_point_2_user_1], [data_point_1_user_2,data_point_2_user_2] ] Features com lista de listas [ [data_point_1_user_1,data_point_2_user_1], [data_point_1_user_2,data_point_2_user_2] ] """ stats = [] ... ... @@ -51,7 +53,8 @@ def jfa_train(features, ubm): subspace_dimension_of_u = 1 subspace_dimension_of_v = 1 jfa_base = bob.learn.em.JFABase(ubm, subspace_dimension_of_u, subspace_dimension_of_v) jfa_base = bob.learn.em.JFABase( ubm, subspace_dimension_of_u, subspace_dimension_of_v) trainer = bob.learn.em.JFATrainer() # trainer.rng = bob.core.random.mt19937(int(self.init_seed)) bob.learn.em.train_jfa(trainer, jfa_base, stats, max_iterations=50) ... ... @@ -59,11 +62,14 @@ def jfa_train(features, ubm): return jfa_base ### GENERATING DATA # GENERATING DATA data_per_class = bob.db.iris.data() setosa = numpy.column_stack((data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack((data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack((data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) setosa = numpy.column_stack( (data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack( (data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack( (data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) data = numpy.vstack((setosa, versicolor, virginica)) # TRAINING THE PRIOR ... ... @@ -82,33 +88,47 @@ v1 = jfa_base.v[2:4, 0] / numpy.linalg.norm(jfa_base.v[2:4, 0]) v2 = jfa_base.v[4:6, 0] / numpy.linalg.norm(jfa_base.v[4:6, 0]) figure, ax = plt.subplots() plt.scatter(setosa[:, 0], setosa[:, 1], c="darkcyan", label="setosa") plt.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") plt.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") plt.scatter(virginica[:, 0], virginica[:, 1], c="dimgrey", label="virginica") plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", marker="x", label="centroids - mle") #plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", marker=".", label="within class varibility", s=0.01) plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", marker="x", label="centroids - mle") # plt.scatter(ubm.means[:, 0], ubm.means[:, 1], c="blue", # marker=".", label="within class varibility", s=0.01) # U ax.arrow(ubm.means[0, 0], ubm.means[0, 1], u0[0], u0[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[1, 0], ubm.means[1, 1], u1[0], u1[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[2, 0], ubm.means[2, 1], u2[0], u2[1], fc="k", ec="k", head_width=0.05, head_length=0.1) plt.text(ubm.means[0, 0] + u0[0], ubm.means[0, 1] + u0[1] - 0.1, r'$\mathbf{U}_1$', fontsize=15) plt.text(ubm.means[1, 0] + u1[0], ubm.means[1, 1] + u1[1] - 0.1, r'$\mathbf{U}_2$', fontsize=15) plt.text(ubm.means[2, 0] + u2[0], ubm.means[2, 1] + u2[1] - 0.1, r'$\mathbf{U}_3$', fontsize=15) ax.arrow(ubm.means[0, 0], ubm.means[0, 1], u0[0], u0[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[1, 0], ubm.means[1, 1], u1[0], u1[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[2, 0], ubm.means[2, 1], u2[0], u2[1], fc="k", ec="k", head_width=0.05, head_length=0.1) plt.text(ubm.means[0, 0] + u0[0], ubm.means[0, 1] + u0[1] - 0.1, r'$\mathbf{U}_1$', fontsize=15) plt.text(ubm.means[1, 0] + u1[0], ubm.means[1, 1] + u1[1] - 0.1, r'$\mathbf{U}_2$', fontsize=15) plt.text(ubm.means[2, 0] + u2[0], ubm.means[2, 1] + u2[1] - 0.1, r'$\mathbf{U}_3$', fontsize=15) # V ax.arrow(ubm.means[0, 0], ubm.means[0, 1], v0[0], v0[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[1, 0], ubm.means[1, 1], v1[0], v1[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[2, 0], ubm.means[2, 1], v2[0], v2[1], fc="k", ec="k", head_width=0.05, head_length=0.1) plt.text(ubm.means[0, 0] + v0[0], ubm.means[0, 1] + v0[1] - 0.1, r'$\mathbf{V}_1$', fontsize=15) plt.text(ubm.means[1, 0] + v1[0], ubm.means[1, 1] + v1[1] - 0.1, r'$\mathbf{V}_2$', fontsize=15) plt.text(ubm.means[2, 0] + v2[0], ubm.means[2, 1] + v2[1] - 0.1, r'$\mathbf{V}_3$', fontsize=15) ax.set_xticklabels("" for item in ax.get_xticklabels()) ax.set_yticklabels("" for item in ax.get_yticklabels()) ax.arrow(ubm.means[0, 0], ubm.means[0, 1], v0[0], v0[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[1, 0], ubm.means[1, 1], v1[0], v1[1], fc="k", ec="k", head_width=0.05, head_length=0.1) ax.arrow(ubm.means[2, 0], ubm.means[2, 1], v2[0], v2[1], fc="k", ec="k", head_width=0.05, head_length=0.1) plt.text(ubm.means[0, 0] + v0[0], ubm.means[0, 1] + v0[1] - 0.1, r'$\mathbf{V}_1$', fontsize=15) plt.text(ubm.means[1, 0] + v1[0], ubm.means[1, 1] + v1[1] - 0.1, r'$\mathbf{V}_2$', fontsize=15) plt.text(ubm.means[2, 0] + v2[0], ubm.means[2, 1] + v2[1] - 0.1, r'$\mathbf{V}_3$', fontsize=15) plt.xticks([], []) plt.yticks([], []) # plt.grid(True) plt.xlabel('Sepal length') ... ... @@ -116,4 +136,5 @@ plt.ylabel('Petal width') plt.legend(loc=2) plt.ylim([-1, 3.5]) #plt.show() plt.tight_layout() # plt.show()
 import bob.learn.em import matplotlib.pyplot as plt import bob.db.iris import bob.learn.em import numpy numpy.random.seed(10) from matplotlib import pyplot data_per_class = bob.db.iris.data() setosa = numpy.column_stack((data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack((data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack((data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) setosa = numpy.column_stack( (data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack( (data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack( (data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) data = numpy.vstack((setosa, versicolor, virginica)) mle_machine = bob.learn.em.GMMMachine(3, 2)# Two clusters with a feature dimensionality of 3 # Two clusters with a feature dimensionality of 3 mle_machine = bob.learn.em.GMMMachine(3, 2) mle_trainer = bob.learn.em.ML_GMMTrainer(True, True, True) mle_machine.means = numpy.array([[5, 3], [4, 2], [7, 3.]]) bob.learn.em.train(mle_trainer, mle_machine, data, max_iterations=200, convergence_threshold=1e-5) # Train the KMeansMachine bob.learn.em.train(mle_trainer, mle_machine, data, max_iterations=200, convergence_threshold=1e-5) # Train the KMeansMachine #Creating some random data centered in # Creating some random data centered in new_data = numpy.random.normal(2, 0.8, (50, 2)) map_machine = bob.learn.em.GMMMachine(3, 2) # Two clusters with a feature dimensionality of 3 # Two clusters with a feature dimensionality of 3 map_machine = bob.learn.em.GMMMachine(3, 2) map_trainer = bob.learn.em.MAP_GMMTrainer(mle_machine, relevance_factor=4) bob.learn.em.train(map_trainer, map_machine, new_data, max_iterations=200, convergence_threshold=1e-5) # Train the KMeansMachine bob.learn.em.train(map_trainer, map_machine, new_data, max_iterations=200, convergence_threshold=1e-5) # Train the KMeansMachine figure, ax = pyplot.subplots() pyplot.scatter(new_data[:, 0], new_data[:, 1], c="olivedrab", label="new data") pyplot.scatter(setosa[:, 0], setosa[:, 1], c="darkcyan", label="setosa") pyplot.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") pyplot.scatter(virginica[:, 0], virginica[:, 1], c="dimgrey", label="virginica") pyplot.scatter(mle_machine.means[:, 0], mle_machine.means[:, 1], c="blue", marker="x", label="prior centroids - mle", s=60) pyplot.scatter(map_machine.means[:, 0], map_machine.means[:, 1], c="red", marker="^", label="adapted centroids - map", s=60) pyplot.legend() ax.set_xticklabels("" for item in ax.get_xticklabels()) ax.set_yticklabels("" for item in ax.get_yticklabels()) figure, ax = plt.subplots() plt.scatter(new_data[:, 0], new_data[:, 1], c="olivedrab", label="new data") plt.scatter(setosa[:, 0], setosa[:, 1], c="darkcyan", label="setosa") plt.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") plt.scatter(virginica[:, 0], virginica[:, 1], c="dimgrey", label="virginica") plt.scatter(mle_machine.means[:, 0], mle_machine.means[:, 1], c="blue", marker="x", label="prior centroids - mle", s=60) plt.scatter(map_machine.means[:, 0], map_machine.means[:, 1], c="red", marker="^", label="adapted centroids - map", s=60) plt.legend() plt.xticks([], []) plt.yticks([], []) ax.set_xlabel("Sepal length") ax.set_ylabel("Petal width") pyplot.show() plt.tight_layout() plt.show()
 import bob.learn.em import bob.db.iris import numpy from matplotlib import pyplot import matplotlib.pyplot as plt data_per_class = bob.db.iris.data() setosa = numpy.column_stack((data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack((data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack((data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) setosa = numpy.column_stack( (data_per_class['setosa'][:, 0], data_per_class['setosa'][:, 3])) versicolor = numpy.column_stack( (data_per_class['versicolor'][:, 0], data_per_class['versicolor'][:, 3])) virginica = numpy.column_stack( (data_per_class['virginica'][:, 0], data_per_class['virginica'][:, 3])) data = numpy.vstack((setosa, versicolor, virginica)) machine = bob.learn.em.GMMMachine(3, 2) # Two clusters with a feature dimensionality of 3 # Two clusters with a feature dimensionality of 3 machine = bob.learn.em.GMMMachine(3, 2) trainer = bob.learn.em.ML_GMMTrainer(True, True, True) machine.means = numpy.array([[5, 3], [4, 2], [7, 3.]]) bob.learn.em.train(trainer, machine, data, max_iterations = 200, convergence_threshold = 1e-5) # Train the KMeansMachine bob.learn.em.train(trainer, machine, data, max_iterations=200, convergence_threshold=1e-5) # Train the KMeansMachine figure, ax = pyplot.subplots() pyplot.scatter(setosa[:, 0], setosa[:, 1], c="darkcyan", label="setosa") pyplot.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") pyplot.scatter(virginica[:, 0], virginica[:, 1], c="dimgrey", label="virginica") pyplot.scatter(machine.means[:, 0], machine.means[:, 1], c="blue", marker="x", label="centroids", s=60) pyplot.legend() ax.set_xticklabels("" for item in ax.get_xticklabels()) ax.set_yticklabels("" for item in ax.get_yticklabels()) figure, ax = plt.subplots() plt.scatter(setosa[:, 0], setosa[:, 1], c="darkcyan", label="setosa") plt.scatter(versicolor[:, 0], versicolor[:, 1], c="goldenrod", label="versicolor") plt.scatter(virginica[:, 0], virginica[:, 1], c="dimgrey", label="virginica") plt.scatter(machine.means[:, 0], machine.means[:, 1], c="blue", marker="x", label="centroids", s=60) plt.legend() plt.xticks([], []) plt.yticks([], []) ax.set_xlabel("Sepal length") ax.set_ylabel("Petal width") pyplot.show() plt.tight_layout() plt.show()
 import matplotlib.pyplot as plt import bob.learn.em import numpy numpy.random.seed(10) from matplotlib import pyplot n_clients = 10 n_scores_per_client = 200 # Defining some fake scores for genuines and impostors impostor_scores = numpy.random.normal(-15.5, 5, (n_scores_per_client, n_clients)) impostor_scores = numpy.random.normal(-15.5, 5, (n_scores_per_client, n_clients)) genuine_scores = numpy.random.normal(0.5, 5, (n_scores_per_client, n_clients)) # Defining the scores for the statistics computation ... ... @@ -19,25 +19,30 @@ t_norm_impostors = bob.learn.em.tnorm(impostor_scores, t_scores) t_norm_genuine = bob.learn.em.tnorm(genuine_scores, t_scores) # PLOTTING figure = pyplot.subplot(2, 1, 1) figure = plt.subplot(2, 1, 1) ax = figure.axes pyplot.title("Raw scores", fontsize=8) pyplot.hist(impostor_scores.reshape(n_scores_per_client*n_clients), label='Impostors', normed=True, color='red', alpha=0.5, bins=50) pyplot.hist(genuine_scores.reshape(n_scores_per_client*n_clients), label='Genuine', normed=True, color='blue', alpha=0.5, bins=50) pyplot.legend(fontsize=8) ax.set_yticklabels("" for item in ax.get_yticklabels()) figure = pyplot.subplot(2, 1, 2) plt.title("Raw scores", fontsize=8) plt.hist(impostor_scores.reshape(n_scores_per_client * n_clients), label='Impostors', normed=True, color='C1', alpha=0.5, bins=50) plt.hist(genuine_scores.reshape(n_scores_per_client * n_clients), label='Genuine', normed=True, color='C0', alpha=0.5, bins=50) plt.legend(fontsize=8) plt.yticks([], []) figure = plt.subplot(2, 1, 2) ax = figure.axes pyplot.title("T-norm scores", fontsize=8) pyplot.hist(t_norm_impostors.reshape(n_scores_per_client*n_clients), label='T-Norm Impostors', normed=True, color='red', alpha=0.5, bins=50) pyplot.hist(t_norm_genuine.reshape(n_scores_per_client*n_clients), label='T-Norm Genuine', normed=True, color='blue', alpha=0.5, bins=50) pyplot.legend(fontsize=8) ax.set_yticklabels("" for item in ax.get_yticklabels()) pyplot.show() plt.title("T-norm scores", fontsize=8) plt.hist(t_norm_impostors.reshape(n_scores_per_client * n_clients), label='T-Norm Impostors', normed=True, color='C1', alpha=0.5, bins=50) plt.hist(t_norm_genuine.reshape(n_scores_per_client * n_clients), label='T-Norm Genuine', normed=True, color='C0', alpha=0.5, bins=50) plt.legend(fontsize=8) plt.yticks([], []) plt.tight_layout() plt.show()
 import matplotlib.pyplot as plt import bob.learn.em import numpy numpy.random.seed(10) from matplotlib import pyplot n_clients = 10 n_scores_per_client = 200 # Defining some fake scores for genuines and impostors impostor_scores = numpy.random.normal(-15.5, 5, (n_scores_per_client, n_clients)) impostor_scores = numpy.random.normal(-15.5, 5, (n_scores_per_client, n_clients)) genuine_scores = numpy.random.normal(0.5, 5, (n_scores_per_client, n_clients)) # Defining the scores for the statistics computation ... ... @@ -19,29 +19,36 @@ t_scores = numpy.random.normal(-6., 5, (n_scores_per_client, n_clients)) zt_scores = bob.learn.em.tnorm(z_scores, t_scores) # ZT - Normalizing zt_norm_impostors = bob.learn.em.ztnorm(impostor_scores, z_scores, t_scores, zt_scores) zt_norm_genuine = bob.learn.em.ztnorm(genuine_scores, z_scores, t_scores, zt_scores) zt_norm_impostors = bob.learn.em.ztnorm( impostor_scores, z_scores, t_scores, zt_scores) zt_norm_genuine = bob.learn.em.ztnorm( genuine_scores, z_scores, t_scores, zt_scores) # PLOTTING figure = pyplot.subplot(2, 1, 1) figure = plt.subplot(2, 1, 1) ax = figure.axes pyplot.title("Raw scores", fontsize=8) pyplot.hist(impostor_scores.reshape(n_scores_per_client*n_clients), label='Impostors', normed=True, color='red', alpha=0.5, bins=50) pyplot.hist(genuine_scores.reshape(n_scores_per_client*n_clients), label='Genuine', normed=True, color='blue', alpha=0.5, bins=50) pyplot.legend(fontsize=8) ax.set_yticklabels("" for item in ax.get_yticklabels()) figure = pyplot.subplot(2, 1, 2) plt.title("Raw scores", fontsize=8) plt.hist(impostor_scores.reshape(n_scores_per_client * n_clients), label='Impostors', normed=True, color='C1', alpha=0.5, bins=50) plt.hist(genuine_scores.reshape(n_scores_per_client * n_clients), label='Genuine', normed=True, color='C0', alpha=0.5, bins=50) plt.legend(fontsize=8) plt.yticks([], []) figure = plt.subplot(2,