From 87f0432a3d76ee3d3600b97aa30b7bd545a858bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 15 Dec 2021 16:35:53 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20lagrangien=20augment=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lagrangien_Augmente.jl | 43 ++-- src/TP-Projet-Optinum.ipynb | 474 ++++++------------------------------ 2 files changed, 106 insertions(+), 411 deletions(-) diff --git a/src/Lagrangien_Augmente.jl b/src/Lagrangien_Augmente.jl index babb400..3ca707f 100755 --- a/src/Lagrangien_Augmente.jl +++ b/src/Lagrangien_Augmente.jl @@ -4,7 +4,7 @@ Résolution des problèmes de minimisation sous cs d'égalités # Syntaxe ```julia Lagrangien_Augmente(algo,f,c,gradf,hessf,grad_c, - hess_c,x0,options) + hess_c,x_0,options) ``` # Entrées @@ -18,7 +18,7 @@ Lagrangien_Augmente(algo,f,c,gradf,hessf,grad_c, * **hessf** : (Function) la hessienne de la ftion * **grad_c** : (Function) le gradient de la c * **hess_c** : (Function) la hessienne de la c - * **x0** : (Array{Float,1}) la première composante du point de départ du Lagrangien + * **x_0** : (Array{Float,1}) la première composante du point de départ du Lagrangien * **options** : (Array{Float,1}) 1. **epsilon** : utilisé dans les critères d'arrêt 2. **tol** : la tolérance utilisée dans les critères d'arrêt @@ -42,15 +42,15 @@ f(x)=100*(x[2]-x[1]^2)^2+(1-x[1])^2 gradf(x)=[-400*x[1]*(x[2]-x[1]^2)-2*(1-x[1]) ; 200*(x[2]-x[1]^2)] hessf(x)=[-400*(x[2]-3*x[1]^2)+2 -400*x[1];-400*x[1] 200] algo = "gct" # ou newton|gct -x0 = [1; 0] +x_0 = [1; 0] options = [] c(x) = (x[1]^2) + (x[2]^2) -1.5 grad_c(x) = [2*x[1] ;2*x[2]] hess_c(x) = [2 0;0 2] -output = Lagrangien_Augmente(algo,f,c,gradf,hessf,grad_c,hess_c,x0,options) +output = Lagrangien_Augmente(algo,f,c,gradf,hessf,grad_c,hess_c,x_0,options) ``` """ -function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, hessf::Function, grad_c::Function, hess_c::Function, x0, options) +function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, hessf::Function, grad_c::Function, hess_c::Function, x_0, options) if options == [] epsilon = 1e-8 @@ -68,11 +68,14 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he tau = options[6] end - n = length(x0) - flag = -1 + delta = 2 # TODO: changer ? - L(x, lambda, mu) = f(x) + lambda' * c(x) + mu / 2 * norm(c(x))^2 - gradL(x, lambda, mu) = gradf(x) + lambda' * grad_c(x) + mu / 2 * c(x) # à vérifier + _L(x, lambda, mu) = f(x) + lambda' * c(x) + mu / 2 * norm(c(x))^2 + _gradL(x, lambda, mu) = gradf(x) + lambda' * grad_c(x) + mu * c(x) * grad_c(x) + _hessL(x, lambda, mu) = hessf(x) + lambda' * hess_c(x) + mu * (c(x) * hess_c(x) + grad_c(x) * grad_c(x)') + + n = length(x_0) + flag = -1 eta_chap_0 = 0.1258925 alpha = 0.1 @@ -82,22 +85,26 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he k = 0 x_k = x_0 + x_k1 = x_0 lambda_k = lambda_0 mu_k = mu_0 + eta_k = eta_0 + epsilon_k = epsilon_0 while true + L(x) = _L(x, lambda_k, mu_k) + gradL(x) = _gradL(x, lambda_k, mu_k) + hessL(x) = _hessL(x, lambda_k, mu_k) + # a if algo == "newton" - x_k1, _, _, _ = Algorithme_De_Newton(L, gradL, hessL, x_k, options) - # A FINIR - elseif algo == "cauchy" - s_k = Gradient_Conjugue_Tronque(gradf(x_k), hessf(x_k), [delta_k max_iter Tol_rel]) - elseif algo == "gct" - s_k, e_k = Pas_De_Cauchy(gradf(x_k), hessf(x_k), delta_k) + x_k1, _, _, _ = Algorithme_De_Newton(L, gradL, hessL, x_k, [itermax epsilon tol]) + elseif algo == "cauchy" || algo == "gct" + x_k1, _, _, _ = Regions_De_Confiance(algo, L, gradL, hessL, x_k, [10 0.5 2 0.25 0.75 2 itermax epsilon tol]) end - if norm(c_k1) <= eta_k # b + if norm(c(x_k1)) <= eta_k # b lambda_k1 = lambda_k + mu_k * c(x_k1) mu_k1 = mu_k epsilon_k1 = epsilon_k / mu_k @@ -110,7 +117,7 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he end - if norm(gradL(x_k, lambda_k, 0)) <= max(tol * norm(gradL(x_0, lambda_0, 0)), epsilon) && norm(c(x_k)) <= max(tol * norm(c(x_0), epsilon)) + if norm(_gradL(x_k, lambda_k, 0)) <= max(tol * norm(_gradL(x_0, lambda_0, 0)), epsilon) && norm(c(x_k)) <= max(tol * norm(c(x_0), epsilon)) flag = 0 break elseif k >= max_iter @@ -125,7 +132,7 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he end - xmin = xkp1 + xmin = x_k1 f_min = f(xmin) return xmin, f_min, flag, k end diff --git a/src/TP-Projet-Optinum.ipynb b/src/TP-Projet-Optinum.ipynb index 1fe3dc9..1e739dd 100644 --- a/src/TP-Projet-Optinum.ipynb +++ b/src/TP-Projet-Optinum.ipynb @@ -14,50 +14,9 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\u001b[90m @ \u001b[39m\u001b[90m~/Documents/Cours/ENSEEIHT/S7 - Optimisation numérique/optinum/test/\u001b[39m\u001b[90m\u001b[4mtester_regions_de_confiance.jl:83\u001b[24m\u001b[39m\u001b[90m [inlined]\u001b[39m\n", - " [5] \u001b[0m\u001b[1mmacro expansion\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[90m/usr/share/julia/stdlib/v1.7/Test/src/\u001b[39m\u001b[90m\u001b[4mTest.jl:1283\u001b[24m\u001b[39m\u001b[90m [inlined]\u001b[39m\n", - " [6] \u001b[0m\u001b[1mtester_regions_de_confiance\u001b[22m\u001b[0m\u001b[1m(\u001b[22m\u001b[90mafficher\u001b[39m::\u001b[0mBool, \u001b[90mRegions_De_Confiance\u001b[39m::\u001b[0mtypeof(Regions_De_Confiance)\u001b[0m\u001b[1m)\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[35mMain\u001b[39m \u001b[90m~/Documents/Cours/ENSEEIHT/S7 - Optimisation numérique/optinum/test/\u001b[39m\u001b[90m\u001b[4mtester_regions_de_confiance.jl:39\u001b[24m\u001b[39m\n", - "\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[91m\u001b[1mFail \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n", - "La méthode des RC | \u001b[32m 5 \u001b[39m\u001b[91m 5 \u001b[39m\u001b[36m 10\u001b[39m\n", - " avec Cauchy | \u001b[32m 3 \u001b[39m\u001b[91m 2 \u001b[39m\u001b[36m 5\u001b[39m\n", - " avec GCT | \u001b[32m 2 \u001b[39m\u001b[91m 3 \u001b[39m\u001b[36m 5\u001b[39m\n", - "\u001b[32m\u001b[1m Status\u001b[22m\u001b[39m `~/.julia/environments/v1.7/Project.toml`\n", - " \u001b[90m [0c46a032] \u001b[39mDifferentialEquations v6.20.0\n", - " \u001b[90m [a6016688] \u001b[39mTestOptinum v0.1.0 `https://github.com/mathn7/TestOptinum.git#master`\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", - "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Project.toml`\n", - "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Manifest.toml`\n", - "\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n", - "\u001b[32m ✓ \u001b[39mTestOptinum\n", - " 1 dependency successfully precompiled in 1 seconds (169 already precompiled, 2 skipped during auto due to previous errors)\n" - ] - }, - { - "data": { - "text/plain": [ - "tester_lagrangien_augmente" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "using Pkg\n", "Pkg.status()\n", @@ -75,21 +34,9 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2-element Vector{Float64}:\n", - " 1.0\n", - " 0.01" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "# Fonction f0\n", "# -----------\n", @@ -143,79 +90,9 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f0 au point initial -1.5707963267948966:\u001b[22m\u001b[39m\n", - " * xsol = -1.5707963267948966\n", - " * f(xsol) = -1.0\n", - " * nb_iters = 0\n", - " * flag = 0\n", - " * sol_exacte : -1.5707963267948966\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f0 au point initial -1.0707963267948966:\u001b[22m\u001b[39m\n", - " * xsol = -1.5707963267949088\n", - " * f(xsol) = -1.0\n", - " * nb_iters = 3\n", - " * flag = 0\n", - " * sol_exacte : -1.5707963267948966\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f0 au point initial 1.5707963267948966:\u001b[22m\u001b[39m\n", - " * xsol = 1.5707963267948966\n", - " * f(xsol) = 1.0\n", - " * nb_iters = 0\n", - " * flag = 0\n", - " * sol_exacte : -1.5707963267948966\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f1 au point initial [1, 1, 1]:\u001b[22m\u001b[39m\n", - " * xsol = [1, 1, 1]\n", - " * f(xsol) = 0\n", - " * nb_iters = 0\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f1 au point initial [1, 0, 0]:\u001b[22m\u001b[39m\n", - " * xsol = [1.0000000000000002, 1.0, 0.9999999999999998]\n", - " * f(xsol) = 9.860761315262648e-32\n", - " * nb_iters = 1\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f1 au point initial [10.0, 3.0, -2.2]:\u001b[22m\u001b[39m\n", - " * xsol = [1.0, 0.9999999999999996, 0.9999999999999982]\n", - " * f(xsol) = 1.1832913578315177e-29\n", - " * nb_iters = 1\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f2 au point initial [1.0, 0.01]:\u001b[22m\u001b[39m\n", - " * xsol = [1.0, 1.0]\n", - " * f(xsol) = 9801.0\n", - " * nb_iters = 1\n", - " * flag = 0\n", - " * sol_exacte : [1.0, 0.01]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f2 au point initial [-1.2, 1.0]:\u001b[22m\u001b[39m\n", - " * xsol = [1.0000000000000238, 0.9999999999815201]\n", - " * f(xsol) = 9800.999999634088\n", - " * nb_iters = 6\n", - " * flag = 0\n", - " * sol_exacte : [1.0, 0.01]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Newton appliqué à f2 au point initial [10, 0]:\u001b[22m\u001b[39m\n", - " * xsol = [1.000000000000007, 1.0000000000000142]\n", - " * f(xsol) = 9801.000000000278\n", - " * nb_iters = 5\n", - " * flag = 0\n", - " * sol_exacte : [1.0, 0.01]\n" - ] - } - ], + "outputs": [], "source": [ "# Affichage les sorties de l'algorithme de Newton\n", "function my_afficher_resultats(algo, nom_fct, point_init, xmin, fxmin, flag, sol_exacte, nbiters)\n", @@ -266,27 +143,9 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n", - "L'algo de Newton | \u001b[32m 14 \u001b[39m\u001b[36m 14\u001b[39m\n" - ] - }, - { - "data": { - "text/plain": [ - "Test.DefaultTestSet(\"L'algo de Newton\", Any[Test.DefaultTestSet(\"Cas test 1 x0 = solution\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 1 x0 = x011\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 1 x0 = x012\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = solution\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x021\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x022\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x023\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"exception\", Any[], 1, false, false)], 0, false, false)], 0, false, false)" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "tester_algo_newton(false, Algorithme_De_Newton)" ] @@ -342,28 +201,9 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 1\u001b[22m\u001b[39m\n", - " * s = [0, 0]\n", - " * e = 0\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 2\u001b[22m\u001b[39m\n", - " * s = [-0.9230769230769234, -0.30769230769230776]\n", - " * e = 1\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 3\u001b[22m\u001b[39m\n", - " * s = [0.8944271909999159, -0.4472135954999579]\n", - " * e = -1\n" - ] - } - ], + "outputs": [], "source": [ "function my_afficher_resultats_cauchy(algo, s, e)\n", " println(\"-------------------------------------------------------------------------\")\n", @@ -393,68 +233,18 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Cauchy 4 = [5.000000000000001, -2.5000000000000004]\n", - "Cauchy 5= [4.47213595499958, -2.23606797749979]\n", - "Cauchy 6= [-4.743416490252569, -1.5811388300841895]\n", - "Cauchy 6= [-2.23606797749979, -4.47213595499958]\n", - "\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n", - "Pas de Cauchy | \u001b[32m 7 \u001b[39m\u001b[36m 7\u001b[39m\n" - ] - }, - { - "data": { - "text/plain": [ - "Test.DefaultTestSet(\"Pas de Cauchy\", Any[Test.DefaultTestSet(\"g = 0\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 2, non saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 2, saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, non saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, g'*H*g <0 saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, g'*H*g = 0 saturé\", Any[], 1, false, false)], 0, false, false)" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "tester_pas_de_cauchy(false, Pas_De_Cauchy)" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : RC-Cauchy appliqué à f0 au point initial -1.5707963267948966:\u001b[22m\u001b[39m\n", - " * xsol = -1.5707963267948966\n", - " * f(xsol) = -1.0\n", - " * nb_iters = 0\n", - " * flag = 0\n", - " * sol_exacte : -1.5707963267948966\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : RC-Cauchy appliqué à f1 au point initial [1, 1, 1]:\u001b[22m\u001b[39m\n", - " * xsol = [1, 1, 1]\n", - " * f(xsol) = 0\n", - " * nb_iters = 0\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : RC-Cauchy appliqué à f2 au point initial [1.0, 0.01]:\u001b[22m\u001b[39m\n", - " * xsol = [1.0, 0.01]\n", - " * f(xsol) = 0.0\n", - " * nb_iters = 10000\n", - " * flag = 3\n", - " * sol_exacte : [1.0, 0.01]\n" - ] - } - ], + "outputs": [], "source": [ "options = [10, 0.5, 2.00, 0.25, 0.75, 2, 10000, sqrt(eps()), 1e-15]\n", "algo = \"cauchy\"\n", @@ -511,31 +301,9 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 1\u001b[22m\u001b[39m\n", - " * s = [2.220446049250313e-16, 1.0]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 2\u001b[22m\u001b[39m\n", - " * s = [0.0, 0.0]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 3\u001b[22m\u001b[39m\n", - " * s = [-0.4743416490252569, -0.15811388300841897]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 4\u001b[22m\u001b[39m\n", - " * s = [-0.8740776099190263, -0.8221850958502243]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 5\u001b[22m\u001b[39m\n", - " * s = [-0.8571428571428571, -0.9999999999999998]\n" - ] - } - ], + "outputs": [], "source": [ "function my_afficher_resultats_gct(algo, s)\n", " println(\"-------------------------------------------------------------------------\")\n", @@ -576,64 +344,18 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n", - "Gradient-CT | \u001b[32m 9 \u001b[39m\u001b[36m 9\u001b[39m\n" - ] - }, - { - "data": { - "text/plain": [ - "Test.DefaultTestSet(\"Gradient-CT\", Any[], 9, false, false)" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "tester_gct(false, Gradient_Conjugue_Tronque)" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : RC-GCT appliqué à f0 au point initial -1.5707963267948966:\u001b[22m\u001b[39m\n", - " * xsol = -1.5707963267948966\n", - " * f(xsol) = -1.0\n", - " * nb_iters = 0\n", - " * flag = 0\n", - " * sol_exacte : -1.5707963267948966\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : RC-GCT appliqué à f1 au point initial [1, 1, 1]:\u001b[22m\u001b[39m\n", - " * xsol = [1, 1, 1]\n", - " * f(xsol) = 0\n", - " * nb_iters = 0\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : RC-GCT appliqué à f2 au point initial [1.0, 0.01]:\u001b[22m\u001b[39m\n", - " * xsol = [1.0, 0.01]\n", - " * f(xsol) = 0.0\n", - " * nb_iters = 10000\n", - " * flag = 3\n", - " * sol_exacte : [1.0, 0.01]\n" - ] - } - ], + "outputs": [], "source": [ "options = [10, 0.5, 2.00, 0.25, 0.75, 2, 10000, sqrt(eps()), 1e-15]\n", "algo = \"gct\"\n", @@ -653,100 +375,11 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec cauchy appliqué à fonction 1 au point initial x011 :\u001b[22m\u001b[39m\n", - " * xsol = [1.0000000310867154, 0.9999999957837182, 0.999999960480721]\n", - " * f(xsol) = 2.812589785349316e-15\n", - " * nb_iters = 48\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec cauchy appliqué à fonction 1 au point initial x012 :\u001b[22m\u001b[39m\n", - " * xsol = [1.0000001114825787, 0.9999999912691591, 0.9999998710557396]\n", - " * f(xsol) = 3.027462898391515e-14\n", - " * nb_iters = 42\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec cauchy appliqué à fonction 2 au point initial x021 :\u001b[22m\u001b[39m\n", - " * xsol = [0.9993529197795769, 0.9987042941099483]\n", - " * f(xsol) = 4.1909860490578263e-7\n", - " * nb_iters = 5000\n", - " * flag = 3\n", - " * sol_exacte : [1, 1]\n", - "iters = 864\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec cauchy appliqué à fonction 2 au point initial x022 :\u001b[22m\u001b[39m\n", - " * xsol = [0.9961677295964368, 0.9923393628804894]\n", - " * f(xsol) = 1.4697922911344958e-5\n", - " * nb_iters = 864\n", - " * flag = 0\n", - " * sol_exacte : [1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec cauchy appliqué à fonction 2 au point initial x023 :\u001b[22m\u001b[39m\n", - " * xsol = [0.9999372227331438, 0.9998738531186088]\n", - " * f(xsol) = 3.9765412510183685e-9\n", - " * nb_iters = 5000\n", - " * flag = 3\n", - " * sol_exacte : [1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec gct appliqué à fonction 1 au point initial x011 :\u001b[22m\u001b[39m\n", - " * xsol = [1.0000000000000007, 1.0, 1.0]\n", - " * f(xsol) = 2.0214560696288428e-30\n", - " * nb_iters = 1\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec gct appliqué à fonction 1 au point initial x012 :\u001b[22m\u001b[39m\n", - " * xsol = [0.9999999999999996, 1.0000000000000002, 1.0000000000000004]\n", - " * f(xsol) = 4.930380657631324e-31\n", - " * nb_iters = 3\n", - " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec gct appliqué à fonction 2 au point initial x021 :\u001b[22m\u001b[39m\n", - " * xsol = [0.9999996743780089, 0.9999993478371609]\n", - " * f(xsol) = 1.0611413038132374e-13\n", - " * nb_iters = 31\n", - " * flag = 0\n", - " * sol_exacte : [1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec gct appliqué à fonction 2 au point initial x022 :\u001b[22m\u001b[39m\n", - " * xsol = [1.0000035183009863, 1.0000066949336202]\n", - " * f(xsol) = 2.4053014026923312e-11\n", - " * nb_iters = 44\n", - " * flag = 0\n", - " * sol_exacte : [1, 1]\n", - "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : régions de confiance avec gct appliqué à fonction 2 au point initial x023 :\u001b[22m\u001b[39m\n", - " * xsol = [1.0000000000000007, 1.0, 1.0]\n", - " * f(xsol) = 3.1813581453548166e-24\n", - " * nb_iters = 19\n", - " * flag = 0\n", - " * sol_exacte : [1, 1]\n", - "\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n", - "La méthode des RC | \u001b[32m 10 \u001b[39m\u001b[36m 10\u001b[39m\n" - ] - }, - { - "data": { - "text/plain": [ - "Test.DefaultTestSet(\"La méthode des RC \", Any[Test.DefaultTestSet(\"avec Cauchy \", Any[], 5, false, false), Test.DefaultTestSet(\"avec GCT \", Any[], 5, false, false)], 0, false, false)" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ - "tester_regions_de_confiance(true, Regions_De_Confiance)" + "tester_regions_de_confiance(false, Regions_De_Confiance)" ] }, { @@ -772,7 +405,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Vos réponses?\n" + "1. dqzd\n", + "2. dzqd\n", + "3. 3dqzdzd\n", + "4. dqzd" ] }, { @@ -794,11 +430,63 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Vos tests" + "function afficher_resultats(algo,nom_fct,point_init,xmin,fxmin,flag,sol_exacte,nbiters)\n", + "\tprintln(\"-------------------------------------------------------------------------\")\n", + "\tprintstyled(\"Résultats de : \"*algo*\" appliqué à \"*nom_fct*\" au point initial \"*point_init*\" :\\n\",bold=true,color=:blue)\n", + "\tprintln(\" * xsol = \",xmin)\n", + "\tprintln(\" * f(xsol) = \",fxmin)\n", + "\tprintln(\" * nb_iters = \",nbiters)\n", + "\tprintln(\" * flag = \",flag)\n", + "\tprintln(\" * sol_exacte : \", sol_exacte)\n", + "end\n", + "\n", + "fct1(x) = 2 * (x[1] + x[2] + x[3] - 3)^2 + (x[1] - x[2])^2 + (x[2] - x[3])^2\n", + "# la gradient de la fonction fct1\n", + "function grad_fct1(x)\n", + " y1 = 4 * (x[1] + x[2] + x[3] - 3) + 2 * (x[1] - x[2])\n", + " y2 = 4 * (x[1] + x[2] + x[3] - 3) - 2 * (x[1] - x[2]) + 2 * (x[2] - x[3])\n", + " y3 = 4 * (x[1] + x[2] + x[3] - 3) - 2 * (x[2] - x[3])\n", + " return [y1; y2; y3]\n", + "end\n", + "# la hessienne de la fonction fct1\n", + "hess_fct1(x) = [6 2 4; 2 8 2; 4 2 6]\n", + "\n", + "contrainte1(x) = x[1] + x[3] - 1\n", + "grad_contrainte1(x) = [1; 0; 1]\n", + "hess_contrainte1(x) = [0 0 0; 0 0 0; 0 0 0]\n", + "\n", + "x01 = [0; 1; 1]\n", + "x02 = [0.5; 1.25; 1]\n", + "x03 = [1; 0]\n", + "x04 = [sqrt(3) / 2; sqrt(3) / 2]\n", + "pts2 = Pts_avec_contraintes(x01, x02, x03, x04)\n", + "\n", + "# sol_fct1_augm = [0.5 ; 1.25 ; 0.5]\n", + "\n", + "algo = \"newton\"\n", + "xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct1, contrainte1, grad_fct1, hess_fct1, grad_contrainte1, hess_contrainte1, pts2.x01, options)\n", + "afficher_resultats(\"Lagrangien augmenté avec \" * algo, \"fonction 1\", \"x01\", xmin, fxmin, flag, sol_fct1_augm, nbiters)\n", + "\n", + "algo = \"cauchy\"\n", + "xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct1, contrainte1, grad_fct1, hess_fct1, grad_contrainte1, hess_contrainte1, pts2.x01, options)\n", + "afficher_resultats(\"Lagrangien augmenté avec \" * algo, \"fonction 1\", \"x01\", xmin, fxmin, flag, sol_fct1_augm, nbiters)\n", + "\n", + "algo = \"gct\"\n", + "xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct1, contrainte1, grad_fct1, hess_fct1, grad_contrainte1, hess_contrainte1, pts2.x01, options)\n", + "afficher_resultats(\"Lagrangien augmenté avec \" * algo, \"fonction 1\", \"x01\", xmin, fxmin, flag, sol_fct1_augm, nbiters)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tester_lagrangien_augmente(false, Lagrangien_Augmente)" ] }, {