Last active
August 29, 2015 14:21
-
-
Save JosmanPS/a83ac0d27cf187b11ffd to your computer and use it in GitHub Desktop.
Método numérico para optimización con rengiones de confianza
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function x = RegConfianza(fun, maxiter, tol, delta, DELTA, etha) | |
% =========================================================== | |
% METODO DE REGIONES DE CONFIANZA | |
% | |
% AUTHOR: Jose Manuel Proudinat Silva | |
% ID: 000130056 | |
% COURSE: Analisis Aplicado | |
% | |
% DESCRIPTION: | |
% | |
% | |
% INPUT: | |
% | |
% | |
% OUTPUT: | |
% | |
% | |
% =========================================================== | |
% Configuracion AMPL | |
nombre_ampl = strcat(fun, '.nl'); | |
salida = strcat(fun, '.out'); | |
fout = fopen(salida, 'w'); | |
[x, ~, ~, ~, ~, ~] = spamfunc(nombre_ampl); | |
% Valores iniciales | |
n = length(x) | |
k = 1; | |
[f, ~] = spamfunc(x, 0); | |
[g, ~] = spamfunc(x, 1); | |
[H, ~] = spamfunc(x, 2); | |
normg = norm(g); | |
curv = 1; | |
mf = @(H, g, f, x) x' * H * x + g' * x + f; | |
% Preparamos la impresion | |
fprintf( fout, '######################################################################\n\n'); | |
fprintf( fout, ' Nombre del problema %10s \n', fun); | |
fprintf( fout, ' Numero de variables %3i \n', n); | |
fprintf(fout,' k f ||g|| ||p|| nfg curv \n'); | |
fprintf(fout,['----------------------------------------------------' ... | |
'-------------------\n']); | |
while k < maxiter && normg > tol | |
% Obtenemos la direccion de descenso a traves del GC modificado | |
p = GCTR(H, -g, tol, tol, maxiter, delta); | |
% Calculamos el paso rho | |
xx = x + p; | |
[ff, ~] = spamfunc(xx, 0); | |
mm = mf(H, g, f, p); | |
rho = (f - ff) / (f - mm); | |
% Actualizamos la region de confianza | |
normp = norm(p); | |
if rho < 0.25 | |
delta = 0.25 * normp; | |
else | |
if rho > 0.75 && normp == delta | |
delta = min(2 * delta, DELTA); | |
end | |
end | |
if rho > etha | |
x = xx; | |
end | |
k = k + 1; | |
if mod(k, 50) == 0 | |
fprintf(fout, ' %3i %14.8e %8.2e %5.3f %3i %5.3f \n', ... | |
k, f, normg, normp, numfg, curv ); | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment