From 9864a2ae189f0a9f74895c8d9557fa9da372ccd8 Mon Sep 17 00:00:00 2001 From: yarkin06 Date: Thu, 23 Jun 2022 14:42:55 +0200 Subject: [PATCH] update --- HW2/Untitled-1.py | 5 ++ HW2/WolfePowellSearch.py | 74 +++++++++++++++++- HW2/__pycache__/LLTSolver.cpython-39.pyc | Bin 0 -> 962 bytes HW2/__pycache__/PrecCGSolver.cpython-39.pyc | Bin 0 -> 1081 bytes .../WolfePowellSearch.cpython-39.pyc | Bin 0 -> 1791 bytes .../globalNewtonDescent.cpython-39.pyc | Bin 0 -> 1097 bytes .../incompleteCholesky.cpython-39.pyc | Bin 0 -> 1345 bytes .../nonlinearObjective.cpython-39.pyc | Bin 0 -> 2370 bytes .../simpleValleyObjective.cpython-39.pyc | Bin 0 -> 1913 bytes HW2/globalNewtonDescent.py | 26 ++++-- 10 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 HW2/Untitled-1.py create mode 100644 HW2/__pycache__/LLTSolver.cpython-39.pyc create mode 100644 HW2/__pycache__/PrecCGSolver.cpython-39.pyc create mode 100644 HW2/__pycache__/WolfePowellSearch.cpython-39.pyc create mode 100644 HW2/__pycache__/globalNewtonDescent.cpython-39.pyc create mode 100644 HW2/__pycache__/incompleteCholesky.cpython-39.pyc create mode 100644 HW2/__pycache__/nonlinearObjective.cpython-39.pyc create mode 100644 HW2/__pycache__/simpleValleyObjective.cpython-39.pyc diff --git a/HW2/Untitled-1.py b/HW2/Untitled-1.py new file mode 100644 index 0000000..d563a4f --- /dev/null +++ b/HW2/Untitled-1.py @@ -0,0 +1,5 @@ + +import numpy as np +a = np.array([[0.00324953]]) +print(a) +print(-a) \ No newline at end of file diff --git a/HW2/WolfePowellSearch.py b/HW2/WolfePowellSearch.py index 5c8a0e6..e4c58e6 100644 --- a/HW2/WolfePowellSearch.py +++ b/HW2/WolfePowellSearch.py @@ -54,12 +54,13 @@ # should return t=0.0938 +from re import T import numpy as np def matrnr(): # set your matriculation number here - matrnr = 0 + matrnr = 23062789 return matrnr @@ -67,6 +68,7 @@ def WolfePowellSearch(f, x: np.array, d: np.array, sigma=1.0e-3, rho=1.0e-2, ver fx = f.objective(x) gradx = f.gradient(x) descent = gradx.T @ d + print("wp",descent) if descent >= 0: raise TypeError('descent direction check failed!') @@ -82,6 +84,72 @@ def WolfePowellSearch(f, x: np.array, d: np.array, sigma=1.0e-3, rho=1.0e-2, ver t = 1 - MISSING CODE - + # MISSING CODE + + fxd = f.objective(x + t*d) + gradxd = f.gradient(x + t*d) + descentxd = gradxd.T @ d + + W1 = fxd <= (fx + t*sigma*descent) + W2 = descentxd >= (rho*descent) + if W1 == False: + t = t/2 + fxd = f.objective(x + t*d) + W1 = fxd <= (fx + t*sigma*descent) + gradxd = f.gradient(x + t*d) + descentxd = gradxd.T @ d + W2 = descentxd >= (rho*descent) + while W1 == False: + t = t/2 + fxd = f.objective(x + t*d) + W1 = fxd <= (fx + t*sigma*descent) + gradxd = f.gradient(x + t*d) + descentxd = gradxd.T @ d + W2 = descentxd >= (rho*descent) + t_min = t + t_pl = 2*t + + elif W2 == True: + t_star = t + return t_star + + else: + t = 2*t + fxd = f.objective(x + t*d) + W1 = fxd <= (fx + t*sigma*descent) + gradxd = f.gradient(x + t*d) + descentxd = gradxd.T @ d + W2 = descentxd >= (rho*descent) + while W1 == True: + t = 2*t + fxd = f.objective(x + t*d) + W1 = fxd <= (fx + t*sigma*descent) + gradxd = f.gradient(x + t*d) + descentxd = gradxd.T @ d + W2 = descentxd >= (rho*descent) + t_min = t/2 + t_pl = t + + t = t_min + fxd = f.objective(x + t*d) + W1 = fxd <= (fx + t*sigma*descent) + gradxd = f.gradient(x + t*d) + descentxd = gradxd.T @ d + W2 = descentxd >= (rho*descent) + while W2 == False: + print("4") + t = (t_min + t_pl)/2 + fxd = f.objective(x + t*d) + W1 = fxd <= (fx + t*sigma*descent) + gradxd = f.gradient(x + t*d) + descentxd = gradxd.T @ d + W2 = descentxd >= (rho*descent) + if W1 == True: + t_min = t + else: + t_pl = t + print(t_min) + t_star = t_min + + t = np.copy(t_star) return t diff --git a/HW2/__pycache__/LLTSolver.cpython-39.pyc b/HW2/__pycache__/LLTSolver.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f97f182b453eebbb5f80a381147b32853302be53 GIT binary patch literal 962 zcmY*YPfyf96rVTkv|R!TAtYinv0^l?hc4k{3^6J~j3GeWH71)7Q+5U@?6&K4KzB2} z2p_<+@c>7!eh5Fr9K3kqD|pd20}JbG-s}7Gn>WACyrxrA69nb!*5mD80U^I_FfKj@ z&rr)pXgJ}}C2io8dncq#c_?7tv&#K%lrtWju(r>kN$Sx#;>mi)+K~V{R+mxB2n~md zXo6_EE^XmEse=i6sgk*r6cf(;Ng8`aPc#OpJjn9K=9`VzE6c5BV`H=Re)aj=#;bRW zjkUE_v*;cPne+$J!WyD z3@T5dPsAA|d=Py)&MxWCidJ{iKGaWe3*TF?@mdue6Vu^fMbQoqa zoE}iA730|TGmJ2oT^!=p_{s;`uR_a#`*Q@3n;m<|Wyf)GIb?B>vz)>)PJwpaFgMQW z5`mn4{)c84Xx#f6@k7%uAYUMNvL8%i1r_E<72#|2L;q2c;)rm0e?;_I79 z5_ieNyKNzhm}lv3k*D2QbVX0(D&|6ojuJdcl5;x@=YLU#_pa8*O2}T8rwEBZW@;~% zqRjYV+I>GDl2jWt$Ix|Y%g)zi3xFJ zwu@32z*1=-Gq7)9V4_j;>oJsenoRAA&wUKbhiL4CMRWopn8YWc(-_TDpU%Q8M)Nd) z8LUMhZy>e~?hxwCu>7!x!)kv&H=l;3Ql!`S_uy1KqKH*p{i9>pr~pq5`>gXw29qz)6H)1y3j=4 zQ+q|?0YFNQ+_>-xJcJKiIG`T5a6#h4cqz1irTIK#&x}9YGhww_Mle3@HF&v{dE@slUirH>Ej4M`jbsnrftv`Bpx4tcSuko;%#xJ;79FBwq!MDvZ=01qnxLEn}>g$Ke_mA(FYeeH! zjk~>K+ql4(1@S-%dRKv{vV<>zzGAR*u3`lD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K>X zxp_`vB)RCOc_KNBk{xiO{p(RF4bC8yyHQ?_3v<=<>^a-91cA~hL;@VZO*P_@3a*eDYgcgvLj*n#edNBI zG&8*C!W0*R&_BRMvuk&51pfm602eOq)3Aeyem-r-$%LfWAHgejRyNfBV#KOc5SSt7bqCdYBwUAuMj z#6phgp(Ogc2*GY$A&Bw3APzgCWkFWTpc`U9gs?&z}7G z%V&eND^I`s?D5G8OJ6FETLw>q`DQ~?k60Z8e{ zuTTz+tilp8ACWu1R{=(CD7SRWpbYL|))MyV0n~cWU;|EHC+I=Z<9Zd^I@}WN29H=e zcI98_ab&4|m&h4XTYF^tCvKuzjL}|-`(@QYOXDcZjbm9FFS0xYdDh0TwmKTt?4qZw z<`h}{FDD{;MA0$dwo> z!QYFDoXH|q(>iW0MIq#_;GNl-b;YEL{^w+OIltPmPL)ecTfL#kn{A=a?fpR1FbOC9g^!&-lFy`{N#dg0YR zFQL7-ii|)Le<8FWq;DXFN9022wjiPla2npGbNHQuMS6j@U;$3KK5Fym6;k;o#%Mdz z!;jrayWee3d+APs&qTx6&0B$;Ny(-bf2=_J64@%lUXt;hiMV_Y(e_mdozVXm6H-*z literal 0 HcmV?d00001 diff --git a/HW2/__pycache__/nonlinearObjective.cpython-39.pyc b/HW2/__pycache__/nonlinearObjective.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..52f71547904bf02da90b307875848faca98d1147 GIT binary patch literal 2370 zcmb_ezmFS56rP#=;XTKfz+vLRA&}@SM66gyG>{F7AQ6QxkRT*CtIf@_=U}goSznYp z)>V!!{{RRfkZ7*Cf+|$0>1f#sL~*icBMK_MH?zArUwl@Ij5Kd%-h1=*&3o^g*>H8W z&d`4Ow|o1ovyA;si{s70;tG2DCWvH`4_Ti}A+3GZ7uT4yrL)hZb6@l=$#1f@JA)qU zZ4xaT$AtP-^wa~9e9AHgZP8OCIACp_yQ6TT5~Tzfn*8@}XKOr)I=i9za*%Xxe7f=R zhgWai>}=e)6@2u;XPxVxcRR^A84i*tR2#SNM4OYr-RR=>t|F%!=&23Dgv~W)&L@btzc;6}@AJNUj7R4sUhNpql{L-tq=z%D>9vy*$_Pal$OdWmq zEw$hLqeAW%oL~K;ubYS0{@VMwb?GqSagT5Fz1N-&^2JJhF4FX&D$wsR*` zD%@?mI`8U5lCFW|mP84FbaNh`%)b|_P!6JG@(wgpvTf4;fIr}Cd~bb036wkLDuCRr zD&P=hds+o7!kY9bN7B(*q?`dWh+(~`6N9libdrX~noBwhFbWLLTQxdO!tJs>rQL=> zaE0I1(w^Z{_Ou=28z|PKqxaLdib^~6ewp{KMdx)gs+_aB?w9#E7cH$_>?AAr_7dNL zrlRte-F=mBg+I?ZAKI#k)pN*)zG0s!AC5sAuqHA)b7G+p=VmStckUSCihKC*kwKlt zpGFX)jE?rFU#j{VjIp_?XTC;dvHHVTFGIIoI|)noivYm9)Hh?-j9q|q>m*2P zTTz-0!sLC}NeTJ}qmS`|KIZ57-m42xT5RdzvGjr<2}e;7qOolQvErY89gD2U{CjqzCFBk!Pi`LPjD@1+qskM djPT2#jZ*Y9f03!&d(XIcnO-sdYvEa*`#*)zuQ>n! literal 0 HcmV?d00001 diff --git a/HW2/__pycache__/simpleValleyObjective.cpython-39.pyc b/HW2/__pycache__/simpleValleyObjective.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..07912d92e0e94a1ddba5b6dd774f43b843bd9b1c GIT binary patch literal 1913 zcmZ{lO>f&a7{^J9l4Zwk-KHtThJIaX0KR3`MtM&Cr8mEZqwDFhMmHTbV7p zlrqGD3=C+l`vyC#M_>1GbloXmVW<5cDst?^lfg%P`0|L)kAKpBtyW=p{{H>Tx4*cI z{X@?3W5Icj67Rq$rudL`xf04cV_mVwlvMT^Q}%n&wG=;K4d)!=Si48IcsMFlUZBMI z2%^kb$}n2AHFeBcgJ;gjPjsZUK!Y*=e%&05M?rJy>tDmD+4*t*)%P!6A2jznuf3Pw z{?z>8&C_NajwZw4XMZ>hru%P?f?g8-7Cf0uHLd$|lvu(rA-QQ;Sr&Cr?{k!R0uxYb zNGq_8q~d?(Y09o`dDv#fX}^aVFpM?uNRF z^y}H(wF%65#wR@jQ9M+qVi3}fr95RGHspZKd0RVZnTt%u!SGO*;9OGFlw#(3UKoXm z=Y0V$Hj(-1_S%m>DTZQC_{qvDC^CgJt9Xe@%8sy^AF-J*HG!Iya?>L5Cf`o@Um}$s zcq&p`SzD0ICcDG#v(&oJW=`sWgWaABBZOQH;+#a0H{3++oYvd0Ok$acCYkJw<3XdO z352e~WMZ<5(#pgM-Y2b$A6_L;9vAZX3KL?Q#drlj7r$+O`d~eb#jF(&B;o~#S8$d< zV}S0wYRk$-vMxMASFP)X5NohRpZ% z7V6mNFdAgGueCpIxR)68CJnz!<{nJfKJ?VdZvFz3{#7P!U;8QyqU0Gy$Miu$LO?3K z&Ts#(LW*hEnAnJ5#PJ;}*O@F>NF@p$7aSx=Kp=aj0+!7Weq+r|ZRWF>3__X_d;Fld4HJ=B(;6 z)o565%o(l4LDKQHKMImS#~pMQ2le6l&##Q{5u@Uv$P0ab1}9-hxG?BoDuE+tZL&V} zNxDmfl7EO9PwDoy+qvvWaYlQ%18kK{CjpKhNzdTU?8D*MPa49Uy>4kV-Gh!gSM#|w zDUzXXlGyz}hMF8V@S;g~4V|6^Fde!sZ9s9$)=W=~|gI2ml z<`Xj8WFEj|)j08!um{3}vC=!#ez^&zM$|OPxP@Y*;EK9cck5;REWu4*LuPh#Ji_0M YVPX|?)& eps: + print("tur") + # MISSING CODE + Bk = hessx + dk = PCG.PrecCGSolver(Bk,xk) + descent = gradx.T @ dk + print(dk) + if descent >= 0: + print("girdi") + dk = -gradx + print(descent) + tk = WP.WolfePowellSearch(f,xk,dk) + xk = xk + tk*dk + hessx = f.hessian(xk) + Bk = hessx countIter = countIter + 1 + x = np.copy(xk) if verbose: gradx = f.gradient(x)