Aucun titre de diapositive

publicité
ASI 3
Méthodes numériques
pour l’ingénieur
la méthode des moindres carrés
Le point de vue numérique
(factorisation QR)
Approximation/interpollation:
moindres carrés
2
f(x)
1
0
yi
-1
-2
-3
-4
0
0.2
0.4
données :  xi , yi i 1,n
k
f ( x)    j x
0.8
xi
1
1.2
1.4
1.6
1.8
k  n interpollation
k  n approximat ion
j 1
j 1
f ( xi )  yi
0.6
k
   j xi
j 1
j 1
 yi
n équations et n inconnues ( k )
n
min   f ( xi )  yi 2

i 1
approximat ion au sens
des moindres carrés
Posons le problème
matriciellement
k
f ( x)    j x j 1
j 1
pour
 xi , yi i 1,n
1   2 x1(1)  ...   j x1( j 1)  ...   k x1( k 1) 

(1)
( j 1)
( k 1)



x

...


x

...


x

2 2
j 2
k 2
 1




(1)
( j 1)
 ...   k xi( k 1) 
1   2 xi  ...   j xi



1   2 xn(1)  ...   j xn( j 1)  ...   k xn( k 1) 
f  x1 
f  x2 
f  xi 
f  xn 
Xa = f
k
f ( x)    j x j 1
j 1
pour
 xi , yi i 1,n
1
1



1


1
x1(1) ...
x2(1) ...
x1( j 1) ...
x2( j 1) ...
x1( k 1)
x2( k 1)
f  x1 
f  x2 
xi(1) ...
xi( j 1) ...

xn( j 1) ...
xi( k 1)
f  xi 
xn( k 1)
f  xn 
Posons le problème

matriciellement
=
xn(1) ...
1   2 x1(1)  ...   j x1( j 1)  ...   k x1( k 1) 

(1)
( j 1)
( k 1)



x

...


x

...


x

2 2
j 2
k 2
 1




(1)
( j 1)
 ...   k xi( k 1) 
1   2 xi  ...   j xi



1   2 xn(1)  ...   j xn( j 1)  ...   k xn( k 1) 
f  x1 
f  x2 
f  xi 
f  xn 
Approximation au sens des
moindres carrés


j 1
min   f ( xi )  yi   min J ( ) avec J ( )      j xi  yi 
 i 1

i 1  j 1

J
principe :  *  argmin J ( ) 
( *)  0;
j  1,..., k
 j

n
n
2
n
J
 k

 2     xi 1  yi  xij 1  0
 j

i 1   1
k
2
 n  1 j 1  n
      xi xi   yi xij 1
 i 1
 i 1
 1
k
Système linéaire de k équations et k inconnues
Approximation : version matricielle


j
min   f ( xi )  yi   min J ( ) avec J ( )      j xi  yi 
 i 1

i 1  j 0

k
ei  f ( xi )  yi    j xij  yi
j 0
Erreur

 
e

X

y
d’approximation
 e1  1 x1  x1k 1 
 y1 
  1   
  
     
     
 e   1 x  x k 1       y 
i
i
  j   i 
 i 
      
     

e  

k 1   k  
y
 n  1 xi  xi 
 n
2
 2
J ( )  e  X  y
 
J ' ( )  2 X '  X  y 
J ' ( )  0   X ' X   X ' y
n
2
n
k
2
Système linéaire de k équations et k inconnues
Approximation : version matricielle
2


j
min   f ( xi )  yi   min J ( ) avec J ( )      j xi  yi 
 i 1

i 1  j 0

k
ei  f ( xi )  yi    j xij  yi
j 0
Erreur

 
Matrice de Vandermonde
e

X

y
d’approximation
(1735-1796)
k 1
e
y


1
x

x
 1
 1
1 
1

  
 1  
     
     
 e   1 x  x k 1       y 
i
i
  j   i 
 i 
      
     

e  

k 1   k  
y
 n  1 xi  xi 
 n
2
 2
J ( )  e  X  y
 
J ' ( )  2 X '  X  y 
J ' ( )  0   X ' X   X ' y
n
2
n
k
Système linéaire de k équations et k inconnues
Forme quadratique
2
 2
J ( )  e  X  y
 
 
  X  y '  X  y 



  
  ' X ' X  2 ' X ' y  y ' y
1 

min
 ' G  2 ' h
 J ( )  min


 2
 
J ' ( )  2 X '  X  y 
J ' ( )  0 
G h 
X ' X  X ' y
Équations normales
Point de vue algèbrique (géométrique)
X représente une application linéaire de Rp sur Rn
Projection de y (les résultats des expériences)
sur le sous espace vectoriel engendré par X (les données)

e   yˆ  y    X  y 
y
Rn
0
Im X   R p
 ( j)
X   X  j

p
j 1
yˆ  X '  X '  X ' X 1 Xy
montrons que X '  X ' X 1 X est un projecteur
yˆ  y est orthogonal à X  X '  yˆ  y   0
 X '  X  y   0
Comment résoudre le problème
des moindres carrées ?
1


X 
0

0
1 1
1   2
1
1 



0 0
T
2
X X  1
1 
1 

 0
 1
2

1
1




0 
Rang(X’X) = Rang(X) = 3
cond(X’X) = cond(X)*cond(X)
si  2  précision machine, X T X est singulière
si   précision machine, X est régulière
Il faut mieux travailler sur X que sur X’X … si possible !
Un principe, deux idées
factorisat ion X  QR
avec Q'Q  I
Matrice
ainsi : X ' Xa  X ' y  R  Q' y (triangula ire) orthogonale
Orthogonalisation de Schmidt
1
p
R
Orthogonalisation de Householder
HX  R  X  QR
Car H orthogonale
X
0
1
1
G
n
X
R
H
n
0
Base orthogonale (Schmidt)
R
0
X  GR
 G : base orthogonal e

 R : triangula ire supérieure
G' G  I
G
X
yˆ  X ' y
 GG ' y
X  GG ' y  GR  GG ' y
 G ' GR  G ' GG ' y
 R  G ' y
Fonction x = mmc(A,b)
G,R = decompose(A)
x = triang(R,G’b)
R
Décompose : X=GR
0
Théorème :
dans tout espace vectoriel
de dimension finie,
il existe des bases orthogonales
G
(1)
 k1 X
G (k )
G
1
avec k1  (1)
X
(1)


~
G ( 2)  X ( 2)  X ( 2) ' G (1) G (1) ;
k 1


i 1
{
~
G ( k )  X ( k )   X ( k ) ' G (i ) G (i ) ;
~
rki
G ( 2)
~ ( 2)
G
 ~ ( 2)
G
G (k )
~
G (k )
 ~ (k )
G
X (k )
X
Décompose : X=GR
Fonction G,R = décompose(A)
pour k  1 jusqu' à p
pour j  1 jusqu' à n; g jk  0 fait
pour i  1 jusqu' à k  1
ps  0
pour j  1 jusqu' à n; ps  ps  a jk g ji fait
pour j  1 jusqu' à n; g jk  g jk  ps g ji fait
fait
g2  0
pour j  1 jusqu' à n;
g jk  x jk - g jk
g 2  g kj g kj
fait
pour j  1 jusqu' à n; g jk  g jk / g 2 fait
fait
Problème d’accumulation d’erreurs d’arrondi
La méthode QR
Il est si facile le résoudre un système « triangulaire » !
A  QR
Ax  b  Rx  Q 1b
Q « facilement » inversible et R triangulaire
Définition : on appelle matrice de Householder du vecteur normé u
une matrice H de la forme suivante
H  I  2uu T
Propriété : une matrice de Householder est symétrique et orthogonale
HTH=I
Les transformations orthogonales « conservent » la norme
Hx  x
Orthogonalisation : X = QR
R
0
Q symétrique
Q concerve la norme : Qx  x
Q'  Q 1  Q  L (n, n)
Transformation de Householder
HX  R  X  H 1R
 H'R
( H orthogonal e)
 QR
(Q  H ' )
colonne par colonne (comme pour LU)
H  H ( k 1) H ( k 2) ...H ( j ) ...H ( 2) H (1)
le produit de deux matrices orthogonal es
est une matrice orthogonal e
QH
1
 H'
Q (k )
X (k )
Q
Définir H
X
Householder et moindres carrés
Q est une transform ation orthogonal e 
- Q concerve la norme : QT x  x
- Q TQ  I
appliquons au problème des moindres carrées
min X  y  min QR  y


 min QT QR  y 

 min R  QT y

 R  QT y
(système triangula ire)
Transformation de Householder
transforma tion de Householde r
orthogonal e à y
yy '
H  I 2
y' y
Symétrie d' axe y : Hy   y
la première transform ation
Hx  e  y  x  e
Transformation de Householder
Théorème : pour tout vecteur normé x, pour le vecteur unitaire e1
il existe une matrice H telle que : Hx=e1
Démonstration : posons
y    x  e1  avec  
1
x  e1
alors H  I  2 yy ' répond à la question, en effet :
Hx   I  2 yy 'x  x  2 2  x  e1  x  e1 ' x
 x  2 2  xx'e1 x' xe1 'e1e1 'x
 x  2 2  x  e1  x1  x  e1 
 x  2 2 1  x1  x  e1 
1
or  
21  x1 
d' ou Hx  x   x  e1   e1
2
Transformation de Householder
transforma tion de Householde r
orthogonal e à y
yy '
H  I 2
y' y
la première transform ation




1
1
HH(k )
=
0
0
X (k )
R
H (1) X (1)  e (1)  y  X (1)  e (1)
(1)
(1)
(1)
(1) '
X e X e
(1)
H  I 2
(1)
(1) '
X e
X (1)  e (1)
la k ème transformation


X
0
~ (k )
HH
HH(k )
0
~
y ( k )  X ( k )  e (1k )
(k ) (k )
y
y '
~ (k )
H  I  2 (k ) (k )
y 'y
Quels calculs ?
(k ) (k )

y
y '
~ (k )

H X   I  ( k ) ( k )  X
y 'y 

1 (k ) (k )
 X  y y 'X







n
s j   yi( k ) xij
i k
xij  xij 
1

yi( k ) s j
QR : algorithme de Householder
k premières
lignes de R
• Rangement des variables
• produit des H : (si besoin)
à la fin en commençant par le plus simple
• formules à l’étape k

(k )
Diag(R)
n
y
1
y
k
n
Partie
non encore
factorisée
  sign(ak ,k )  ai2,k
i k
yk( k )  ak ,k   ( k ) et yi( k )  ai ,k
p
pour k  1  i  n
  n    ( k ) ak ,k
ak , k   ( k )
(k ) 2
sj 
1
n
 yi( k ) ai , j pour k  1  j  p
 i k
ai , j  ai , j  s j yi( k )
pour k  1  i  p et k  1  j  n
L’algorithme QR
Fonction Q,R = décomposeQR(X)
pour k  1 jusqu' à p
s0
pour j  k jusqu' à n;
y j  x jk
s  s  y 2j
fait
 s ;
si   0  alors    finsi
yk  yk  
  s   xkk
xkk  xkk  
pour j  k  1 jusqu' à p;
fait
fait
s0
pour i  k jusqu' à n; s  s  xij yi fait
s  s/
pour i  k jusqu' à n; xij  xij  s yi fait
Retour des moindres carrées
la méthode QR
Ax  b  Q'  Ax  b   Q' Ax  Q' b
2
2
2
c
posons Q' b   
d 
 Rx   c 
Q' Ax  Q' b  Q' QRx  Q' b      
 0  d 
2
min Ax  b  résoudre en x : Rx  c
x
Mise en œuvre : on calcule directement Q’b
pendant la décomposition
Remarques
MMC sans Q
min X  y  X ' X  X ' y
2

X  QR
X ' X  R' R
1  R' z  X ' y
2  R  y
résidus : r  y  X  X ' Xe  X ' r
3  r  y  X
4  R' w  X ' r
5  Re  w
6 x  xe
R=chol(A’A)
Si on ajoute ou on enlève une variable Q et R changent « peu »
1



X 
0

0
1 1

3
 
0 0
; b    1

 0
1

 
0 
Matlab
1. construire y tel que y  X * b
2. résoudre le problème des moindres carrées  X , y 
- en utilisant les équation normales
- en utilisant la fonction qr de matlab
- en utilisant la fonction \ de matlab
3. implémente z la méthode de Householde r sur la matrice X
d' abord sans faire de boucle en calculant les matrices H (1) , H ( 2) et H (3)
puis en faisant une boucle sur k  1 : 3 sans calculer les matrices H ( k )
puis sans calculer de matrice H , mais directement le vecteur Q' y
ATTENTION : cette semaine il faut un compte rendu par binôme
unCR est une page recto verso : recto ce que vous avez fait, verso : ce que vous en pensez !
Téléchargement