diff --git a/simpeg/directives/_vector_models.py b/simpeg/directives/_vector_models.py index dba2f319e5..1636b46415 100644 --- a/simpeg/directives/_vector_models.py +++ b/simpeg/directives/_vector_models.py @@ -129,7 +129,7 @@ def endIter(self): model = self.invProb.model.copy() # Project bounds - if self.mode == "cartesian" and np.any(~np.isinf(self.opt.upper)): + if self.mode == "cartesian": vec_model = [] indices = [] upper_bound = [] @@ -140,12 +140,12 @@ def endIter(self): indices.append(mapping.indices) amplitude = np.linalg.norm(np.vstack(vec_model), axis=0) - upper_bound = np.hstack(upper_bound) - upper_bound = np.max(upper_bound[~np.isinf(upper_bound)]) + upper_bound = np.linalg.norm(np.vstack(upper_bound), axis=0) out_bound = amplitude > upper_bound if np.any(out_bound): scale = upper_bound / amplitude + for ind in indices: vec = model[ind] vec[out_bound] *= scale[out_bound] @@ -165,16 +165,19 @@ def endIter(self): vec_ref = [] indices = [] mappings = [] + upper_bound = [] for reg in self.regularizations.objfcts: mappings.append(reg.mapping) vec_model.append(reg.mapping * model) vec_ref.append(reg.mapping * reg.reference_model) + upper_bound.append(reg.mapping * self.opt.upper) mapping = reg.mapping.deriv(np.zeros(reg.mapping.shape[1])) indices.append(mapping.indices) indices = np.hstack(indices) nC = mapping.shape[0] vec_model = cartesian2spherical(np.vstack(vec_model).T) + upper_bound = np.linalg.norm(np.vstack(upper_bound), axis=0) vec_ref = cartesian2spherical(np.vstack(vec_ref).T).flatten() model[indices] = vec_model.flatten() @@ -218,7 +221,9 @@ def endIter(self): self.opt.lower[indices] = np.kron( np.asarray([0, -np.inf, -np.inf]), np.ones(nC) ) - self.opt.upper[indices[nC:]] = np.inf + self.opt.upper[indices] = np.r_[ + upper_bound, np.ones_like(indices[nC:]) * np.inf + ] updates = {} for misfit in self.misfits: