initial notebook laying out the problem of bound constraints.

This commit is contained in:
Rowan Cockett
2013-11-06 10:57:13 -08:00
parent 059ccd40b3
commit 22f1ff9f74
5 changed files with 248 additions and 31 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
*.pyc
SimPEG.sublime-project
SimPEG.sublime-workspace
docs/_build/
*.sublime-project
*.sublime-workspace
docs/_build/
+15 -23
View File
@@ -13,13 +13,13 @@ class LinearProblem(Problem):
return self.G.dot(m)
def J(self, m, v, u=None):
return G.dot(v)
return self.G.dot(v)
def Jt(self, m, v, u=None):
return G.T.dot(v)
return self.G.T.dot(v)
if __name__ == '__main__':
N = 100
def example(N):
h = np.ones(N)/N
M = TensorMesh([h])
@@ -28,8 +28,6 @@ if __name__ == '__main__':
p = -0.25
q = 0.25
g = lambda k: np.exp(p*jk[k]*M.vectorCCx)*np.cos(2*np.pi*q*jk[k]*M.vectorCCx)
G = np.empty((nk, M.nC))
@@ -38,12 +36,6 @@ if __name__ == '__main__':
G[i,:] = g(i)
plt.figure(1)
for i in range(nk):
plt.plot(G[i,:])
m_true = np.zeros(M.nC)
m_true[M.vectorCCx > 0.3] = 1.
m_true[M.vectorCCx > 0.45] = -0.5
@@ -55,29 +47,29 @@ if __name__ == '__main__':
d_obs = d_true + noise
# plt.figure(3)
# plt.plot(d_true,'-o')
# plt.plot(d_obs,'r-o')
prob = LinearProblem(M)
prob.G = G
prob.dobs = d_obs
prob.std = np.ones_like(d_obs)*0.1
return prob, m_true
if __name__ == '__main__':
prob, m_true = example(100)
M = prob.mesh
reg = Regularization(M)
opt = InexactGaussNewton(maxIter=20)
inv = Inversion(prob,reg,opt,beta0=1e-4)
m0 = np.zeros_like(m_true)
mrec = inv.run(m0)
plt.figure(1)
for i in range(prob.G.shape[0]):
plt.plot(prob.G[i,:])
plt.figure(2)
+5 -3
View File
@@ -154,6 +154,7 @@ class Minimize(object):
self._iterLS = 0
self._STOP = np.zeros((5,1),dtype=bool)
x0 = self.projection(x0) # ensure that we start of feasible.
self.x0 = x0
self.xc = x0
self.xOld = x0
@@ -296,17 +297,18 @@ class Minimize(object):
:rtype: numpy.ndarray,bool
:return: (xt, passLS)
"""
# Armijo linesearch
descent = np.inner(self.g, p)
# Projected Armijo linesearch
t = 1
iterLS = 0
while iterLS < self.maxIterLS:
xt = self.projection(self.xc + t*p)
ft = self.evalFunction(xt, return_g=False, return_H=False)
if ft < self.f + t*self.LSreduction*descent:
descent = np.inner(self.g, xt - self.xc) # this takes into account multiplying by t, but is important for projection.
if ft < self.f + self.LSreduction*descent:
break
iterLS += 1
t = self.LSshorten*t
# TODO: Check if t is tooo small.
self._iterLS = iterLS
return xt, iterLS < self.maxIterLS
+7 -2
View File
@@ -8,8 +8,13 @@ import numpy as np
import unittest
import inspect
happiness = ['The test be workin!', 'You get a gold star!', 'Yay passed!', 'Happy little convergence test!', 'That was easy!', 'Testing is important.', 'You are awesome.', 'Go Test Go!', 'Once upon a time, a happy little test passed.', 'And then everyone was happy.']
sadness = ['No gold star for you.','Try again soon.','Thankfully, persistence is a great substitute for talent.','It might be easier to call this a feature...','Coffee break?', 'Boooooooo :(', 'Testing is important. Do it again.']
try:
import getpass
name = getpass.getuser()[0].upper() + getpass.getuser()[1:]
except Exception, e:
name = 'You'
happiness = ['The test be workin!', 'You get a gold star!', 'Yay passed!', 'Happy little convergence test!', 'That was easy!', 'Testing is important.', 'You are awesome.', 'Go Test Go!', 'Once upon a time, a happy little test passed.', 'And then everyone was happy.','Not just a pretty face '+name,'You deserve a pat on the back!','Well done '+name+'!', 'Awesome, '+name+', just awesome.']
sadness = ['No gold star for you.','Try again soon.','Thankfully, persistence is a great substitute for talent.','It might be easier to call this a feature...','Coffee break?', 'Boooooooo :(', 'Testing is important. Do it again.',"Did you put your clever trousers on today?",'Just think about a dancing dinosaur and life will get better!','You had so much promise '+name+', oh well...', name.upper()+' ERROR!','Get on it '+name+'!', 'You break it, you fix it.']
class OrderTest(unittest.TestCase):
"""
File diff suppressed because one or more lines are too long