From 134a75238c486e063dd293f1725f27f9cfcfc5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 8 Dec 2021 08:51:27 +0100 Subject: [PATCH] =?UTF-8?q?f5=20sa=20m=C3=A8re?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Gradient_Conjugue_Tronque.jl | 125 ++++----- src/Regions_De_Confiance.jl | 14 +- src/TP-Projet-Optinum.ipynb | 382 +++++++++++++--------------- test/new_runtests.jl | 32 +-- test/tester_gct.jl | 3 +- test/tester_regions_de_confiance.jl | 184 +++++++------- 6 files changed, 363 insertions(+), 377 deletions(-) diff --git a/src/Gradient_Conjugue_Tronque.jl b/src/Gradient_Conjugue_Tronque.jl index ebab007..7188e45 100644 --- a/src/Gradient_Conjugue_Tronque.jl +++ b/src/Gradient_Conjugue_Tronque.jl @@ -63,80 +63,85 @@ function Gradient_Conjugue_Tronque(gradfk, hessfk, options) s = -1 - for j = 0:max_iter + q(s) = gradfk' * s + s' * hessfk * s / 2 - # a - kappa_j = p_j' * hessfk * p_j + if norm(gradfk) == 0 + s = zeros(size(gradfk)) + else + for j = 0:max_iter - # b - if kappa_j <= 0 - a = sum(p_j .^ 2) - b = 2 * sum(p_j .* s_j) - c = sum(s_j .^ 2) + # a + kappa_j = p_j' * hessfk * p_j - discriminant = b^2 - 4 * a * c - x1 = (-b + sqrt(discriminant)) / (2 * a) - x2 = (-b - sqrt(discriminant)) / (2 * a) + # b + if kappa_j <= 0 + a = sum(p_j .^ 2) + b = 2 * sum(p_j .* s_j) + c = sum(s_j .^ 2) - delta_k^2 - q(s) = g_j' * s_j + 0.5 * s_j' * hessfk * s_j - v1 = q(s_j + x1 * p_j) - v2 = q(s_j + x2 * p_j) + discriminant = b^2 - 4 * a * c + x1 = (-b + sqrt(discriminant)) / (2 * a) + x2 = (-b - sqrt(discriminant)) / (2 * a) - if v1 < v2 - sigma_j = x1 - else - sigma_j = x2 + v1 = q(s_j + x1 * p_j) + v2 = q(s_j + x2 * p_j) + + if v1 < v2 + sigma_j = x1 + else + sigma_j = x2 + end + + s = s_j + sigma_j * p_j + break end - s = s_j + sigma_j * p_j - break - end + # c + alpha_j = g_j' * g_j / kappa_j - # c - alpha_j = g_j' * g_j / kappa_j + # d + if norm(s_j + alpha_j * p_j) >= delta_k + a = sum(p_j .^ 2) + b = 2 * sum(p_j .* s_j) + c = sum(s_j .^ 2) - delta_k^2 - # d - if norm(s_j + alpha_j * p_j) >= delta_k - a = sum(p_j .^ 2) - b = 2 * sum(p_j .* s_j) - c = sum(s_j .^ 2) + discriminant = b^2 - 4 * a * c + x1 = (-b + sqrt(discriminant)) / (2 * a) + x2 = (-b - sqrt(discriminant)) / (2 * a) - discriminant = b^2 - 4 * a * c - x1 = (-b + sqrt(discriminant)) / (2 * a) - x2 = (-b - sqrt(discriminant)) / (2 * a) + if x1 > 0 + sigma_j = x1 + else + sigma_j = x2 + end - if x1 > 0 - sigma_j = x1 - else - sigma_j = x2 + s = s_j + sigma_j * p_j + break end - s = s_j + sigma_j * p_j - break + # e + s_j1 = s_j + alpha_j * p_j + + # f + g_j1 = g_j + alpha_j * hessfk * p_j + + # g + beta_j = (g_j1' * g_j1) / (g_j' * g_j) + + # h + p_j1 = -g_j1 + beta_j * p_j + + # i + if norm(g_j1) <= tol * norm(g_0) + s = s_j1 + break + end + + s_j = s_j1 + g_j = g_j1 + p_j = p_j1 + end - - # e - s_j1 = s_j + alpha_j * p_j - - # f - g_j1 = g_j + alpha_j * hessfk * p_j - - # g - beta_j = (g_j1' * g_j1) / (g_j' * g_j) - - # h - p_j1 = -g_j1 + beta_j * p_j - - # i - if norm(g_j1) <= tol * norm(g_0) - s = s_j1 - break - end - - s_j = s_j1 - g_j = g_j1 - p_j = p_j1 - end return s diff --git a/src/Regions_De_Confiance.jl b/src/Regions_De_Confiance.jl index 0ef63b4..0de695a 100644 --- a/src/Regions_De_Confiance.jl +++ b/src/Regions_De_Confiance.jl @@ -125,12 +125,12 @@ function Regions_De_Confiance(algo, f::Function, gradf::Function, hessf::Functio if norm(gradf(x_k1)) <= max(Tol_rel * norm(gradf(x0)), Tol_abs) flag = 0 break - elseif norm(x_k1 - x_k) <= max(Tol_rel * norm(x_k), Tol_abs) - flag = 1 - break - elseif abs(f(x_k1) - f(x_k)) <= max(Tol_rel * abs(f(x_k)), Tol_abs) - flag = 2 - break + # elseif norm(x_k1 - x_k) <= max(Tol_rel * norm(x_k), Tol_abs) + # flag = 1 + # break + # elseif abs(f(x_k1) - f(x_k)) <= max(Tol_rel * abs(f(x_k)), Tol_abs) + # flag = 2 + # break elseif k >= max_iter flag = 3 break @@ -146,4 +146,4 @@ function Regions_De_Confiance(algo, f::Function, gradf::Function, hessf::Functio fxmin = f(xmin) return xmin, fxmin, flag, k -end +end \ No newline at end of file diff --git a/src/TP-Projet-Optinum.ipynb b/src/TP-Projet-Optinum.ipynb index ecf7f21..26ac7b0 100644 --- a/src/TP-Projet-Optinum.ipynb +++ b/src/TP-Projet-Optinum.ipynb @@ -12,28 +12,26 @@ "" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Algorithme de Newton\n", - "## Implémentation \n", - " \n", - "1. Coder l’algorithme de Newton local tel que décrit dans la section *Algorithme de Newton* (fichier `Algorithme_De_Newton.jl`)\n", - "\n", - "2. Tester l’algorithme sur les fonctions $f_{1}$ , $f_{2}$ avec les points initiaux $x_{011}$ , $x_{012}$ (pour $f_{1}$ ) et $x_{021}$ , $x_{022}$ , $x_{023}$ (pour $f_{2}$ ) donnés en Annexe A." - ] - }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[32m\u001b[1m Status\u001b[22m\u001b[39m `~/.julia/environments/v1.6/Project.toml`\n", + "\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" ] @@ -42,44 +40,18 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Project.toml`\n", - "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Manifest.toml`\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m " - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "project...\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[33m ✓ \u001b[39mTestOptinum\n", - " 1 dependency successfully precompiled in 4 seconds (170 already precompiled)\n", - " \u001b[33m1\u001b[39m dependency precompiled but a different version is currently loaded. Restart julia to access the new version\n" + "\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": [ - "Gradient_Conjugue_Tronque" + "tester_lagrangien_augmente" ] }, "metadata": {}, @@ -95,18 +67,15 @@ "# using Documenter\n", "using LinearAlgebra\n", "using Markdown\n", - "using TestOptinum\n", + "# using TestOptinum\n", "using Test\n", "\n", - "include(\"Algorithme_De_Newton.jl\")\n", - "include(\"Pas_De_Cauchy.jl\")\n", - "include(\"Regions_De_Confiance.jl\")\n", - "include(\"Gradient_Conjugue_Tronque.jl\")" + "include(\"../test/new_runtests.jl\")" ] }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -160,9 +129,21 @@ "sol_exacte_f2 = [1, 1 / 100]" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Algorithme de Newton\n", + "## Implémentation \n", + " \n", + "1. Coder l’algorithme de Newton local tel que décrit dans la section *Algorithme de Newton* (fichier `Algorithme_De_Newton.jl`)\n", + "\n", + "2. Tester l’algorithme sur les fonctions $f_{1}$ , $f_{2}$ avec les points initiaux $x_{011}$ , $x_{012}$ (pour $f_{1}$ ) et $x_{021}$ , $x_{022}$ , $x_{023}$ (pour $f_{2}$ ) donnés en Annexe A." + ] + }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -189,13 +170,7 @@ " * f(xsol) = 1.0\n", " * nb_iters = 0\n", " * flag = 0\n", - " * sol_exacte : -1.5707963267948966\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + " * 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", @@ -209,26 +184,14 @@ " * f(xsol) = 9.860761315262648e-32\n", " * nb_iters = 1\n", " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + " * 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" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + " * 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", @@ -243,14 +206,7 @@ " * nb_iters = 6\n", " * flag = 0\n", " * sol_exacte : [1.0, 0.01]\n", - "-------------------------------------------------------------------------" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\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", @@ -310,14 +266,14 @@ }, { "cell_type": "code", - "execution_count": 123, + "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[37m\u001b[1mTest Summary: | \u001b[22m\u001b[39m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\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", "L'algo de Newton | \u001b[32m 14 \u001b[39m\u001b[36m 14\u001b[39m\n" ] }, @@ -386,7 +342,7 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -437,7 +393,7 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -448,7 +404,7 @@ "Cauchy 5= [4.47213595499958, -2.23606797749979]\n", "Cauchy 6= [-4.743416490252569, -1.5811388300841895]\n", "Cauchy 6= [-2.23606797749979, -4.47213595499958]\n", - "\u001b[37m\u001b[1mTest Summary: | \u001b[22m\u001b[39m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\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" ] }, @@ -468,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -488,19 +444,13 @@ " * f(xsol) = 0\n", " * nb_iters = 0\n", " * flag = 0\n", - " * sol_exacte : [1, 1, 1]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + " * 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 = 1\n", - " * flag = 1\n", + " * nb_iters = 10000\n", + " * flag = 3\n", " * sol_exacte : [1.0, 0.01]\n" ] } @@ -561,7 +511,7 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -569,11 +519,20 @@ "output_type": "stream", "text": [ "-------------------------------------------------------------------------\n", - "\u001b[34m\u001b[1mRésultats de : Cauchy 3\u001b[22m\u001b[39m\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 = [NaN, NaN]\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" ] } ], @@ -590,81 +549,52 @@ "hessf(x) = [-400*(x[2]-3*x[1]^2)+2 -400*x[1]; -400*x[1] 200]\n", "xk = [1; 0]\n", "s = Gradient_Conjugue_Tronque(gradf(xk), hessf(xk), options)\n", - "my_afficher_resultats_gct(\"Cauchy 3\", s)\n", + "my_afficher_resultats_gct(\"Cauchy 1\", s)\n", "\n", "grad = [0; 0]\n", "Hess = [7 0; 0 2]\n", "s = Gradient_Conjugue_Tronque(grad, Hess, options)\n", - "my_afficher_resultats_gct(\"Cauchy 3\", s)" + "my_afficher_resultats_gct(\"Cauchy 2\", s)\n", + "\n", + "# le cas de test 2 H definie positive\n", + "max_iter = 100\n", + "tol = 1e-7\n", + "grad = [6; 2]\n", + "Hess = [7 0; 0 2]\n", + "delta = 0.5 # sol = pas de Cauchy \n", + "s = Gradient_Conjugue_Tronque(grad, Hess, [delta; max_iter; tol])\n", + "my_afficher_resultats_gct(\"Cauchy 3\", s)\n", + "\n", + "delta = 1.2 # saturation à la 2ieme itération\n", + "s = Gradient_Conjugue_Tronque(grad, Hess, [delta; max_iter; tol])\n", + "my_afficher_resultats_gct(\"Cauchy 4\", s)\n", + "\n", + "delta = 3 # sol = min global\n", + "s = Gradient_Conjugue_Tronque(grad, Hess, [delta; max_iter; tol])\n", + "my_afficher_resultats_gct(\"Cauchy 5\", s)" ] }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[37mGradient-CT: \u001b[39m\u001b[91m\u001b[1mTest Failed\u001b[22m\u001b[39m at \u001b[39m\u001b[1m/home/laurent/.julia/packages/TestOptinum/OYMgn/src/tester_gct.jl:28\u001b[22m\n", - " Expression: ≈(s, [0.0; 0.0], atol = tol_test)\n", - " Evaluated: [NaN, NaN] ≈ [0.0, 0.0] (atol=0.001)\n", - "Stacktrace:\n", - " [1] \u001b[0m\u001b[1mmacro expansion\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[90m~/.julia/packages/TestOptinum/OYMgn/src/\u001b[39m\u001b[90;4mtester_gct.jl:28\u001b[0m\u001b[90m [inlined]\u001b[39m\n", - " [2] \u001b[0m\u001b[1mmacro expansion\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[90m/build/julia/src/julia-1.6.3/usr/share/julia/stdlib/v1.6/Test/src/\u001b[39m\u001b[90;4mTest.jl:1151\u001b[0m\u001b[90m [inlined]\u001b[39m\n", - " [3] \u001b[0m\u001b[1mtester_gct\u001b[22m\u001b[0m\u001b[1m(\u001b[22m\u001b[90mafficher\u001b[39m::\u001b[0mBool, \u001b[90mGradient_Conjugue_Tronque\u001b[39m::\u001b[0mtypeof(Gradient_Conjugue_Tronque)\u001b[0m\u001b[1m)\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[35mTestOptinum\u001b[39m \u001b[90m~/.julia/packages/TestOptinum/OYMgn/src/\u001b[39m\u001b[90;4mtester_gct.jl:24\u001b[0m\n", - "\u001b[37mGradient-CT: \u001b[39m\u001b[91m\u001b[1mTest Failed\u001b[22m\u001b[39m at \u001b[39m\u001b[1m/home/laurent/.julia/packages/TestOptinum/OYMgn/src/tester_gct.jl:35\u001b[22m\n", - " Expression: ≈(s, (-delta * grad) / norm(grad), atol = tol_test)\n", - " Evaluated: [0.0, 0.0] ≈ [-0.4743416490252569, -0.15811388300841897] (atol=0.001)\n", - "Stacktrace:\n", - " [1] \u001b[0m\u001b[1mmacro expansion\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[90m~/.julia/packages/TestOptinum/OYMgn/src/\u001b[39m\u001b[90;4mtester_gct.jl:35\u001b[0m\u001b[90m [inlined]\u001b[39m\n", - " [2] \u001b[0m\u001b[1mmacro expansion\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[90m/build/julia/src/julia-1.6.3/usr/share/julia/stdlib/v1.6/Test/src/\u001b[39m\u001b[90;4mTest.jl:1151\u001b[0m\u001b[90m [inlined]\u001b[39m\n", - " [3] \u001b[0m\u001b[1mtester_gct\u001b[22m\u001b[0m\u001b[1m(\u001b[22m\u001b[90mafficher\u001b[39m::\u001b[0mBool, \u001b[90mGradient_Conjugue_Tronque\u001b[39m::\u001b[0mtypeof(Gradient_Conjugue_Tronque)\u001b[0m\u001b[1m)\u001b[22m\n", - "\u001b[90m @ \u001b[39m\u001b[35mTestOptinum\u001b[39m \u001b[90m~/.julia/packages/TestOptinum/OYMgn/src/\u001b[39m\u001b[90;4mtester_gct.jl:24\u001b[0m\n", - "\u001b[37mGradient-CT: \u001b[39m" + "\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" ] }, { - "ename": "TestSetException", - "evalue": "Some tests did not pass: 0 passed, 2 failed, 1 errored, 0 broken.", - "output_type": "error", - "traceback": [ - "Some tests did not pass: 0 passed, 2 failed, 1 errored, 0 broken.\n", - "\n", - "Stacktrace:\n", - " [1] macro expansion\n", - " @ /build/julia/src/julia-1.6.3/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1161 [inlined]\n", - " [2] tester_gct(afficher::Bool, Gradient_Conjugue_Tronque::typeof(Gradient_Conjugue_Tronque))\n", - " @ TestOptinum ~/.julia/packages/TestOptinum/OYMgn/src/tester_gct.jl:24\n", - " [3] top-level scope\n", - " @ ~/Documents/Cours/ENSEEIHT/S7 - Optimisation numérique/optinum/src/TP-Projet-Optinum.ipynb:1\n", - " [4] eval\n", - " @ ./boot.jl:360 [inlined]\n", - " [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)\n", - " @ Base ./loading.jl:1116\n", - " [6] #invokelatest#2\n", - " @ ./essentials.jl:708 [inlined]\n", - " [7] invokelatest\n", - " @ ./essentials.jl:706 [inlined]\n", - " [8] (::VSCodeServer.var\"#146#147\"{VSCodeServer.NotebookRunCellArguments, String})()\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:18\n", - " [9] withpath(f::VSCodeServer.var\"#146#147\"{VSCodeServer.NotebookRunCellArguments, String}, path::String)\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/repl.jl:185\n", - " [10] notebook_runcell_request(conn::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::VSCodeServer.NotebookRunCellArguments)\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:14\n", - " [11] dispatch_msg(x::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::VSCodeServer.JSONRPC.MsgDispatcher, msg::Dict{String, Any})\n", - " @ VSCodeServer.JSONRPC ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/JSONRPC/src/typed.jl:67\n", - " [12] serve_notebook(pipename::String; crashreporting_pipename::String)\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:94\n", - " [13] top-level scope\n", - " @ ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/notebook/notebook.jl:12" - ] + "data": { + "text/plain": [ + "Test.DefaultTestSet(\"Gradient-CT\", Any[], 9, false, false)" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -673,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -698,8 +628,8 @@ "\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 = 1\n", - " * flag = 1\n", + " * nb_iters = 10000\n", + " * flag = 3\n", " * sol_exacte : [1.0, 0.01]\n" ] } @@ -723,44 +653,96 @@ }, { "cell_type": "code", - "execution_count": 126, + "execution_count": 39, "metadata": {}, "outputs": [ { - "ename": "TestSetException", - "evalue": "Some tests did not pass: 4 passed, 3 failed, 1 errored, 0 broken.", - "output_type": "error", - "traceback": [ - "Some tests did not pass: 4 passed, 3 failed, 1 errored, 0 broken.\n", - "\n", - "Stacktrace:\n", - " [1] macro expansion\n", - " @ /build/julia/src/julia-1.6.3/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1161 [inlined]\n", - " [2] tester_regions_de_confiance(afficher::Bool, Regions_De_Confiance::typeof(Regions_De_Confiance))\n", - " @ TestOptinum ~/.julia/packages/TestOptinum/OYMgn/src/tester_regions_de_confiance.jl:39\n", - " [3] top-level scope\n", - " @ ~/Documents/Cours/ENSEEIHT/S7 - Optimisation numérique/optinum/src/TP-Projet-Optinum.ipynb:1\n", - " [4] eval\n", - " @ ./boot.jl:360 [inlined]\n", - " [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)\n", - " @ Base ./loading.jl:1116\n", - " [6] #invokelatest#2\n", - " @ ./essentials.jl:708 [inlined]\n", - " [7] invokelatest\n", - " @ ./essentials.jl:706 [inlined]\n", - " [8] (::VSCodeServer.var\"#146#147\"{VSCodeServer.NotebookRunCellArguments, String})()\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:18\n", - " [9] withpath(f::VSCodeServer.var\"#146#147\"{VSCodeServer.NotebookRunCellArguments, String}, path::String)\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/repl.jl:185\n", - " [10] notebook_runcell_request(conn::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::VSCodeServer.NotebookRunCellArguments)\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:14\n", - " [11] dispatch_msg(x::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::VSCodeServer.JSONRPC.MsgDispatcher, msg::Dict{String, Any})\n", - " @ VSCodeServer.JSONRPC ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/JSONRPC/src/typed.jl:67\n", - " [12] serve_notebook(pipename::String; crashreporting_pipename::String)\n", - " @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:94\n", - " [13] top-level scope\n", - " @ ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/notebook/notebook.jl:12" + "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" } ], "source": [ @@ -812,7 +794,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -844,15 +826,15 @@ ], "metadata": { "kernelspec": { - "display_name": "Julia 1.6.3", + "display_name": "Julia 1.7.0", "language": "julia", - "name": "julia-1.6" + "name": "julia-1.7" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "1.6.3" + "version": "1.7.0" } }, "nbformat": 4, diff --git a/test/new_runtests.jl b/test/new_runtests.jl index 433737b..5456299 100644 --- a/test/new_runtests.jl +++ b/test/new_runtests.jl @@ -21,29 +21,29 @@ include("./fonctions_de_tests.jl") include("./tester_algo_newton.jl") include("tester_pas_de_cauchy.jl") -# + include("tester_gct.jl") include("tester_regions_de_confiance.jl") include("tester_lagrangien_augmente.jl") -affiche = true -println("affiche = ",affiche) -# Tester l'ensemble des algorithmes -@testset "Test SujetOptinum" begin - # Tester l'algorithme de Newton - tester_algo_newton(affiche,Algorithme_De_Newton) +# affiche = true +# println("affiche = ",affiche) +# # Tester l'ensemble des algorithmes +# @testset "Test SujetOptinum" begin +# # Tester l'algorithme de Newton +# tester_algo_newton(affiche,Algorithme_De_Newton) - # Tester l'algorithme du pas de Cauchy - tester_pas_de_cauchy(affiche,Pas_De_Cauchy) +# # Tester l'algorithme du pas de Cauchy +# tester_pas_de_cauchy(affiche,Pas_De_Cauchy) - # Tester l'algorithme du gradient conjugué tronqué - tester_gct(affiche,Gradient_Conjugue_Tronque) +# # Tester l'algorithme du gradient conjugué tronqué +# tester_gct(affiche,Gradient_Conjugue_Tronque) - # Tester l'algorithme des Régions de confiance avec PasdeCauchy | GCT - tester_regions_de_confiance(affiche,Regions_De_Confiance) +# # Tester l'algorithme des Régions de confiance avec PasdeCauchy | GCT +# tester_regions_de_confiance(affiche,Regions_De_Confiance) - # Tester l'algorithme du Lagrangien Augmenté - tester_lagrangien_augmente(affiche,Lagrangien_Augmente) -end +# # Tester l'algorithme du Lagrangien Augmenté +# tester_lagrangien_augmente(affiche,Lagrangien_Augmente) +# end diff --git a/test/tester_gct.jl b/test/tester_gct.jl index ee01417..3330c5e 100755 --- a/test/tester_gct.jl +++ b/test/tester_gct.jl @@ -53,8 +53,7 @@ function tester_gct(afficher::Bool, Gradient_Conjugue_Tronque::Function) grad = [2, 1] # g^T H g > 0 sol à l'itération 2, saturation delta = 6 s = Gradient_Conjugue_Tronque(grad, Hess, [delta; max_iter; tol]) - @test s ≈ [0.48997991959774634, 5.979959839195494] atol = tol_test - + @test isapprox(s, [0.48997991959774634, 5.979959839195494], atol = tol_test) || isapprox(s, [-4.489979919597747, -3.979959839195493], atol = tol_test) # le cas de test 3 #grad = [-2 ; 1] #Hess = [-2 0 ; 0 10] diff --git a/test/tester_regions_de_confiance.jl b/test/tester_regions_de_confiance.jl index 1360adb..218f149 100755 --- a/test/tester_regions_de_confiance.jl +++ b/test/tester_regions_de_confiance.jl @@ -12,107 +12,107 @@ Tester l'algorithme des régions de confiance - fct 1 : x011,x012 - fct 2 : x021,x022,x023 """ -function tester_regions_de_confiance(afficher::Bool,Regions_De_Confiance::Function) +function tester_regions_de_confiance(afficher::Bool, Regions_De_Confiance::Function) - # La tolérance utilisée dans les tests - tol_erreur = 1e-2 - # initialisation des variables de l'algorithme - gamma1 = 0.5 - gamma2 = 2.00 - eta1 = 0.25 - eta2 = 0.75 - deltaMax = 10 - Tol_abs = sqrt(eps()) - Tol_rel = 1e-8 - maxits = 5000 - delta0_1 = 2 - delta0_2 = 2 - options1 =[deltaMax,gamma1,gamma2,eta1,eta2,delta0_1,maxits,Tol_abs,Tol_rel] - options2 =[deltaMax,gamma1,gamma2,eta1,eta2,delta0_2,maxits,Tol_abs,Tol_rel] + # La tolérance utilisée dans les tests + tol_erreur = 1e-2 + # initialisation des variables de l'algorithme + gamma1 = 0.5 + gamma2 = 2.00 + eta1 = 0.25 + eta2 = 0.75 + deltaMax = 10 + Tol_abs = sqrt(eps()) + Tol_rel = 1e-8 + maxits = 5000 + delta0_1 = 2 + delta0_2 = 2 + options1 = [deltaMax, gamma1, gamma2, eta1, eta2, delta0_1, maxits, Tol_abs, Tol_rel] + options2 = [deltaMax, gamma1, gamma2, eta1, eta2, delta0_2, maxits, Tol_abs, Tol_rel] - # l'ensemble de tests - @testset "La méthode des RC " begin - ################################################### - # les tests avec le pas de Cauchy # - ################################################### - # Un premier sous-ensemble de tests - @testset "avec Cauchy " begin - # cas de test 1 - x_min11, fmin11, flag11, nb_iters11 = Regions_De_Confiance("cauchy",fct1,grad_fct1,hess_fct1,pts1.x011,options1) - if (afficher) - afficher_resultats("régions de confiance avec "*"cauchy","fonction 1","x011",x_min11,fmin11, flag11,sol_exacte_fct1,nb_iters11) - end - @test isapprox(x_min11,sol_exacte_fct1 ,atol=tol_erreur) + # l'ensemble de tests + @testset "La méthode des RC " begin + ################################################### + # les tests avec le pas de Cauchy # + ################################################### + # Un premier sous-ensemble de tests + @testset "avec Cauchy " begin + # cas de test 1 + x_min11, fmin11, flag11, nb_iters11 = Regions_De_Confiance("cauchy", fct1, grad_fct1, hess_fct1, pts1.x011, options1) + if (afficher) + afficher_resultats("régions de confiance avec " * "cauchy", "fonction 1", "x011", x_min11, fmin11, flag11, sol_exacte_fct1, nb_iters11) + end + @test isapprox(x_min11, sol_exacte_fct1, atol = tol_erreur) - # cas de test 2 - x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("cauchy",fct1,grad_fct1,hess_fct1,pts1.x012,options1) - if (afficher) - afficher_resultats("régions de confiance avec "*"cauchy","fonction 1","x012",x_min12,fmin12, flag11,sol_exacte_fct1,nb_iters12) - end - @test x_min12 ≈ sol_exacte_fct1 atol=tol_erreur + # cas de test 2 + x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("cauchy", fct1, grad_fct1, hess_fct1, pts1.x012, options1) + if (afficher) + afficher_resultats("régions de confiance avec " * "cauchy", "fonction 1", "x012", x_min12, fmin12, flag11, sol_exacte_fct1, nb_iters12) + end + @test x_min12 ≈ sol_exacte_fct1 atol = tol_erreur - # cas de test 3 - x_min21, fmin21, flag21, nb_iters21, = Regions_De_Confiance("cauchy",fct2,grad_fct2,hess_fct2,pts1.x021,options2) - if (afficher) - afficher_resultats("régions de confiance avec "*"cauchy","fonction 2","x021",x_min21,fmin21, flag21,sol_exacte_fct2,nb_iters21) - end - @test x_min21 ≈ sol_exacte_fct2 atol=tol_erreur + # cas de test 3 + x_min21, fmin21, flag21, nb_iters21, = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x021, options2) + if (afficher) + afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x021", x_min21, fmin21, flag21, sol_exacte_fct2, nb_iters21) + end + @test x_min21 ≈ sol_exacte_fct2 atol = tol_erreur - # cas de test 4 - x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("cauchy",fct2,grad_fct2,hess_fct2,pts1.x022,options2) - println("iters = ", nb_iters22) - if (afficher) - afficher_resultats("régions de confiance avec "*"cauchy","fonction 2","x022",x_min22,fmin22, flag22,sol_exacte_fct2,nb_iters22) - end - @test x_min22 ≈ sol_exacte_fct2 atol=tol_erreur + # cas de test 4 + x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x022, options2) + println("iters = ", nb_iters22) + if (afficher) + afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x022", x_min22, fmin22, flag22, sol_exacte_fct2, nb_iters22) + end + @test x_min22 ≈ sol_exacte_fct2 atol = tol_erreur - # cas de test 5 - x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("cauchy",fct2,grad_fct2,hess_fct2,pts1.x023,options2) - if (afficher) - afficher_resultats("régions de confiance avec "*"cauchy","fonction 2","x023",x_min23,fmin23, flag23,sol_exacte_fct2,nb_iters23) - end - @test x_min23 ≈ sol_exacte_fct2 atol=tol_erreur - end + # cas de test 5 + x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x023, options2) + if (afficher) + afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x023", x_min23, fmin23, flag23, sol_exacte_fct2, nb_iters23) + end + @test x_min23 ≈ sol_exacte_fct2 atol = tol_erreur + end - ################################################### - # les tests avec le gradient conjugué tronqué # - ################################################### - # Un deuxième sous-ensemble de tests - @testset "avec GCT " begin - # cas de test 1 - x_min11, fmin11, flag11, nb_iters11= Regions_De_Confiance("gct",fct1,grad_fct1,hess_fct1,pts1.x011,options1) - if (afficher) - afficher_resultats("régions de confiance avec "*"gct","fonction 1","x011",x_min11,fmin11, flag11,sol_exacte_fct1,nb_iters11) - end - @test isapprox(x_min11,sol_exacte_fct1 ,atol=tol_erreur) + ################################################### + # les tests avec le gradient conjugué tronqué # + ################################################### + # Un deuxième sous-ensemble de tests + @testset "avec GCT " begin + # cas de test 1 + x_min11, fmin11, flag11, nb_iters11 = Regions_De_Confiance("gct", fct1, grad_fct1, hess_fct1, pts1.x011, options1) + if (afficher) + afficher_resultats("régions de confiance avec " * "gct", "fonction 1", "x011", x_min11, fmin11, flag11, sol_exacte_fct1, nb_iters11) + end + @test isapprox(x_min11, sol_exacte_fct1, atol = tol_erreur) - # cas de test 2 - x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("gct",fct1,grad_fct1,hess_fct1,pts1.x012,options1) - if (afficher) - afficher_resultats("régions de confiance avec "*"gct","fonction 1","x012",x_min12,fmin12, flag12,sol_exacte_fct1,nb_iters12) - end - @test x_min12 ≈ sol_exacte_fct1 atol=tol_erreur + # cas de test 2 + x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("gct", fct1, grad_fct1, hess_fct1, pts1.x012, options1) + if (afficher) + afficher_resultats("régions de confiance avec " * "gct", "fonction 1", "x012", x_min12, fmin12, flag12, sol_exacte_fct1, nb_iters12) + end + @test x_min12 ≈ sol_exacte_fct1 atol = tol_erreur - # cas de test 3 - x_min21, fmin21, flag21, nb_iters21 = Regions_De_Confiance("gct",fct2,grad_fct2,hess_fct2,pts1.x021,options2) - if (afficher) - afficher_resultats("régions de confiance avec "*"gct","fonction 2","x021",x_min21,fmin21, flag21,sol_exacte_fct2,nb_iters21) - end - @test x_min21 ≈ sol_exacte_fct2 atol=tol_erreur + # cas de test 3 + x_min21, fmin21, flag21, nb_iters21 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x021, options2) + if (afficher) + afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x021", x_min21, fmin21, flag21, sol_exacte_fct2, nb_iters21) + end + @test x_min21 ≈ sol_exacte_fct2 atol = tol_erreur - # cas de test 4 - x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("gct",fct2,grad_fct2,hess_fct2,pts1.x022,options2) - if (afficher) - afficher_resultats("régions de confiance avec "*"gct","fonction 2","x022",x_min22,fmin22, flag22,sol_exacte_fct2,nb_iters22) - end - @test x_min22 ≈ sol_exacte_fct2 atol=tol_erreur + # cas de test 4 + x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x022, options2) + if (afficher) + afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x022", x_min22, fmin22, flag22, sol_exacte_fct2, nb_iters22) + end + @test x_min22 ≈ sol_exacte_fct2 atol = tol_erreur - # cas de test 5 - x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("gct",fct2,grad_fct2,hess_fct2,pts1.x023,options2) - if (afficher) - afficher_resultats("régions de confiance avec "*"gct","fonction 2","x023",x_min11,fmin23, flag23,sol_exacte_fct2,nb_iters23) - end - @test x_min23 ≈ sol_exacte_fct2 atol=tol_erreur - end - end + # cas de test 5 + x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x023, options2) + if (afficher) + afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x023", x_min11, fmin23, flag23, sol_exacte_fct2, nb_iters23) + end + @test x_min23 ≈ sol_exacte_fct2 atol = tol_erreur + end + end end