Skip to content
Snippets Groups Projects
Commit 77ce72ec authored by asilador's avatar asilador
Browse files

Update

parent 1ec789f3
No related branches found
No related tags found
No related merge requests found
import numpy as np
iimport numpy as np
# Initialize iteration counter
# Import text files
Q = np.asmatrix(np.loadtxt('Q.txt'))
......@@ -31,7 +31,7 @@ def armijo(alpha0,Q,b,c,D,m):
return alpha
else:
m+=1
print('m is ', m)
#print('m is ', m)
alpha = beta**m*s
alpha = armijo(alpha,Q,b,c,D,m)
......@@ -39,22 +39,22 @@ def armijo(alpha0,Q,b,c,D,m):
def xval():
return x
def countval():
return count
# Begin Gradient Descent Algorithm
def grad_opt(epsilon):
x = xval()
count = countval()
def grad_opt(epsilon,x,count):
alpha = armijo(alpha0,Q,b,c,D,m)
print('m is ', m)
print('alpha is ', alpha)
f1 = f(Q,b,c,x)
x = x - alpha*np.transpose(gradf(Q,b,x))*(np.identity(np.size(b)))*gradf(Q,b,x)
if np.linalg.norm(gradf(Q,b,x))>= epsilon:
count += 1
print('f(x*) is ', f(Q,b,c,x))
grad_opt(epsilon)
print('x is ', x)
grad_opt(epsilon,x,count)
return 0
else:
print('Done')
......@@ -62,8 +62,16 @@ def grad_opt(epsilon):
print('f(x*) is ', f(Q,b,c,x))
print('epsilon is ', epsilon)
return 0
grad_opt(0.1)
def run(epsilon):
xstart = xval()
countstart = countval()
epsilon = 0.1
grad_opt(epsilon,xstart,countstart)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment