Skip to content
Snippets Groups Projects
Commit 945287cf authored by asilador's avatar asilador
Browse files

Modified Armijo's Rule. Faster convergence, but I'm not sure if it is correct

parent 5e306099
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ b = np.asmatrix(np.loadtxt('b.txt'))
c = np.asmatrix(np.loadtxt('c.txt'))
b = np.transpose(b) #make b a column vector
D = np.asmatrix(np.ones(np.size(b)))
m = 0
m = 1
# Make a guess for x vector
#x = np.asmatrix(np.zeros(np.size(b)))
......@@ -14,8 +14,9 @@ m = 0
#x=np.matrix(np.random.rand(5,1))
x = np.transpose(np.asmatrix(np.ones(np.size(b)))*0.1)
alpha0 = 1000.0
alpha0 = 1.0
count = 0
# Define f(x)
def f(Q,b,c,x):
return np.transpose(x)*Q*x + np.transpose(b)*x + c
......@@ -32,7 +33,7 @@ def armijo(alpha0,Q,b,c,D,m):
s = 1.0
sigma = 1.0
beta = 1.0/2
while f(Q,b,c,x+np.transpose(beta**m*alpha*D)) > f(Q,b,c,x) + sigma*beta**m*alpha*(np.transpose(gradf(Q,b,x)))*np.transpose(D):
while f(Q,b,c,x+np.transpose(beta**m*s*D)) < f(Q,b,c,x) + sigma*beta**m*s*(np.transpose(gradf(Q,b,x)))*np.transpose(D):
m+=1
#print('m is ', m)
alpha = beta**m*s
......@@ -60,7 +61,7 @@ def grad_opt(epsilon,x,count,alpha):
#print('norm of gradf(x) is ', np.linalg.norm(gradf(Q,b,x)))
x -= alpha*gradf(Q,b,x)
alpha = alpha0
print '\nDone at ', count,'th iteration'
print 'x* is ', x
......
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