Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
M1-EEA
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
EEA
M1-EEA
Commits
1097541b
Commit
1097541b
authored
Apr 04, 2019
by
Pierre-antoine Comby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
devoirs de 455
parent
c9283f84
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
2 deletions
+108
-2
455-Codage_Sources/Cours/chapA.tex
455-Codage_Sources/Cours/chapA.tex
+4
-1
455-Codage_Sources/algo_code/code_arithmetique.py
455-Codage_Sources/algo_code/code_arithmetique.py
+0
-1
455-Codage_Sources/algo_code/llyod_max.py
455-Codage_Sources/algo_code/llyod_max.py
+58
-0
455-Codage_Sources/algo_code/quantif.py
455-Codage_Sources/algo_code/quantif.py
+46
-0
No files found.
455-Codage_Sources/Cours/chapA.tex
View file @
1097541b
...
...
@@ -7,12 +7,15 @@
\subsection
{
version objet
}
\inputminted
{
python
}{
../algo
_
code/huffman2.py
}
\section
{
Codage arithétique
}
\section
{
Codage arithmétique
}
\inputminted
{
python
}{
../algio
_
code/code
_
arithmetique.py
}
\section
{
Codage LZW
}
\inputminted
{
python
}{
../algo
_
code/LZW.py
}
\section
{
Quantification
}
\subsection
{
Quantification uniforme
}
\inputminted
{
python
}{
../algo
_
code/quantif.py
}
\subsection
{
Algorithme de Llyod-max
}
\inputminted
{
python
}{
../algo
_
code/llyod
_
max.py
}
\subsection
{
Algorithme LBG
}
en 2D , ne pas essayer de tracer les cellule de voronoi
\section
{
Codeur prédictif
}
...
...
455-Codage_Sources/algo_code/code_arithmetique.py
View file @
1097541b
...
...
@@ -74,6 +74,5 @@ def arithm_pratique(X,p):
l
[
-
1
]
=
2
*
l
[
-
1
]
-
0.5
h
[
-
1
]
=
2
*
h
[
-
1
]
-
0.5
return
c
#print(arithm(X,p))
print
(
arithm_pratique
(
X
,
p
))
455-Codage_Sources/algo_code/llyod_max.py
0 → 100755
View file @
1097541b
#!/usr/bin/env python3
import
numpy
as
np
from
sipy
import
integrate
from
scipy
import
norm
M
=
8
X
=
np
.
random
.
normal
(
0
,
1
,
1000
)
def
ddp
(
x
):
mean
=
0
,
sigma
=
1
return
norm
.
pdf
(
x
,
mean
,
sigma
)
def
init_thres_vec
(
M
,
X
):
step
=
(
np
.
max
(
X
)
-
np
.
min
(
X
))
/
M
thres_intervals
=
np
.
array
([])
mid
=
np
.
mean
(
X
)
for
i
in
range
(
int
(
M
/
2
)):
thres_intervals
=
np
.
append
(
thres_vec
,
mid
+
(
i
+
1
)
*
step
)
thres_intervals
=
np
.
insert
(
thtres_vec
,
0
,
mid
-
(
1
+
1
)
*
step
)
return
thres_intervals
def
quant
(
x
,
thres
,
intervals
):
thres
=
np
.
append
(
thres
,
np
.
inf
)
thres
=
np
.
insert
(
thres
,
0
,
-
np
.
inf
)
x_hat_q
=
np
.
zeros
(
np
.
shape
(
x
))
for
i
in
range
(
len
(
thres
)
-
1
):
if
i
==
0
:
x_hat_q
=
np
.
where
(
np
.
logical_and
(
x
>
thres
[
i
],
x
<=
thres
[
i
+
1
]),
np
.
full
(
np
.
size
(
x_hat_q
),
intervals
[
i
]),
x_hat_q
)
elif
i
==
range
(
len
(
thres
))[
-
1
]
-
1
:
x_hat_q
=
np
.
where
(
np
.
logical_and
(
x
>
thres
[
i
],
x
<=
thres
[
i
+
1
]),
np
.
full
(
np
.
size
(
x_hat_q
),
intervals
[
i
]),
x_hat_q
)
else
:
x_hat_q
=
np
.
where
(
np
.
logical_and
(
x
>
thres
[
i
],
x
<
thres
[
i
+
1
]),
np
.
full
(
np
.
size
(
x_hat_q
),
intervals
[
i
]),
x_hat_q
)
return
x_hat_q
def
LlyodMax
(
X
,
intervals
,
max_iter
=
1000
,
eps
=
1e-5
):
err_min
=
np
.
inf
for
i
in
range
(
max_iter
):
for
j
in
range
(
len
(
x_hat_q
)):
centroids
[
i
]
=
integrate
.
quad
(
lambda
x
:
x
*
ddp
(
x
),
intervals
[
j
],
intervals
[
j
+
1
])[
0
]
/
integrate
.
quad
(
lambda
x
:
ddp
(
x
),
intervals
[
j
],
intervals
[
j
+
1
])[
0
]
intervals
=
0.5
*
(
centroids
[
1
:]
+
centroids
[:
-
1
])
x_hat
=
quant
(
X
,
centroids
,
intervals
)
err
=
np
.
linalg
.
norm
(
X
-
x_hat
)
if
err
<
err_min
:
err_min
=
err
intervals_min
=
intervals
centroids_min
=
centroids
if
err_min
<
1e-5
:
break
best_x_hat
=
quant
(
X
,
centroids_min
,
intervals_min
)
return
best_x_hat
455-Codage_Sources/algo_code/quantif.py
0 → 100755
View file @
1097541b
#!/usr/bin/env python3
import
numpy
as
np
import
matplotlib.pyplot
as
plt
N
=
1000
X
=
np
.
random
.
rand
(
N
)
X_c
=
(
X
-
0.5
)
*
10
def
quantif_uniforme
(
M
,
X
,
xmin
=-
1
,
xmax
=
1
,
d
=
0
):
"""
réalise la quantification uniforme d'un vecteur sur M niveau
"""
delta
=
2
*
xmax
/
M
# pas de quantification
Q
=
np
.
zeros
(
len
(
X
))
for
k
in
range
(
len
(
X
)):
q
=
(
X
[
k
]
/
delta
)
if
abs
(
q
)
<
d
:
#seuil
Q
[
k
]
=
0
continue
elif
abs
(
q
)
<
2
*
delta
:
if
q
<
0
:
Q
[
k
]
=-
1
else
:
Q
[
k
]
=
1
continue
else
:
Q
[
k
]
=
int
(
q
)
return
Q
,
delta
def
reverse_quantif
(
Q
,
delta
):
return
Q
*
delta
Q
,
delta
=
quantif_uniforme
(
4
,
X_c
)
Q_2
,
delta
=
quantif_uniforme
(
4
,
X_c
,
d
=
0.5
):
print
(
len
(
Q
),
len
(
X_c
))
plt
.
figure
()
plt
.
grid
()
plt
.
plot
(
X_c
,
Q
,
'.'
)
plt
.
plot
(
X_c
,
Q_2
,
'.'
)
plt
.
show
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment