f5 sa mère

This commit is contained in:
Laureηt 2021-12-08 08:51:27 +01:00
parent a9fa860b74
commit 134a75238c
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
6 changed files with 363 additions and 377 deletions

View file

@ -63,6 +63,11 @@ function Gradient_Conjugue_Tronque(gradfk, hessfk, options)
s = -1 s = -1
q(s) = gradfk' * s + s' * hessfk * s / 2
if norm(gradfk) == 0
s = zeros(size(gradfk))
else
for j = 0:max_iter for j = 0:max_iter
# a # a
@ -72,13 +77,12 @@ function Gradient_Conjugue_Tronque(gradfk, hessfk, options)
if kappa_j <= 0 if kappa_j <= 0
a = sum(p_j .^ 2) a = sum(p_j .^ 2)
b = 2 * sum(p_j .* s_j) b = 2 * sum(p_j .* s_j)
c = sum(s_j .^ 2) c = sum(s_j .^ 2) - delta_k^2
discriminant = b^2 - 4 * a * c discriminant = b^2 - 4 * a * c
x1 = (-b + sqrt(discriminant)) / (2 * a) x1 = (-b + sqrt(discriminant)) / (2 * a)
x2 = (-b - sqrt(discriminant)) / (2 * a) x2 = (-b - sqrt(discriminant)) / (2 * a)
q(s) = g_j' * s_j + 0.5 * s_j' * hessfk * s_j
v1 = q(s_j + x1 * p_j) v1 = q(s_j + x1 * p_j)
v2 = q(s_j + x2 * p_j) v2 = q(s_j + x2 * p_j)
@ -99,7 +103,7 @@ function Gradient_Conjugue_Tronque(gradfk, hessfk, options)
if norm(s_j + alpha_j * p_j) >= delta_k if norm(s_j + alpha_j * p_j) >= delta_k
a = sum(p_j .^ 2) a = sum(p_j .^ 2)
b = 2 * sum(p_j .* s_j) b = 2 * sum(p_j .* s_j)
c = sum(s_j .^ 2) c = sum(s_j .^ 2) - delta_k^2
discriminant = b^2 - 4 * a * c discriminant = b^2 - 4 * a * c
x1 = (-b + sqrt(discriminant)) / (2 * a) x1 = (-b + sqrt(discriminant)) / (2 * a)
@ -138,6 +142,7 @@ function Gradient_Conjugue_Tronque(gradfk, hessfk, options)
p_j = p_j1 p_j = p_j1
end end
end
return s return s
end end

View file

@ -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) if norm(gradf(x_k1)) <= max(Tol_rel * norm(gradf(x0)), Tol_abs)
flag = 0 flag = 0
break break
elseif norm(x_k1 - x_k) <= max(Tol_rel * norm(x_k), Tol_abs) # elseif norm(x_k1 - x_k) <= max(Tol_rel * norm(x_k), Tol_abs)
flag = 1 # flag = 1
break # break
elseif abs(f(x_k1) - f(x_k)) <= max(Tol_rel * abs(f(x_k)), Tol_abs) # elseif abs(f(x_k1) - f(x_k)) <= max(Tol_rel * abs(f(x_k)), Tol_abs)
flag = 2 # flag = 2
break # break
elseif k >= max_iter elseif k >= max_iter
flag = 3 flag = 3
break break

View file

@ -12,28 +12,26 @@
"</center>" "</center>"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Algorithme de Newton\n",
"## Implémentation \n",
" \n",
"1. Coder lalgorithme de Newton local tel que décrit dans la section *Algorithme de Newton* (fichier `Algorithme_De_Newton.jl`)\n",
"\n",
"2. Tester lalgorithme 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", "cell_type": "code",
"execution_count": 78, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "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 [0c46a032] \u001b[39mDifferentialEquations v6.20.0\n",
" \u001b[90m [a6016688] \u001b[39mTestOptinum v0.1.0 `https://github.com/mathn7/TestOptinum.git#master`\n" " \u001b[90m [a6016688] \u001b[39mTestOptinum v0.1.0 `https://github.com/mathn7/TestOptinum.git#master`\n"
] ]
@ -42,44 +40,18 @@
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\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",
"name": "stderr", "\u001b[32m ✓ \u001b[39mTestOptinum\n",
"output_type": "stream", " 1 dependency successfully precompiled in 1 seconds (169 already precompiled, 2 skipped during auto due to previous errors)\n"
"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"
] ]
}, },
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"Gradient_Conjugue_Tronque" "tester_lagrangien_augmente"
] ]
}, },
"metadata": {}, "metadata": {},
@ -95,18 +67,15 @@
"# using Documenter\n", "# using Documenter\n",
"using LinearAlgebra\n", "using LinearAlgebra\n",
"using Markdown\n", "using Markdown\n",
"using TestOptinum\n", "# using TestOptinum\n",
"using Test\n", "using Test\n",
"\n", "\n",
"include(\"Algorithme_De_Newton.jl\")\n", "include(\"../test/new_runtests.jl\")"
"include(\"Pas_De_Cauchy.jl\")\n",
"include(\"Regions_De_Confiance.jl\")\n",
"include(\"Gradient_Conjugue_Tronque.jl\")"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 101, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -160,9 +129,21 @@
"sol_exacte_f2 = [1, 1 / 100]" "sol_exacte_f2 = [1, 1 / 100]"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Algorithme de Newton\n",
"## Implémentation \n",
" \n",
"1. Coder lalgorithme de Newton local tel que décrit dans la section *Algorithme de Newton* (fichier `Algorithme_De_Newton.jl`)\n",
"\n",
"2. Tester lalgorithme 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", "cell_type": "code",
"execution_count": 102, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -189,13 +170,7 @@
" * f(xsol) = 1.0\n", " * f(xsol) = 1.0\n",
" * nb_iters = 0\n", " * nb_iters = 0\n",
" * flag = 0\n", " * flag = 0\n",
" * sol_exacte : -1.5707963267948966\n" " * sol_exacte : -1.5707963267948966\n",
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------------------------------------------------------------\n", "-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à f1 au point initial [1, 1, 1]:\u001b[22m\u001b[39m\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", " * xsol = [1, 1, 1]\n",
@ -209,26 +184,14 @@
" * f(xsol) = 9.860761315262648e-32\n", " * f(xsol) = 9.860761315262648e-32\n",
" * nb_iters = 1\n", " * nb_iters = 1\n",
" * flag = 0\n", " * flag = 0\n",
" * sol_exacte : [1, 1, 1]\n" " * sol_exacte : [1, 1, 1]\n",
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------------------------------------------------------------\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", "\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", " * xsol = [1.0, 0.9999999999999996, 0.9999999999999982]\n",
" * f(xsol) = 1.1832913578315177e-29\n", " * f(xsol) = 1.1832913578315177e-29\n",
" * nb_iters = 1\n", " * nb_iters = 1\n",
" * flag = 0\n", " * flag = 0\n",
" * sol_exacte : [1, 1, 1]\n" " * sol_exacte : [1, 1, 1]\n",
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------------------------------------------------------------\n", "-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à f2 au point initial [1.0, 0.01]:\u001b[22m\u001b[39m\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", " * xsol = [1.0, 1.0]\n",
@ -243,14 +206,7 @@
" * nb_iters = 6\n", " * nb_iters = 6\n",
" * flag = 0\n", " * flag = 0\n",
" * sol_exacte : [1.0, 0.01]\n", " * sol_exacte : [1.0, 0.01]\n",
"-------------------------------------------------------------------------" "-------------------------------------------------------------------------\n",
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à f2 au point initial [10, 0]:\u001b[22m\u001b[39m\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", " * xsol = [1.000000000000007, 1.0000000000000142]\n",
" * f(xsol) = 9801.000000000278\n", " * f(xsol) = 9801.000000000278\n",
@ -310,14 +266,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 123, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "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" "L'algo de Newton | \u001b[32m 14 \u001b[39m\u001b[36m 14\u001b[39m\n"
] ]
}, },
@ -386,7 +342,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 105, "execution_count": 33,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -437,7 +393,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 122, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -448,7 +404,7 @@
"Cauchy 5= [4.47213595499958, -2.23606797749979]\n", "Cauchy 5= [4.47213595499958, -2.23606797749979]\n",
"Cauchy 6= [-4.743416490252569, -1.5811388300841895]\n", "Cauchy 6= [-4.743416490252569, -1.5811388300841895]\n",
"Cauchy 6= [-2.23606797749979, -4.47213595499958]\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" "Pas de Cauchy | \u001b[32m 7 \u001b[39m\u001b[36m 7\u001b[39m\n"
] ]
}, },
@ -468,7 +424,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 108, "execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -488,19 +444,13 @@
" * f(xsol) = 0\n", " * f(xsol) = 0\n",
" * nb_iters = 0\n", " * nb_iters = 0\n",
" * flag = 0\n", " * flag = 0\n",
" * sol_exacte : [1, 1, 1]\n" " * sol_exacte : [1, 1, 1]\n",
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------------------------------------------------------------\n", "-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : RC-Cauchy appliqué à f2 au point initial [1.0, 0.01]:\u001b[22m\u001b[39m\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", " * xsol = [1.0, 0.01]\n",
" * f(xsol) = 0.0\n", " * f(xsol) = 0.0\n",
" * nb_iters = 1\n", " * nb_iters = 10000\n",
" * flag = 1\n", " * flag = 3\n",
" * sol_exacte : [1.0, 0.01]\n" " * sol_exacte : [1.0, 0.01]\n"
] ]
} }
@ -561,7 +511,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 119, "execution_count": 36,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -569,11 +519,20 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"-------------------------------------------------------------------------\n", "-------------------------------------------------------------------------\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", " * s = [2.220446049250313e-16, 1.0]\n",
"-------------------------------------------------------------------------\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", "\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", "hessf(x) = [-400*(x[2]-3*x[1]^2)+2 -400*x[1]; -400*x[1] 200]\n",
"xk = [1; 0]\n", "xk = [1; 0]\n",
"s = Gradient_Conjugue_Tronque(gradf(xk), hessf(xk), options)\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", "\n",
"grad = [0; 0]\n", "grad = [0; 0]\n",
"Hess = [7 0; 0 2]\n", "Hess = [7 0; 0 2]\n",
"s = Gradient_Conjugue_Tronque(grad, Hess, options)\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", "cell_type": "code",
"execution_count": 121, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "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", "\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n",
" Expression: ≈(s, [0.0; 0.0], atol = tol_test)\n", "Gradient-CT | \u001b[32m 9 \u001b[39m\u001b[36m 9\u001b[39m\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"
] ]
}, },
{ {
"ename": "TestSetException", "data": {
"evalue": "Some tests did not pass: 0 passed, 2 failed, 1 errored, 0 broken.", "text/plain": [
"output_type": "error", "Test.DefaultTestSet(\"Gradient-CT\", Any[], 9, false, false)"
"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"
] ]
},
"metadata": {},
"output_type": "display_data"
} }
], ],
"source": [ "source": [
@ -673,7 +603,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 124, "execution_count": 38,
"metadata": {}, "metadata": {},
"outputs": [ "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", "\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", " * xsol = [1.0, 0.01]\n",
" * f(xsol) = 0.0\n", " * f(xsol) = 0.0\n",
" * nb_iters = 1\n", " * nb_iters = 10000\n",
" * flag = 1\n", " * flag = 3\n",
" * sol_exacte : [1.0, 0.01]\n" " * sol_exacte : [1.0, 0.01]\n"
] ]
} }
@ -723,44 +653,96 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 126, "execution_count": 39,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "TestSetException", "name": "stdout",
"evalue": "Some tests did not pass: 4 passed, 3 failed, 1 errored, 0 broken.", "output_type": "stream",
"output_type": "error", "text": [
"traceback": [ "-------------------------------------------------------------------------\n",
"Some tests did not pass: 4 passed, 3 failed, 1 errored, 0 broken.\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",
"\n", " * xsol = [1.0000000310867154, 0.9999999957837182, 0.999999960480721]\n",
"Stacktrace:\n", " * f(xsol) = 2.812589785349316e-15\n",
" [1] macro expansion\n", " * nb_iters = 48\n",
" @ /build/julia/src/julia-1.6.3/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1161 [inlined]\n", " * flag = 0\n",
" [2] tester_regions_de_confiance(afficher::Bool, Regions_De_Confiance::typeof(Regions_De_Confiance))\n", " * sol_exacte : [1, 1, 1]\n",
" @ TestOptinum ~/.julia/packages/TestOptinum/OYMgn/src/tester_regions_de_confiance.jl:39\n", "-------------------------------------------------------------------------\n",
" [3] top-level scope\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",
" @ ~/Documents/Cours/ENSEEIHT/S7 - Optimisation numérique/optinum/src/TP-Projet-Optinum.ipynb:1\n", " * xsol = [1.0000001114825787, 0.9999999912691591, 0.9999998710557396]\n",
" [4] eval\n", " * f(xsol) = 3.027462898391515e-14\n",
" @ ./boot.jl:360 [inlined]\n", " * nb_iters = 42\n",
" [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)\n", " * flag = 0\n",
" @ Base ./loading.jl:1116\n", " * sol_exacte : [1, 1, 1]\n",
" [6] #invokelatest#2\n", "-------------------------------------------------------------------------\n",
" @ ./essentials.jl:708 [inlined]\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",
" [7] invokelatest\n", " * xsol = [0.9993529197795769, 0.9987042941099483]\n",
" @ ./essentials.jl:706 [inlined]\n", " * f(xsol) = 4.1909860490578263e-7\n",
" [8] (::VSCodeServer.var\"#146#147\"{VSCodeServer.NotebookRunCellArguments, String})()\n", " * nb_iters = 5000\n",
" @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:18\n", " * flag = 3\n",
" [9] withpath(f::VSCodeServer.var\"#146#147\"{VSCodeServer.NotebookRunCellArguments, String}, path::String)\n", " * sol_exacte : [1, 1]\n",
" @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/repl.jl:185\n", "iters = 864\n",
" [10] notebook_runcell_request(conn::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::VSCodeServer.NotebookRunCellArguments)\n", "-------------------------------------------------------------------------\n",
" @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:14\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",
" [11] dispatch_msg(x::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::VSCodeServer.JSONRPC.MsgDispatcher, msg::Dict{String, Any})\n", " * xsol = [0.9961677295964368, 0.9923393628804894]\n",
" @ VSCodeServer.JSONRPC ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/JSONRPC/src/typed.jl:67\n", " * f(xsol) = 1.4697922911344958e-5\n",
" [12] serve_notebook(pipename::String; crashreporting_pipename::String)\n", " * nb_iters = 864\n",
" @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/packages/VSCodeServer/src/serve_notebook.jl:94\n", " * flag = 0\n",
" [13] top-level scope\n", " * sol_exacte : [1, 1]\n",
" @ ~/.vscode/extensions/julialang.language-julia-1.5.6/scripts/notebook/notebook.jl:12" "-------------------------------------------------------------------------\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": [ "source": [
@ -812,7 +794,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 40,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -844,15 +826,15 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Julia 1.6.3", "display_name": "Julia 1.7.0",
"language": "julia", "language": "julia",
"name": "julia-1.6" "name": "julia-1.7"
}, },
"language_info": { "language_info": {
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.6.3" "version": "1.7.0"
} }
}, },
"nbformat": 4, "nbformat": 4,

View file

@ -21,29 +21,29 @@ include("./fonctions_de_tests.jl")
include("./tester_algo_newton.jl") include("./tester_algo_newton.jl")
include("tester_pas_de_cauchy.jl") include("tester_pas_de_cauchy.jl")
#
include("tester_gct.jl") include("tester_gct.jl")
include("tester_regions_de_confiance.jl") include("tester_regions_de_confiance.jl")
include("tester_lagrangien_augmente.jl") include("tester_lagrangien_augmente.jl")
affiche = true # affiche = true
println("affiche = ",affiche) # println("affiche = ",affiche)
# Tester l'ensemble des algorithmes # # Tester l'ensemble des algorithmes
@testset "Test SujetOptinum" begin # @testset "Test SujetOptinum" begin
# Tester l'algorithme de Newton # # Tester l'algorithme de Newton
tester_algo_newton(affiche,Algorithme_De_Newton) # tester_algo_newton(affiche,Algorithme_De_Newton)
# Tester l'algorithme du pas de Cauchy # # Tester l'algorithme du pas de Cauchy
tester_pas_de_cauchy(affiche,Pas_De_Cauchy) # tester_pas_de_cauchy(affiche,Pas_De_Cauchy)
# Tester l'algorithme du gradient conjugué tronqué # # Tester l'algorithme du gradient conjugué tronqué
tester_gct(affiche,Gradient_Conjugue_Tronque) # tester_gct(affiche,Gradient_Conjugue_Tronque)
# Tester l'algorithme des Régions de confiance avec PasdeCauchy | GCT # # Tester l'algorithme des Régions de confiance avec PasdeCauchy | GCT
tester_regions_de_confiance(affiche,Regions_De_Confiance) # tester_regions_de_confiance(affiche,Regions_De_Confiance)
# Tester l'algorithme du Lagrangien Augmenté # # Tester l'algorithme du Lagrangien Augmenté
tester_lagrangien_augmente(affiche,Lagrangien_Augmente) # tester_lagrangien_augmente(affiche,Lagrangien_Augmente)
end # end

View file

@ -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 grad = [2, 1] # g^T H g > 0 sol à l'itération 2, saturation
delta = 6 delta = 6
s = Gradient_Conjugue_Tronque(grad, Hess, [delta; max_iter; tol]) 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 # le cas de test 3
#grad = [-2 ; 1] #grad = [-2 ; 1]
#Hess = [-2 0 ; 0 10] #Hess = [-2 0 ; 0 10]

View file

@ -12,7 +12,7 @@ Tester l'algorithme des régions de confiance
- fct 1 : x011,x012 - fct 1 : x011,x012
- fct 2 : x021,x022,x023 - 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 # La tolérance utilisée dans les tests
tol_erreur = 1e-2 tol_erreur = 1e-2
@ -27,8 +27,8 @@ function tester_regions_de_confiance(afficher::Bool,Regions_De_Confiance::Functi
maxits = 5000 maxits = 5000
delta0_1 = 2 delta0_1 = 2
delta0_2 = 2 delta0_2 = 2
options1 =[deltaMax,gamma1,gamma2,eta1,eta2,delta0_1,maxits,Tol_abs,Tol_rel] 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] options2 = [deltaMax, gamma1, gamma2, eta1, eta2, delta0_2, maxits, Tol_abs, Tol_rel]
# l'ensemble de tests # l'ensemble de tests
@testset "La méthode des RC " begin @testset "La méthode des RC " begin
@ -38,40 +38,40 @@ function tester_regions_de_confiance(afficher::Bool,Regions_De_Confiance::Functi
# Un premier sous-ensemble de tests # Un premier sous-ensemble de tests
@testset "avec Cauchy " begin @testset "avec Cauchy " begin
# cas de test 1 # cas de test 1
x_min11, fmin11, flag11, nb_iters11 = Regions_De_Confiance("cauchy",fct1,grad_fct1,hess_fct1,pts1.x011,options1) x_min11, fmin11, flag11, nb_iters11 = Regions_De_Confiance("cauchy", fct1, grad_fct1, hess_fct1, pts1.x011, options1)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"cauchy","fonction 1","x011",x_min11,fmin11, flag11,sol_exacte_fct1,nb_iters11) afficher_resultats("régions de confiance avec " * "cauchy", "fonction 1", "x011", x_min11, fmin11, flag11, sol_exacte_fct1, nb_iters11)
end end
@test isapprox(x_min11,sol_exacte_fct1 ,atol=tol_erreur) @test isapprox(x_min11, sol_exacte_fct1, atol = tol_erreur)
# cas de test 2 # cas de test 2
x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("cauchy",fct1,grad_fct1,hess_fct1,pts1.x012,options1) x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("cauchy", fct1, grad_fct1, hess_fct1, pts1.x012, options1)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"cauchy","fonction 1","x012",x_min12,fmin12, flag11,sol_exacte_fct1,nb_iters12) afficher_resultats("régions de confiance avec " * "cauchy", "fonction 1", "x012", x_min12, fmin12, flag11, sol_exacte_fct1, nb_iters12)
end end
@test x_min12 sol_exacte_fct1 atol=tol_erreur @test x_min12 sol_exacte_fct1 atol = tol_erreur
# cas de test 3 # cas de test 3
x_min21, fmin21, flag21, nb_iters21, = Regions_De_Confiance("cauchy",fct2,grad_fct2,hess_fct2,pts1.x021,options2) x_min21, fmin21, flag21, nb_iters21, = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x021, options2)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"cauchy","fonction 2","x021",x_min21,fmin21, flag21,sol_exacte_fct2,nb_iters21) afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x021", x_min21, fmin21, flag21, sol_exacte_fct2, nb_iters21)
end end
@test x_min21 sol_exacte_fct2 atol=tol_erreur @test x_min21 sol_exacte_fct2 atol = tol_erreur
# cas de test 4 # cas de test 4
x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("cauchy",fct2,grad_fct2,hess_fct2,pts1.x022,options2) x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x022, options2)
println("iters = ", nb_iters22) println("iters = ", nb_iters22)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"cauchy","fonction 2","x022",x_min22,fmin22, flag22,sol_exacte_fct2,nb_iters22) afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x022", x_min22, fmin22, flag22, sol_exacte_fct2, nb_iters22)
end end
@test x_min22 sol_exacte_fct2 atol=tol_erreur @test x_min22 sol_exacte_fct2 atol = tol_erreur
# cas de test 5 # cas de test 5
x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("cauchy",fct2,grad_fct2,hess_fct2,pts1.x023,options2) x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x023, options2)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"cauchy","fonction 2","x023",x_min23,fmin23, flag23,sol_exacte_fct2,nb_iters23) afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x023", x_min23, fmin23, flag23, sol_exacte_fct2, nb_iters23)
end end
@test x_min23 sol_exacte_fct2 atol=tol_erreur @test x_min23 sol_exacte_fct2 atol = tol_erreur
end end
################################################### ###################################################
@ -80,39 +80,39 @@ function tester_regions_de_confiance(afficher::Bool,Regions_De_Confiance::Functi
# Un deuxième sous-ensemble de tests # Un deuxième sous-ensemble de tests
@testset "avec GCT " begin @testset "avec GCT " begin
# cas de test 1 # cas de test 1
x_min11, fmin11, flag11, nb_iters11= Regions_De_Confiance("gct",fct1,grad_fct1,hess_fct1,pts1.x011,options1) x_min11, fmin11, flag11, nb_iters11 = Regions_De_Confiance("gct", fct1, grad_fct1, hess_fct1, pts1.x011, options1)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"gct","fonction 1","x011",x_min11,fmin11, flag11,sol_exacte_fct1,nb_iters11) afficher_resultats("régions de confiance avec " * "gct", "fonction 1", "x011", x_min11, fmin11, flag11, sol_exacte_fct1, nb_iters11)
end end
@test isapprox(x_min11,sol_exacte_fct1 ,atol=tol_erreur) @test isapprox(x_min11, sol_exacte_fct1, atol = tol_erreur)
# cas de test 2 # cas de test 2
x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("gct",fct1,grad_fct1,hess_fct1,pts1.x012,options1) x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("gct", fct1, grad_fct1, hess_fct1, pts1.x012, options1)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"gct","fonction 1","x012",x_min12,fmin12, flag12,sol_exacte_fct1,nb_iters12) afficher_resultats("régions de confiance avec " * "gct", "fonction 1", "x012", x_min12, fmin12, flag12, sol_exacte_fct1, nb_iters12)
end end
@test x_min12 sol_exacte_fct1 atol=tol_erreur @test x_min12 sol_exacte_fct1 atol = tol_erreur
# cas de test 3 # cas de test 3
x_min21, fmin21, flag21, nb_iters21 = Regions_De_Confiance("gct",fct2,grad_fct2,hess_fct2,pts1.x021,options2) x_min21, fmin21, flag21, nb_iters21 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x021, options2)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"gct","fonction 2","x021",x_min21,fmin21, flag21,sol_exacte_fct2,nb_iters21) afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x021", x_min21, fmin21, flag21, sol_exacte_fct2, nb_iters21)
end end
@test x_min21 sol_exacte_fct2 atol=tol_erreur @test x_min21 sol_exacte_fct2 atol = tol_erreur
# cas de test 4 # cas de test 4
x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("gct",fct2,grad_fct2,hess_fct2,pts1.x022,options2) x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x022, options2)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"gct","fonction 2","x022",x_min22,fmin22, flag22,sol_exacte_fct2,nb_iters22) afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x022", x_min22, fmin22, flag22, sol_exacte_fct2, nb_iters22)
end end
@test x_min22 sol_exacte_fct2 atol=tol_erreur @test x_min22 sol_exacte_fct2 atol = tol_erreur
# cas de test 5 # cas de test 5
x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("gct",fct2,grad_fct2,hess_fct2,pts1.x023,options2) x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x023, options2)
if (afficher) if (afficher)
afficher_resultats("régions de confiance avec "*"gct","fonction 2","x023",x_min11,fmin23, flag23,sol_exacte_fct2,nb_iters23) afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x023", x_min11, fmin23, flag23, sol_exacte_fct2, nb_iters23)
end end
@test x_min23 sol_exacte_fct2 atol=tol_erreur @test x_min23 sol_exacte_fct2 atol = tol_erreur
end end
end end
end end