Commit c9e82a39 authored by Pierre-antoine Comby's avatar Pierre-antoine Comby

mise en forme du code

parent 0f84d76d
......@@ -14,10 +14,14 @@
\section{Quantification}
\subsection{Quantification uniforme}
\inputminted{python}{../algo_code/quantif.py}
\newpage
\subsection{Algorithme de Llyod-max}
\inputminted{python}{../algo_code/llyod_max.py}
\newpage
\subsection{Algorithme LBG}
en 2D , ne pas essayer de tracer les cellule de voronoi
\inputminted{python}{../algo_code/LBG.py}
\section{Codeur prédictif}
Construire un schéma de prédiction en boucle fermée à fenêtre glissante dasn lequel $M$et $p$ sont paramétrisable. On utilisera un quantificateur à zone morte de pas $\Delta$ paramétrisable.
\section{KLT}
......
......@@ -2,9 +2,8 @@
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi, voronoi_plot_2d
#
#initialisations clusters
M = 20;
N =100; #point par cluster
K = N*M
......@@ -17,15 +16,12 @@ for m in range(M):
X[m*N:(m+1)*N] = xi
plt.plot(xi[:,0],xi[:,1],'+')
plt.plot(means[:,0],means[:,1],'ob')
mean= np.mean(X,axis=0)
Y0 = np.random.multivariate_normal(mean, 10*cov, M)
plt.show()
print(Y0)
Y0= means
Y0= means #triche
plt.plot(Y0[:,0],Y0[:,1],'ok')
plt.show()
def LBG(X,Y0,eps=1e-5,maxiter=1000):
Y = Y0.copy()
old_dist = np.inf
......@@ -41,17 +37,15 @@ def LBG(X,Y0,eps=1e-5,maxiter=1000):
dist += sum((X[k]-quant_min)**2)
for j in range(len(Y)):
Y[j,:] = np.mean(X[cluster_index==j],axis=0)
print(Y)
if dist-old_dist < eps:
break
else:
old_dist = dist
return Y
Y = LBG(X,Y0)
vor = Voronoi(Y)
vor = Voronoi(Y)# black magic
voronoi_plot_2d(vor,show_vertices=False)
print(Y)
plt.plot(X[:,0],X[:,1],'+')
plt.plot(Y[:,0],Y[:,1],'ob')
plt.plot(Y0[:,0],Y0[:,1],'ok')
plt.show()
plt.show()
\ No newline at end of file
......@@ -5,8 +5,7 @@ from scipy.stats import norm
import matplotlib.pyplot as plt
def ddp(x):
mean = 0,
sigma = 1
mean = 0; sigma = 1
return norm.pdf(x,mean,sigma)
def quant(centroids, X):
......@@ -34,7 +33,6 @@ def llyodMax(X,M,maxiter=1000,eps=1e-6):
/integrate.quad(lambda x: ddp(x),bornes[i],bornes[i+1])[0]
bornes[1:-1] = (centroids[:-1]+centroids[1:])/2
err = np.linalg.norm(centroids-old_centroids)
print(err)
if err < eps :
break
return centroids
......@@ -43,10 +41,7 @@ M = 4
X = np.random.normal(0,1,1000)
centroids = llyodMax(X,M)
bornes = (centroids[:-1]+centroids[1:])/2
bornes = np.insert(bornes,0,-np.inf)
bornes = np.append(bornes,np.inf)
print(centroids, bornes)
bornes = np.insert(bornes,0,-np.inf); bornes = np.append(bornes,np.inf)
plt.figure()
plt.plot(X)
plt.plot(quant(bornes,X))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment