Skip to content

Commit ce873c4

Browse files
committed
Better handling of bound for MVI
1 parent cb0b8a4 commit ce873c4

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

simpeg/directives/_vector_models.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ def initialize(self):
124124

125125
self.reference_model = reg.reference_model
126126

127+
upper_bound = []
128+
for reg in self.regularizations.objfcts:
129+
upper_bound.append(reg.mapping * self.opt.upper)
130+
131+
self.upper_bound = np.linalg.norm(np.vstack(upper_bound), axis=0) / 3**0.5
132+
127133
def endIter(self):
128134

129135
model = self.invProb.model.copy()
@@ -132,25 +138,25 @@ def endIter(self):
132138
if self.mode == "cartesian":
133139
vec_model = []
134140
indices = []
135-
upper_bound = []
136141
for reg in self.regularizations.objfcts:
137142
vec_model.append(reg.mapping * model)
138-
upper_bound.append(reg.mapping * self.opt.upper)
139143
mapping = reg.mapping.deriv(np.zeros(reg.mapping.shape[1]))
140144
indices.append(mapping.indices)
141145

142146
amplitude = np.linalg.norm(np.vstack(vec_model), axis=0)
143-
upper_bound = np.linalg.norm(np.vstack(upper_bound), axis=0)
144-
out_bound = amplitude > upper_bound
147+
out_bound = amplitude > self.upper_bound
145148

146149
if np.any(out_bound):
147-
scale = upper_bound / amplitude
150+
scale = self.upper_bound / amplitude
148151

149152
for ind in indices:
150153
vec = model[ind]
151154
vec[out_bound] *= scale[out_bound]
152155
model[ind] = vec
153156

157+
self.opt.upper[ind[out_bound]] *= scale[out_bound]
158+
self.opt.lower[ind[out_bound]] *= scale[out_bound]
159+
154160
self.invProb.model = model
155161
self.opt.xc = model
156162

@@ -165,19 +171,16 @@ def endIter(self):
165171
vec_ref = []
166172
indices = []
167173
mappings = []
168-
upper_bound = []
169174
for reg in self.regularizations.objfcts:
170175
mappings.append(reg.mapping)
171176
vec_model.append(reg.mapping * model)
172177
vec_ref.append(reg.mapping * reg.reference_model)
173-
upper_bound.append(reg.mapping * self.opt.upper)
174178
mapping = reg.mapping.deriv(np.zeros(reg.mapping.shape[1]))
175179
indices.append(mapping.indices)
176180

177181
indices = np.hstack(indices)
178182
nC = mapping.shape[0]
179183
vec_model = cartesian2spherical(np.vstack(vec_model).T)
180-
upper_bound = np.linalg.norm(np.vstack(upper_bound), axis=0)
181184
vec_ref = cartesian2spherical(np.vstack(vec_ref).T).flatten()
182185
model[indices] = vec_model.flatten()
183186

@@ -222,7 +225,7 @@ def endIter(self):
222225
np.asarray([0, -np.inf, -np.inf]), np.ones(nC)
223226
)
224227
self.opt.upper[indices] = np.r_[
225-
upper_bound, np.ones_like(indices[nC:]) * np.inf
228+
self.upper_bound, np.ones_like(indices[nC:]) * np.inf
226229
]
227230

228231
updates = {}

0 commit comments

Comments
 (0)