diff --git a/455-Codage_Sources/algo_code/LBG.py b/455-Codage_Sources/algo_code/LBG.py new file mode 100644 index 0000000..113300a --- /dev/null +++ b/455-Codage_Sources/algo_code/LBG.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Sun May 5 13:59:37 2019 + +@author: pac +Algorithme de Linde-Buzo-Gray, version 2D +""" + +import numpy as np +import matplotlib.pyplot as plt + +from scipy.spatial import Voronoi, voronoi_plot_2d + +mean= [0,0] +cov = [[1,0],[0,1]] +M = 20; +N =100; #point par cluster +K = N*M +means = np.random.rand(M,2)*10 +X = np.zeros((K,2)) +plt.figure() + +for m in range(M): + xi = np.random.multivariate_normal(means[m,:],cov,N) + X[m*N:(m+1)*N] = xi + plt.plot(xi[:,0],xi[:,1],'+') +plt.plot(means[:,0],means[:,1],'ob') +plt.show() + +# X = np.random.multivariate_normal(mean,cov,K) +Y0 = np.random.multivariate_normal(mean, cov,M) +Y0 = means; +def LBG(X,Y0,eps=1e-5,maxiter=1000): + Y = Y0.copy() + old_dist = np.inf + cluster_index = np.zeros(K,dtype=int) + for l in range(maxiter): + dist= 0; + for k in range(len(X)): + quant_min =np.inf + for j in range(len(Y)): + if np.linalg.norm(X[k]-Y[j])