feat: avancement

This commit is contained in:
Laureηt 2021-12-16 10:34:56 +01:00
parent 87f0432a3d
commit c071194284
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
6 changed files with 625 additions and 231 deletions

View file

@ -68,13 +68,10 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he
tau = options[6]
end
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 * 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
@ -101,7 +98,7 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he
if algo == "newton"
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])
x_k1, _, _, _ = Regions_De_Confiance(algo, L, gradL, hessL, x_k, [10.0 0.5 2 0.25 0.75 2.0 itermax epsilon tol])
end
if norm(c(x_k1)) <= eta_k # b
@ -121,7 +118,7 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he
flag = 0
break
elseif k >= max_iter
flag = 3
flag = 1
break
end
@ -132,6 +129,9 @@ function Lagrangien_Augmente(algo, f::Function, c::Function, gradf::Function, he
end
# println("lambda_k=", lambda_k)
# println("mu_k=", mu_k)
xmin = x_k1
f_min = f(xmin)
return xmin, f_min, flag, k

View file

@ -86,7 +86,7 @@ function Regions_De_Confiance(algo, f::Function, gradf::Function, hessf::Functio
delta_k = delta0
delta_k1 = delta0
m_k(x, s) = f(x) + gradf(x)' * s + 0.5 * s' * hessf(x) * s
m_k(x, s) = f(x) + gradf(x)' * s + s' * hessf(x) * s / 2
if norm(gradf(x_k1)) <= max(Tol_rel * norm(gradf(x0)), Tol_abs)
flag = 0
@ -99,7 +99,7 @@ function Regions_De_Confiance(algo, f::Function, gradf::Function, hessf::Functio
if algo == "gct"
s_k = Gradient_Conjugue_Tronque(gradf(x_k), hessf(x_k), [delta_k max_iter Tol_rel])
elseif algo == "cauchy"
s_k, e_k = Pas_De_Cauchy(gradf(x_k), hessf(x_k), delta_k)
s_k, _ = Pas_De_Cauchy(gradf(x_k), hessf(x_k), delta_k)
end
# b. Evaluer f(x_k + s_k)

View file

@ -14,66 +14,60 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 66,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------------------------------------------------------------\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 [bd48cda9] \u001b[39mGraphRecipes v0.5.8\n",
" \u001b[90m [86223c79] \u001b[39mGraphs v1.4.1\n",
" \u001b[90m [91a5bcdd] \u001b[39mPlots v1.25.1\n",
" \u001b[90m [a6016688] \u001b[39mTestOptinum v0.1.0 `https://github.com/mathn7/TestOptinum.git#master`\n",
" \u001b[90m [37e2e46d] \u001b[39mLinearAlgebra\n",
" \u001b[90m [d6f4376e] \u001b[39mMarkdown\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 3 seconds (262 already precompiled, 2 skipped during auto due to previous errors)\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 3 seconds (262 already precompiled, 2 skipped during auto due to previous errors)\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 3 seconds (262 already precompiled, 2 skipped during auto due to previous errors)\n"
]
},
{
"data": {
"text/plain": [
"tester_lagrangien_augmente"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"using Pkg\n",
"Pkg.status()\n",
"Pkg.add(\"DifferentialEquations\")\n",
"# Pkg.add(\"LinearAlgebra\");\n",
"# Pkg.add(\"Markdown\")\n",
"# using Documenter\n",
"using LinearAlgebra\n",
"using Markdown\n",
"# using TestOptinum\n",
"using Test\n",
"\n",
"include(\"../test/new_runtests.jl\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Fonction f0\n",
"# -----------\n",
"f0(x) = sin.(x)\n",
"# la gradient de la fonction f0\n",
"grad_f0(x) = cos.(x)\n",
"# la hessienne de la fonction f0\n",
"hess_f0(x) = -sin.(x)\n",
"sol_exacte_f0 = -pi / 2\n",
"\n",
"# Fonction f1\n",
"# -----------\n",
"f1(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 f1\n",
"grad_f1(x) = [\n",
" 4 * (x[1] + x[2] + x[3] - 3) + 2 * (x[1] - x[2])\n",
" 4 * (x[1] + x[2] + x[3] - 3) - 2 * (x[1] - x[2]) + 2 * (x[2] - x[3])\n",
" 4 * (x[1] + x[2] + x[3] - 3) - 2 * (x[2] - x[3])\n",
"]\n",
"# la hessienne de la fonction f1\n",
"hess_f1(x) = [6 2 4; 2 8 2; 4 2 6]\n",
"sol_exacte_f1 = [1, 1, 1]\n",
"\n",
"# Fonction f2\n",
"# -----------\n",
"f2(x) = (100 * x[2] - x[1]^2)^2 + (1 - x[1])^2\n",
"# la gradient de la fonction f2\n",
"grad_f2(x) = [\n",
" (2 * (200 * x[1]^3 - 200 * x[1] * x[2] + x[1] - 1))\n",
" (200 * (x[2] - x[1]^2))\n",
"]\n",
"# la hessienne de la fonction f2\n",
"hess_f2(x) = [\n",
" (-400*(x[2]-x[1]^2)+800*x[1]^2+2) (-400*x[1])\n",
" (-400*x[1]) (200)\n",
"]\n",
"sol_exacte_f2 = [1, 1 / 100]"
"include(\"../test/imports_boilerplate.jl\")"
]
},
{
@ -90,62 +84,139 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 67,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct0 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é à fct0 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é à fct0 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é à fct1 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é à fct1 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é à fct1 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é à fct2 au point initial [1, 1] :\u001b[22m\u001b[39m\n",
" * xsol = [1, 1]\n",
" * f(xsol) = 0\n",
" * nb_iters = 0\n",
" * flag = 0\n",
" * sol_exacte : [1, 1]\n",
"-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct2 au point initial [-1.2, 1.0] :\u001b[22m\u001b[39m\n",
" * xsol = [0.9999999999999999, 0.9999999999814724]\n",
" * f(xsol) = 3.4326461875363225e-20\n",
" * nb_iters = 6\n",
" * flag = 0\n",
" * sol_exacte : [1, 1]\n",
"-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct2 au point initial [10, 0] :\u001b[22m\u001b[39m\n",
" * xsol = [1.0, 1.0]\n",
" * f(xsol) = 0.0\n",
" * nb_iters = 5\n",
" * flag = 0\n",
" * sol_exacte : [1, 1]\n"
]
}
],
"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",
" println(\"-------------------------------------------------------------------------\")\n",
" printstyled(\"Résultats de : \", algo, \" appliqué à \", nom_fct, \" au point initial \", point_init, \":\\n\", bold = true, color = :blue)\n",
" println(\" * xsol = \", xmin)\n",
" println(\" * f(xsol) = \", fxmin)\n",
" println(\" * nb_iters = \", nbiters)\n",
" println(\" * flag = \", flag)\n",
" println(\" * sol_exacte : \", sol_exacte)\n",
"end\n",
"\n",
"options = []\n",
"\n",
"x0 = sol_exacte_f0\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f0, grad_f0, hess_f0, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f0\", x0, xmin, f_min, flag, sol_exacte_f0, nb_iters)\n",
"x0 = sol_exacte_fct0\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct0\", x0, xmin, f_min, flag, sol_exacte_fct0, nb_iters)\n",
"x0 = -pi / 2 + 0.5\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f0, grad_f0, hess_f0, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f0\", x0, xmin, f_min, flag, sol_exacte_f0, nb_iters)\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct0\", x0, xmin, f_min, flag, sol_exacte_fct0, nb_iters)\n",
"x0 = pi / 2\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f0, grad_f0, hess_f0, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f0\", x0, xmin, f_min, flag, sol_exacte_f0, nb_iters)\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct0\", x0, xmin, f_min, flag, sol_exacte_fct0, nb_iters)\n",
"\n",
"x0 = sol_exacte_f1\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f1, grad_f1, hess_f1, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f1\", x0, xmin, f_min, flag, sol_exacte_f1, nb_iters)\n",
"x0 = sol_exacte_fct1\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct1\", x0, xmin, f_min, flag, sol_exacte_fct1, nb_iters)\n",
"x0 = [1, 0, 0]\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f1, grad_f1, hess_f1, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f1\", x0, xmin, f_min, flag, sol_exacte_f1, nb_iters)\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct1\", x0, xmin, f_min, flag, sol_exacte_fct1, nb_iters)\n",
"x0 = [10, 3, -2.2]\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f1, grad_f1, hess_f1, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f1\", x0, xmin, f_min, flag, sol_exacte_f1, nb_iters)\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct1\", x0, xmin, f_min, flag, sol_exacte_fct1, nb_iters)\n",
"\n",
"x0 = sol_exacte_f2\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f2, grad_f2, hess_f2, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f2\", x0, xmin, f_min, flag, sol_exacte_f2, nb_iters)\n",
"x0 = sol_exacte_fct2\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)\n",
"x0 = [-1.2, 1]\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f2, grad_f2, hess_f2, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f2\", x0, xmin, f_min, flag, sol_exacte_f2, nb_iters)\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)\n",
"x0 = [10, 0]\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f2, grad_f2, hess_f2, x0, options)\n",
"my_afficher_resultats(\"Newton\", \"f2\", x0, xmin, f_min, flag, sol_exacte_f2, nb_iters)\n",
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
"afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)\n",
"# x0 = [0, 1 / 200 + 1 / 10^12] # explose !\n",
"# xmin, f_min, flag, nb_iters = Algorithme_De_Newton(f2, grad_f2, hess_f2, x0, options)\n",
"# my_afficher_resultats(\"Newton\", \"f2\", x0, xmin, f_min, flag, sol_exacte_f2, nb_iters)"
"# xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
"# afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 48,
"metadata": {},
"outputs": [],
"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"
}
],
"source": [
"tester_algo_newton(false, Algorithme_De_Newton)"
]
@ -201,9 +272,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 49,
"metadata": {},
"outputs": [],
"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"
]
}
],
"source": [
"function my_afficher_resultats_cauchy(algo, s, e)\n",
" println(\"-------------------------------------------------------------------------\")\n",
@ -233,18 +323,68 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"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"
}
],
"source": [
"tester_pas_de_cauchy(false, Pas_De_Cauchy)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"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"
]
}
],
"source": [
"options = [10, 0.5, 2.00, 0.25, 0.75, 2, 10000, sqrt(eps()), 1e-15]\n",
"algo = \"cauchy\"\n",
@ -301,9 +441,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 52,
"metadata": {},
"outputs": [],
"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"
]
}
],
"source": [
"function my_afficher_resultats_gct(algo, s)\n",
" println(\"-------------------------------------------------------------------------\")\n",
@ -344,18 +506,64 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 53,
"metadata": {},
"outputs": [],
"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"
}
],
"source": [
"tester_gct(false, Gradient_Conjugue_Tronque)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 54,
"metadata": {},
"outputs": [],
"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"
]
}
],
"source": [
"options = [10, 0.5, 2.00, 0.25, 0.75, 2, 10000, sqrt(eps()), 1e-15]\n",
"algo = \"gct\"\n",
@ -375,9 +583,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 55,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"iters = 864\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": [
"tester_regions_de_confiance(false, Regions_De_Confiance)"
]
@ -430,9 +657,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 56,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Lagrangien augmenté avec newton appliqué à fonction 1 au point initial x01 :\u001b[22m\u001b[39m\n",
" * xsol = [0, 1, 1]\n",
" * f(xsol) = 3\n",
" * nb_iters = 0\n",
" * flag = 0\n",
" * sol_exacte : [0.5, 1.25, 0.5]\n",
"-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Lagrangien augmenté avec cauchy appliqué à fonction 1 au point initial x01 :\u001b[22m\u001b[39m\n",
" * xsol = [0, 1, 1]\n",
" * f(xsol) = 3\n",
" * nb_iters = 0\n",
" * flag = 0\n",
" * sol_exacte : [0.5, 1.25, 0.5]\n",
"-------------------------------------------------------------------------\n",
"\u001b[34m\u001b[1mRésultats de : Lagrangien augmenté avec gct appliqué à fonction 1 au point initial x01 :\u001b[22m\u001b[39m\n",
" * xsol = [0, 1, 1]\n",
" * f(xsol) = 3\n",
" * nb_iters = 0\n",
" * flag = 0\n",
" * sol_exacte : [0.5, 1.25, 0.5]\n"
]
}
],
"source": [
"function afficher_resultats(algo,nom_fct,point_init,xmin,fxmin,flag,sol_exacte,nbiters)\n",
"\tprintln(\"-------------------------------------------------------------------------\")\n",
@ -482,42 +737,158 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 57,
"metadata": {},
"outputs": [],
"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",
"Lagrangien augmenté | \u001b[32m 12 \u001b[39m\u001b[36m 12\u001b[39m\n"
]
},
{
"data": {
"text/plain": [
"Test.DefaultTestSet(\"Lagrangien augmenté \", Any[Test.DefaultTestSet(\"Avec newton\", Any[], 4, false, false), Test.DefaultTestSet(\"Avec gct\", Any[], 4, false, false), Test.DefaultTestSet(\"Avec cauchy\", Any[], 4, false, false)], 0, false, false)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tester_lagrangien_augmente(false, Lagrangien_Augmente)"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"algo=newton, tau=0.01 \t--> iter=100 fxmin=11.111111108395063 flag=1\n",
"algo=newton, tau=0.1 \t--> iter=100 fxmin=11.111111108395065 flag=1\n",
"algo=newton, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
"algo=newton, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
"algo=newton, tau=100.0 \t--> iter=4 fxmin=2.2500000022152014 flag=0\n",
"algo=newton, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n",
"algo=cauchy, tau=0.01 \t--> iter=100 fxmin=9.972299093706013 flag=1\n",
"algo=cauchy, tau=0.1 \t--> iter=100 fxmin=9.972299137559094 flag=1\n",
"algo=cauchy, tau=1.0 \t--> iter=100 fxmin=4.058286995337872 flag=1\n",
"algo=cauchy, tau=10.0 \t--> iter=100 fxmin=2.2502165830370076 flag=1\n",
"algo=cauchy, tau=100.0 \t--> iter=100 fxmin=2.314845242402915 flag=1\n",
"algo=cauchy, tau=1000.0 \t--> iter=100 fxmin=2.412284973385117 flag=1\n",
"algo=gct, tau=0.01 \t--> iter=100 fxmin=11.111111108395058 flag=1\n",
"algo=gct, tau=0.1 \t--> iter=100 fxmin=11.111110839506175 flag=1\n",
"algo=gct, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
"algo=gct, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
"algo=gct, tau=100.0 \t--> iter=4 fxmin=2.250000002215201 flag=0\n",
"algo=gct, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n"
]
}
],
"source": [
"## Interprétation\n",
" 1.Commenter les résultats obtenus, en étudiant notamment les valeurs de $\\lambda_k$ et $\\mu_k$.\n",
" \n",
" 2.Étudier l'influence du paramètre $\\tau$ dans la performance de l'algorithme.\n",
" \n",
" 3.**Supplémentaire** : \n",
" Que proposez-vous comme méthode pour la résolution des problèmes avec\n",
" des contraintes à la fois d'égalité et d'inégalité ? Implémenter (si le temps le permet)\n",
" ce nouvel algorithme\n"
"for algo in [\"newton\" \"cauchy\" \"gct\"]\n",
" for tau in [0.01; 0.1; 1; 10; 100; 1000]\n",
" options = [1e-8 1e-5 1 10 10 tau]\n",
" xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct1, contrainte1, grad_fct1, hess_fct1, grad_contrainte1, hess_contrainte1, zeros(3), options)\n",
" println(\"algo=\" * algo * \", tau=\" * string(tau) * \" \\t--> iter=\" * string(nbiters) * \" fxmin=\" * string(fxmin) * \" flag=\" * string(flag))\n",
" end\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TODO\n",
"COMPLETER LES TESTS pour avoir tous les flags, tous les if \\\n",
"répondre aux question"
"## Interprétation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Vos réponses?\n"
"1. Commenter les résultats obtenus, en étudiant notamment les valeurs de $\\lambda_k$ et $\\mu_k$.\n",
"2. Étudier l'influence du paramètre $\\tau$ dans la performance de l'algorithme.\n",
"3. **Supplémentaire** : \n",
"Que proposez-vous comme méthode pour la résolution des problèmes avec des contraintes à la fois d'égalité et d'inégalité ? Implémenter (si le temps le permet) ce nouvel algorithme"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-----------------------------------------\n",
"algo=newton, tau=0.01 \t--> iter=100 fxmin=11.111111108395063 flag=1\n",
"-----------------------------------------\n",
"algo=newton, tau=0.1 \t--> iter=100 fxmin=11.111111108395065 flag=1\n",
"-----------------------------------------\n",
"algo=newton, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
"-----------------------------------------\n",
"algo=newton, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
"-----------------------------------------\n",
"algo=newton, tau=100.0 \t--> iter=4 fxmin=2.2500000022152014 flag=0\n",
"-----------------------------------------\n",
"algo=newton, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n",
"-----------------------------------------\n",
"algo=cauchy, tau=0.01 \t--> iter=100 fxmin=9.972299093706013 flag=1\n",
"-----------------------------------------\n",
"algo=cauchy, tau=0.1 \t--> iter=100 fxmin=9.972299137559094 flag=1\n",
"-----------------------------------------\n",
"algo=cauchy, tau=1.0 \t--> iter=100 fxmin=4.058286995337872 flag=1\n",
"-----------------------------------------\n",
"algo=cauchy, tau=10.0 \t--> iter=100 fxmin=2.2502165830370076 flag=1\n",
"-----------------------------------------\n",
"algo=cauchy, tau=100.0 \t--> iter=100 fxmin=2.314845242402915 flag=1\n",
"-----------------------------------------\n",
"algo=cauchy, tau=1000.0 \t--> iter=100 fxmin=2.412284973385117 flag=1\n",
"-----------------------------------------\n",
"algo=gct, tau=0.01 \t--> iter=100 fxmin=11.111111108395058 flag=1\n",
"-----------------------------------------\n",
"algo=gct, tau=0.1 \t--> iter=100 fxmin=11.111110839506175 flag=1\n",
"-----------------------------------------\n",
"algo=gct, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
"-----------------------------------------\n",
"algo=gct, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
"-----------------------------------------\n",
"algo=gct, tau=100.0 \t--> iter=4 fxmin=2.250000002215201 flag=0\n",
"-----------------------------------------\n",
"algo=gct, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n"
]
}
],
"source": [
"for algo in [\"newton\" \"cauchy\" \"gct\"]\n",
" for tau in [0.01; 0.1; 1; 10; 100; 1000]\n",
" options = [1e-8 1e-5 1 10 10 tau]\n",
" println(\"-----------------------------------------\")\n",
" xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct1, contrainte1, grad_fct1, hess_fct1, grad_contrainte1, hess_contrainte1, zeros(3), options)\n",
" println(\"algo=\" * algo * \", tau=\" * string(tau) * \" \\t--> iter=\" * string(nbiters) * \" fxmin=\" * string(fxmin) * \" flag=\" * string(flag))\n",
" end\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Vos réponses\n",
"\n",
"1. On observe que lorsque:\n",
" - l'algorithme converge (flag = 0), alors $\\lambda_k$ tend vers $2 \\times f(x_{min})$.\n",
" - l'algorithme ne converge pas (flag = 1), alors $\\mu_k$ tend vers 0. \n",
"\n",
"2. Il semblerait que plus $\\tau$ est élevé, plus l'algorithme converge rapidement"
]
}
],

View file

@ -6,7 +6,7 @@ Ce fichier contient toutes fonctions utilisés dans les tests des algorithmes :
"""
# Les points initiaux
# pour les problèmes sans contraintes
## pour les problèmes sans contraintes
struct Pts_sans_contraintes
x011
x012
@ -14,77 +14,98 @@ struct Pts_sans_contraintes
x022
x023
end
x011 = [1; 0; 0]
x012 = [10; 3; -2.2]
x021 = [-1.2; 1]
x022 = [10; 0]
x023 = [0; 1/200 + 1/10^12]
# les points initiaux utilisés dans les problèmes sans contraintes
pts1 = Pts_sans_contraintes(x011,x012,x021,x022,x023)
pts1 = Pts_sans_contraintes(
[1; 0; 0],
[10; 3; -2.2],
[-1.2; 1],
[10; 0],
[0; 1 / 200 + 1 / 10^12]
)
# pour les problèmes avec contraintes
## pour les problèmes avec contraintes
struct Pts_avec_contraintes
x01
x02
x03
x04
end
x01 = [0; 1; 1]
x02 = [0.5; 1.25; 1]
x03 = [1; 0]
x04 = [sqrt(3)/2 ;sqrt(3)/2]
pts2 = Pts_avec_contraintes(
[0; 1; 1],
[0.5; 1.25; 1],
[1; 0],
[sqrt(3) / 2; sqrt(3) / 2]
)
pts2 = Pts_avec_contraintes(x01,x02,x03,x04)
# Fonctions de test
# Les solutions exactes
# sol_exacte_fct1 = -hess_fct1(x011)\grad_fct1(zero(similar(x011)))
sol_exacte_fct1 = [1;1;1]
sol_exacte_fct2 = [1;1]
"""
La zéroième fonction de test
# Expression
fct0(x) = sin(x)
"""
fct0(x) = sin.(x)
# la gradient de la fonction fct0
grad_fct0(x) = cos.(x)
# la hessienne de la fonction fct0
hess_fct0(x) = -sin.(x)
# solutions de la fonction fct0
sol_exacte_fct0 = -pi / 2
"""
La première fonction de test
# Expression
fct1(x) = 2*(x[1]+x[2]+x[3]-3)^2 + (x[1]-x[2])^2 + (x[2]-x[3])^2
fct1(x) = 2 * (x[1] + x[2] + x[3] - 3)^2 + (x[1] - x[2])^2 + (x[2] - x[3])^2
"""
fct1(x) = 2*(x[1]+x[2]+x[3]-3)^2 + (x[1]-x[2])^2 + (x[2]-x[3])^2
fct1(x) = 2 * (x[1] + x[2] + x[3] - 3)^2 + (x[1] - x[2])^2 + (x[2] - x[3])^2
# la gradient de la fonction fct1
function grad_fct1(x)
y1 = 4*(x[1]+x[2]+x[3]-3) + 2*(x[1]-x[2])
y2 = 4*(x[1]+x[2]+x[3]-3) - 2*(x[1]-x[2]) +2*(x[2]-x[3])
y3 = 4*(x[1]+x[2]+x[3]-3) - 2*(x[2]-x[3])
return [y1;y2;y3]
end
grad_fct1(x) = [
4 * (x[1] + x[2] + x[3] - 3) + 2 * (x[1] - x[2])
4 * (x[1] + x[2] + x[3] - 3) - 2 * (x[1] - x[2]) + 2 * (x[2] - x[3])
4 * (x[1] + x[2] + x[3] - 3) - 2 * (x[2] - x[3])
]
# la hessienne de la fonction fct1
hess_fct1(x) = [6 2 4;2 8 2;4 2 6]
hess_fct1(x) = [
6 2 4
2 8 2
4 2 6
]
# solutions de la fonction fct1
sol_exacte_fct1 = [1; 1; 1] # = -hess_fct1(x011) \ grad_fct1(zero(similar(x011)))
sol_fct1_augm = [0.5; 1.25; 0.5] # pour les problèmes avec contraintes
"""
La première fonction de test
La deuxième fonction de test
# Expression
fct2(x)=100*(x[2]-x[1]^2)^2+(1-x[1])^2
fct2(x) = 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2
"""
fct2(x)=100*(x[2]-x[1]^2)^2+(1-x[1])^2
fct2(x) = 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2
# la gradient de la fonction fct2
grad_fct2(x)=[-400*x[1]*(x[2]-x[1]^2)-2*(1-x[1]) ; 200*(x[2]-x[1]^2)]
grad_fct2(x) = [
-400 * x[1] * (x[2] - x[1]^2) - 2 * (1 - x[1])
200 * (x[2] - x[1]^2)
]
#la hessienne de la fonction fct2
hess_fct2(x)=[-400*(x[2]-3*x[1]^2)+2 -400*x[1];-400*x[1] 200]
hess_fct2(x) = [
-400*(x[2]-3*x[1]^2)+2 -400*x[1]
-400*x[1] 200
]
# solutions de la fonction fct2
sol_exacte_fct2 = [1; 1]
sol_fct2_augm = [0.9072339605110892; 0.82275545631455] # pour les problèmes avec contraintes
# Pour les problèmes avec contraintes
# solutions
sol_fct1_augm = [0.5 ; 1.25 ; 0.5]
sol_fct2_augm = [0.9072339605110892; 0.82275545631455]
"""
La première contrainte
# Expression
contrainte1(x) = x[1]+x[3]-1
"""
contrainte1(x) = x[1]+x[3]-1
grad_contrainte1(x) = [1 ;0; 1]
hess_contrainte1(x) = [0 0 0;0 0 0;0 0 0]
contrainte1(x) = x[1] + x[3] - 1
grad_contrainte1(x) = [1; 0; 1]
hess_contrainte1(x) = [0 0 0; 0 0 0; 0 0 0]
"""
La deuxième contrainte
@ -92,17 +113,17 @@ La deuxième contrainte
# Expression
contrainte2(x) = (x[1]^2) + (x[2]^2) -1.5
"""
contrainte2(x) = (x[1]^2) + (x[2]^2) -1.5
grad_contrainte2(x) = [2*x[1] ;2*x[2]]
hess_contrainte2(x) = [2 0;0 2]
contrainte2(x) = (x[1]^2) + (x[2]^2) - 1.5
grad_contrainte2(x) = [2 * x[1]; 2 * x[2]]
hess_contrainte2(x) = [2 0; 0 2]
# Affichage les sorties de l'algorithme des Régions de confiance
function afficher_resultats(algo,nom_fct,point_init,xmin,fxmin,flag,sol_exacte,nbiters)
println("-------------------------------------------------------------------------")
printstyled("Résultats de : "*algo*" appliqué à "*nom_fct*" au point initial "*point_init*" :\n",bold=true,color=:blue)
println(" * xsol = ",xmin)
println(" * f(xsol) = ",fxmin)
println(" * nb_iters = ",nbiters)
println(" * flag = ",flag)
println(" * sol_exacte : ", sol_exacte)
function afficher_resultats(algo, nom_fct, point_init, xmin, fxmin, flag, sol_exacte, nbiters)
println("-------------------------------------------------------------------------")
printstyled("Résultats de : " * algo * " appliqué à " * nom_fct * " au point initial ", point_init, " :\n", bold = true, color = :blue)
println(" * xsol = ", xmin)
println(" * f(xsol) = ", fxmin)
println(" * nb_iters = ", nbiters)
println(" * flag = ", flag)
println(" * sol_exacte : ", sol_exacte)
end

View file

@ -0,0 +1,30 @@
using Pkg
Pkg.status()
Pkg.add("DifferentialEquations")
Pkg.add("LinearAlgebra");
Pkg.add("Markdown")
using LinearAlgebra
using Markdown
using Test
# using TestOptinum
# using Documenter
include("../src/Algorithme_De_Newton.jl")
include("../src/Gradient_Conjugue_Tronque.jl")
include("../src/Lagrangien_Augmente.jl")
include("../src/Pas_De_Cauchy.jl")#
include("../src/Regions_De_Confiance.jl")
#include("cacher_stacktrace.jl")
#cacher_stacktrace()
# Tolérance pour les tests d'égalité
tol_erreur = sqrt(eps())
## ajouter les fonctions de test
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")

View file

@ -1,49 +1,21 @@
using Markdown
using Test
using LinearAlgebra
include("imports_boilerplate.jl")
include("../src/Algorithme_De_Newton.jl")
include("../src/Gradient_Conjugue_Tronque.jl")
include("../src/Lagrangien_Augmente.jl")
include("../src/Pas_De_Cauchy.jl")#
include("../src/Regions_De_Confiance.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)
#include("cacher_stacktrace.jl")
#cacher_stacktrace()
# 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)
# Tolérance pour les tests d'égalité
tol_erreur = sqrt(eps())
# Tester l'algorithme des Régions de confiance avec PasdeCauchy | GCT
tester_regions_de_confiance(affiche, Regions_De_Confiance)
## ajouter les fonctions de test
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)
# # 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 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