mise en forme du code
This commit is contained in:
parent
0f84d76db2
commit
c9e82a395d
3 changed files with 12 additions and 19 deletions
|
@ -14,10 +14,14 @@
|
||||||
\section{Quantification}
|
\section{Quantification}
|
||||||
\subsection{Quantification uniforme}
|
\subsection{Quantification uniforme}
|
||||||
\inputminted{python}{../algo_code/quantif.py}
|
\inputminted{python}{../algo_code/quantif.py}
|
||||||
|
\newpage
|
||||||
\subsection{Algorithme de Llyod-max}
|
\subsection{Algorithme de Llyod-max}
|
||||||
\inputminted{python}{../algo_code/llyod_max.py}
|
\inputminted{python}{../algo_code/llyod_max.py}
|
||||||
|
\newpage
|
||||||
\subsection{Algorithme LBG}
|
\subsection{Algorithme LBG}
|
||||||
en 2D , ne pas essayer de tracer les cellule de voronoi
|
\inputminted{python}{../algo_code/LBG.py}
|
||||||
|
|
||||||
|
|
||||||
\section{Codeur prédictif}
|
\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.
|
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}
|
\section{KLT}
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from scipy.spatial import Voronoi, voronoi_plot_2d
|
from scipy.spatial import Voronoi, voronoi_plot_2d
|
||||||
#
|
#initialisations clusters
|
||||||
M = 20;
|
M = 20;
|
||||||
N =100; #point par cluster
|
N =100; #point par cluster
|
||||||
K = N*M
|
K = N*M
|
||||||
|
@ -17,15 +16,12 @@ for m in range(M):
|
||||||
X[m*N:(m+1)*N] = xi
|
X[m*N:(m+1)*N] = xi
|
||||||
plt.plot(xi[:,0],xi[:,1],'+')
|
plt.plot(xi[:,0],xi[:,1],'+')
|
||||||
plt.plot(means[:,0],means[:,1],'ob')
|
plt.plot(means[:,0],means[:,1],'ob')
|
||||||
|
|
||||||
mean= np.mean(X,axis=0)
|
mean= np.mean(X,axis=0)
|
||||||
|
|
||||||
Y0 = np.random.multivariate_normal(mean, 10*cov, M)
|
Y0 = np.random.multivariate_normal(mean, 10*cov, M)
|
||||||
plt.show()
|
plt.show()
|
||||||
print(Y0)
|
Y0= means #triche
|
||||||
Y0= means
|
|
||||||
plt.plot(Y0[:,0],Y0[:,1],'ok')
|
plt.plot(Y0[:,0],Y0[:,1],'ok')
|
||||||
|
plt.show()
|
||||||
def LBG(X,Y0,eps=1e-5,maxiter=1000):
|
def LBG(X,Y0,eps=1e-5,maxiter=1000):
|
||||||
Y = Y0.copy()
|
Y = Y0.copy()
|
||||||
old_dist = np.inf
|
old_dist = np.inf
|
||||||
|
@ -41,16 +37,14 @@ def LBG(X,Y0,eps=1e-5,maxiter=1000):
|
||||||
dist += sum((X[k]-quant_min)**2)
|
dist += sum((X[k]-quant_min)**2)
|
||||||
for j in range(len(Y)):
|
for j in range(len(Y)):
|
||||||
Y[j,:] = np.mean(X[cluster_index==j],axis=0)
|
Y[j,:] = np.mean(X[cluster_index==j],axis=0)
|
||||||
print(Y)
|
|
||||||
if dist-old_dist < eps:
|
if dist-old_dist < eps:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
old_dist = dist
|
old_dist = dist
|
||||||
return Y
|
return Y
|
||||||
Y = LBG(X,Y0)
|
Y = LBG(X,Y0)
|
||||||
vor = Voronoi(Y)
|
vor = Voronoi(Y)# black magic
|
||||||
voronoi_plot_2d(vor,show_vertices=False)
|
voronoi_plot_2d(vor,show_vertices=False)
|
||||||
print(Y)
|
|
||||||
plt.plot(X[:,0],X[:,1],'+')
|
plt.plot(X[:,0],X[:,1],'+')
|
||||||
plt.plot(Y[:,0],Y[:,1],'ob')
|
plt.plot(Y[:,0],Y[:,1],'ob')
|
||||||
plt.plot(Y0[:,0],Y0[:,1],'ok')
|
plt.plot(Y0[:,0],Y0[:,1],'ok')
|
||||||
|
|
|
@ -5,8 +5,7 @@ from scipy.stats import norm
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
def ddp(x):
|
def ddp(x):
|
||||||
mean = 0,
|
mean = 0; sigma = 1
|
||||||
sigma = 1
|
|
||||||
return norm.pdf(x,mean,sigma)
|
return norm.pdf(x,mean,sigma)
|
||||||
|
|
||||||
def quant(centroids, X):
|
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]
|
/integrate.quad(lambda x: ddp(x),bornes[i],bornes[i+1])[0]
|
||||||
bornes[1:-1] = (centroids[:-1]+centroids[1:])/2
|
bornes[1:-1] = (centroids[:-1]+centroids[1:])/2
|
||||||
err = np.linalg.norm(centroids-old_centroids)
|
err = np.linalg.norm(centroids-old_centroids)
|
||||||
print(err)
|
|
||||||
if err < eps :
|
if err < eps :
|
||||||
break
|
break
|
||||||
return centroids
|
return centroids
|
||||||
|
@ -43,10 +41,7 @@ M = 4
|
||||||
X = np.random.normal(0,1,1000)
|
X = np.random.normal(0,1,1000)
|
||||||
centroids = llyodMax(X,M)
|
centroids = llyodMax(X,M)
|
||||||
bornes = (centroids[:-1]+centroids[1:])/2
|
bornes = (centroids[:-1]+centroids[1:])/2
|
||||||
bornes = np.insert(bornes,0,-np.inf)
|
bornes = np.insert(bornes,0,-np.inf); bornes = np.append(bornes,np.inf)
|
||||||
bornes = np.append(bornes,np.inf)
|
|
||||||
|
|
||||||
print(centroids, bornes)
|
|
||||||
plt.figure()
|
plt.figure()
|
||||||
plt.plot(X)
|
plt.plot(X)
|
||||||
plt.plot(quant(bornes,X))
|
plt.plot(quant(bornes,X))
|
||||||
|
|
Loading…
Reference in a new issue