Final
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": 72,
|
||||||
"id": "349bd8d2-2bc8-45e3-9f8a-7d60f7dedd39",
|
"id": "349bd8d2-2bc8-45e3-9f8a-7d60f7dedd39",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 12,
|
"execution_count": 73,
|
||||||
"id": "885fccca-d36b-4d94-ba40-03eb06df2c57",
|
"id": "885fccca-d36b-4d94-ba40-03eb06df2c57",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 32,
|
"execution_count": 74,
|
||||||
"id": "69c3443f-b60c-4ebd-a640-c187eedc0e69",
|
"id": "69c3443f-b60c-4ebd-a640-c187eedc0e69",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
@@ -41,12 +41,43 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def decompoQR(A):\n",
|
"def decompoQR(A):\n",
|
||||||
" return np.linalg.qr(A) # tkt"
|
" \"\"\"\n",
|
||||||
|
" A = QR\n",
|
||||||
|
" \n",
|
||||||
|
" Q = Matrice vecteurs orthogonaux (colonnes)\n",
|
||||||
|
" R = Coéfficients des projections sur les vecteurs (triangulaire sup)\n",
|
||||||
|
" \n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" m, n = A.shape\n",
|
||||||
|
" Q = np.zeros((m,m))\n",
|
||||||
|
" R = np.zeros((m,n))\n",
|
||||||
|
" \n",
|
||||||
|
" for i in range(m):\n",
|
||||||
|
" # Vecteur ligne de A\n",
|
||||||
|
" v = A[:,i]\n",
|
||||||
|
" pr = 0\n",
|
||||||
|
" \n",
|
||||||
|
" # Retirer projection sur v des autres vecteurs\n",
|
||||||
|
" # proj A sur B = A@B/(B@B) * B\n",
|
||||||
|
" for j in range(0, i):\n",
|
||||||
|
" av = Q[:,j]\n",
|
||||||
|
"\n",
|
||||||
|
" pr += (av.T@v)* av\n",
|
||||||
|
" v = v - pr\n",
|
||||||
|
"\n",
|
||||||
|
" # normalisation vecteur\n",
|
||||||
|
" Q[:,i] = v/np.linalg.norm(v)\n",
|
||||||
|
" \n",
|
||||||
|
" \n",
|
||||||
|
" R = Q.T@A\n",
|
||||||
|
" \n",
|
||||||
|
" return Q, R\n",
|
||||||
|
" #return np.linalg.qr(A) # tkt"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 59,
|
"execution_count": 78,
|
||||||
"id": "0a1a13da-c084-4a5d-945f-b9edd39b5a24",
|
"id": "0a1a13da-c084-4a5d-945f-b9edd39b5a24",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
@@ -56,7 +87,7 @@
|
|||||||
"def algoQR(A, maxiter=10**3):\n",
|
"def algoQR(A, maxiter=10**3):\n",
|
||||||
" B = A\n",
|
" B = A\n",
|
||||||
" Q = np.identity(A.shape[0])\n",
|
" Q = np.identity(A.shape[0])\n",
|
||||||
" print('init', 'B=',B,'Q=', Q)\n",
|
" #print('init', 'B=',B,'Q=', Q)\n",
|
||||||
" for k in range(maxiter):\n",
|
" for k in range(maxiter):\n",
|
||||||
" Qk, Rk = decompoQR(B)\n",
|
" Qk, Rk = decompoQR(B)\n",
|
||||||
" B = Rk@Qk\n",
|
" B = Rk@Qk\n",
|
||||||
@@ -67,7 +98,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 56,
|
"execution_count": 79,
|
||||||
"id": "0662681f-fac3-4db2-b296-a6720eb41ad2",
|
"id": "0662681f-fac3-4db2-b296-a6720eb41ad2",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
@@ -82,13 +113,6 @@
|
|||||||
" [0. 1. 2. 1.]\n",
|
" [0. 1. 2. 1.]\n",
|
||||||
" [0. 0. 1. 2.]]\n",
|
" [0. 0. 1. 2.]]\n",
|
||||||
"Valeur propres [3.61803399 2.61803399 0.38196601 1.38196601]\n",
|
"Valeur propres [3.61803399 2.61803399 0.38196601 1.38196601]\n",
|
||||||
"init B= [[2. 1. 0. 0.]\n",
|
|
||||||
" [1. 2. 1. 0.]\n",
|
|
||||||
" [0. 1. 2. 1.]\n",
|
|
||||||
" [0. 0. 1. 2.]] Q= [[1. 0. 0. 0.]\n",
|
|
||||||
" [0. 1. 0. 0.]\n",
|
|
||||||
" [0. 0. 1. 0.]\n",
|
|
||||||
" [0. 0. 0. 1.]]\n",
|
|
||||||
"[3.61803399 2.61803399 1.38196601 0.38196601]\n"
|
"[3.61803399 2.61803399 1.38196601 0.38196601]\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -106,38 +130,19 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 68,
|
"execution_count": 80,
|
||||||
"id": "bfde5aa5-407f-400f-9347-3e1a7a9a47e4",
|
"id": "bfde5aa5-407f-400f-9347-3e1a7a9a47e4",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"init B= [[2. 1. 0. ... 0. 0. 0.]\n",
|
|
||||||
" [1. 2. 1. ... 0. 0. 0.]\n",
|
|
||||||
" [0. 1. 2. ... 0. 0. 0.]\n",
|
|
||||||
" ...\n",
|
|
||||||
" [0. 0. 0. ... 2. 1. 0.]\n",
|
|
||||||
" [0. 0. 0. ... 1. 2. 1.]\n",
|
|
||||||
" [0. 0. 0. ... 0. 1. 2.]] Q= [[1. 0. 0. ... 0. 0. 0.]\n",
|
|
||||||
" [0. 1. 0. ... 0. 0. 0.]\n",
|
|
||||||
" [0. 0. 1. ... 0. 0. 0.]\n",
|
|
||||||
" ...\n",
|
|
||||||
" [0. 0. 0. ... 1. 0. 0.]\n",
|
|
||||||
" [0. 0. 0. ... 0. 1. 0.]\n",
|
|
||||||
" [0. 0. 0. ... 0. 0. 1.]]\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"[]"
|
"[]"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 68,
|
"execution_count": 80,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user