mise à jour
This commit is contained in:
10
TP02/EXOS.md
Normal file
10
TP02/EXOS.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
### Exercice 3 :
|
||||||
|
- C : le criminel à un complice
|
||||||
|
- K : le criminel à la clé
|
||||||
|
- V : le criminel est en voiture
|
||||||
|
|
||||||
|
- C => V
|
||||||
|
- (-C^-K)v(K^C)
|
||||||
|
- K
|
||||||
|
|
||||||
|
Q = (-CvV)^
|
57
TP03/.ipynb_checkpoints/Exercices-checkpoint.ipynb
Normal file
57
TP03/.ipynb_checkpoints/Exercices-checkpoint.ipynb
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Exercice 1 : Calcul de dérivées"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "NameError",
|
||||||
|
"evalue": "name 'sp' is not defined",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"Cell \u001b[1;32mIn[1], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m \n\u001b[1;32m----> 3\u001b[0m x \u001b[38;5;241m=\u001b[39m sp\u001b[38;5;241m.\u001b[39msumbools(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mx\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(x)\n",
|
||||||
|
"\u001b[1;31mNameError\u001b[0m: name 'sp' is not defined"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import numpy as np \n",
|
||||||
|
"\n",
|
||||||
|
"x = np.sumbools('x')\n",
|
||||||
|
"\n",
|
||||||
|
"print(x)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "base",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
255
TP03/Exercices.ipynb
Normal file
255
TP03/Exercices.ipynb
Normal file
File diff suppressed because one or more lines are too long
6
TP04/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Normal file
6
TP04/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"cells": [],
|
||||||
|
"metadata": {},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
173
TP04/Untitled.ipynb
Normal file
173
TP04/Untitled.ipynb
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "c49056b3-e2c2-471d-b998-14eb1cd1a082",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Exercice 1 : \n",
|
||||||
|
"Autre fonctions d'erreurs : \n",
|
||||||
|
"- Erreur résiduelle : ei = f(xi)-yi\n",
|
||||||
|
"- Erreur logarithmique : ei = log(1+|f(xi)-yi|)\n",
|
||||||
|
"- Erreur relative : ei = (f(xi)-yi)/yi\n",
|
||||||
|
"\n",
|
||||||
|
"# Exercice 2 : \n",
|
||||||
|
"Autre fonctions de couts : \n",
|
||||||
|
"- Erreur Log-Cosh, Log-Cosh est similaire à MAE pour de petites erreurs\n",
|
||||||
|
"- Erreur Huber (𝛿=1), Huber réduit l’impact des grandes erreurs\n",
|
||||||
|
"- Erreur de Poisson, Poisson est adaptée aux distributions asymétriques\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "3aa6d565-ac05-48ca-9f10-ece048a7eff2",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Exercice 3 : \n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 84,
|
||||||
|
"id": "d8b00644-a239-44ba-9b4c-4982e624227f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"iteration = 1\n",
|
||||||
|
"a= 50 b= 75\n",
|
||||||
|
"iteration = 2\n",
|
||||||
|
"a= -25.75309997451889 b= 74.9568945\n",
|
||||||
|
"iteration = 3\n",
|
||||||
|
"a= 13.539805289078245 b= 74.97929653630847\n",
|
||||||
|
"iteration = 4\n",
|
||||||
|
"a= -6.841306604859323 b= 74.9677200103882\n",
|
||||||
|
"iteration = 5\n",
|
||||||
|
"a= 3.730314856415273 b= 74.97376806255475\n",
|
||||||
|
"iteration = 6\n",
|
||||||
|
"a= -1.7531534482568194 b= 74.9706742990146\n",
|
||||||
|
"iteration = 7\n",
|
||||||
|
"a= 1.0911050566712879 b= 74.97232236778468\n",
|
||||||
|
"iteration = 8\n",
|
||||||
|
"a= -0.3842033063747208 b= 74.97151086236455\n",
|
||||||
|
"iteration = 9\n",
|
||||||
|
"a= 0.3810346829632343 b= 74.97197513066288\n",
|
||||||
|
"iteration = 10\n",
|
||||||
|
"a= -0.015891986938224745 b= 74.97177765894565\n",
|
||||||
|
"iteration = 11\n",
|
||||||
|
"a= 0.1899926591360049 b= 74.9719234297637\n",
|
||||||
|
"iteration = 12\n",
|
||||||
|
"a= 0.08320088730389696 b= 74.97189116168829\n",
|
||||||
|
"iteration = 13\n",
|
||||||
|
"a= 0.13859343372153637 b= 74.97195124182983\n",
|
||||||
|
"iteration = 14\n",
|
||||||
|
"a= 0.10986146169209325 b= 74.97196342120678\n",
|
||||||
|
"iteration = 15\n",
|
||||||
|
"a= 0.12476462455318163 b= 74.97200044654436\n",
|
||||||
|
"iteration = 16\n",
|
||||||
|
"a= 0.1170343740876787 b= 74.97202458433483\n",
|
||||||
|
"iteration = 17\n",
|
||||||
|
"a= 0.12104400709218902 b= 74.97205540683525\n",
|
||||||
|
"iteration = 18\n",
|
||||||
|
"a= 0.11896419782388343 b= 74.97208276197472\n",
|
||||||
|
"iteration = 19\n",
|
||||||
|
"a= 0.12004296396127893 b= 74.97211191560189\n",
|
||||||
|
"Paramètre a : 0.11948338652853815\n",
|
||||||
|
"Paramètre b : 74.97214013633689\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import numpy as np\n",
|
||||||
|
"\n",
|
||||||
|
"# Données d'exemple (à remplacer par vos propres données)\n",
|
||||||
|
"# xi : les valeurs d'entrée\n",
|
||||||
|
"# yi : les valeurs de sortie cibles\n",
|
||||||
|
"xi = np.array([313, 2384, 342, 420]) # Exemple\n",
|
||||||
|
"yi = np.array([124, 339, 179, 186]) # Exemple\n",
|
||||||
|
"\n",
|
||||||
|
"# Hyperparamètres\n",
|
||||||
|
"alpha = 0.000001 # Taux d'apprentissage\n",
|
||||||
|
"m = len(xi) # Nombre d'exemples\n",
|
||||||
|
"\n",
|
||||||
|
"# Initialisation des paramètres\n",
|
||||||
|
"a = 50 # Paramètre a initial\n",
|
||||||
|
"b = 75 # Paramètre b initial\n",
|
||||||
|
"\n",
|
||||||
|
"# Seuils d'arrêt\n",
|
||||||
|
"epsilon_threshold = 1e-3\n",
|
||||||
|
"\n",
|
||||||
|
"# Initialisation des erreurs\n",
|
||||||
|
"epsilon_1 = float('inf')\n",
|
||||||
|
"epsilon_2 = float('inf')\n",
|
||||||
|
"tmp = 0\n",
|
||||||
|
"\n",
|
||||||
|
"# Boucle principale\n",
|
||||||
|
"while epsilon_1 > epsilon_threshold or epsilon_2 > epsilon_threshold:\n",
|
||||||
|
" a_prev = a\n",
|
||||||
|
" b_prev = b\n",
|
||||||
|
" tmp += 1\n",
|
||||||
|
" print(\"iteration = \",tmp)\n",
|
||||||
|
" print(\"a=\",a,\" b=\",b)\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" # Calcul des gradients et mise à jour des paramètres\n",
|
||||||
|
" b = b - alpha * (1 / m) * np.sum(a * xi + b - yi)\n",
|
||||||
|
" a = a - alpha * (1 / m) * np.sum((a * xi + b - yi) * xi)\n",
|
||||||
|
"\n",
|
||||||
|
" # Calcul des erreurs\n",
|
||||||
|
" epsilon_1 = abs(a_prev - a)\n",
|
||||||
|
" epsilon_2 = abs(b_prev - b)\n",
|
||||||
|
"\n",
|
||||||
|
"# Résultats finaux\n",
|
||||||
|
"print(f\"Paramètre a : {a}\")\n",
|
||||||
|
"print(f\"Paramètre b : {b}\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "10a19dd5-878c-4b92-b0e1-9b3324bb3407",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"| Itération | A | B |\n",
|
||||||
|
"| :--------------- |:---------------:| -----:|\n",
|
||||||
|
"| 1 | 50 | 75 |\n",
|
||||||
|
"| 9 | 0.38103 | 74.97197 |\n",
|
||||||
|
"| 19 | 0.12004 | 74.97214 |"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "d86080eb-bab5-4a25-bf98-2446840313f6",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3 (ipykernel)",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
Reference in New Issue
Block a user