def test_mappings_and_cell_weights(self): mesh = Mesh.TensorMesh([8, 7, 6]) m = np.random.rand(2*mesh.nC) v = np.random.rand(2*mesh.nC) cell_weights = np.random.rand(mesh.nC) wires = Maps.Wires(('sigma', mesh.nC), ('mu', mesh.nC)) reg = Regularization.SimpleSmall( mesh, mapping=wires.sigma, cell_weights=cell_weights ) objfct = ObjectiveFunction.L2ObjectiveFunction( W=Utils.sdiag(np.sqrt(cell_weights)), mapping=wires.sigma ) self.assertTrue(reg(m) == objfct(m)) self.assertTrue(np.all(reg.deriv(m) == objfct.deriv(m))) self.assertTrue(np.all(reg.deriv2(m, v=v) == objfct.deriv2(m, v=v)))
actCells = (mesh.gridCC[:, 2] < 0.) & (mesh.gridCC[:, 2] > -2.) problem_inv = VRM.Problem_Linear(mesh, indActive=actCells, ref_factor=3, ref_radius=[1.25, 2.5, 3.75]) problem_inv.pair(survey_inv) survey_inv.set_active_interval(1e-3, 1e-2) survey_inv.dobs = fields_tot[survey_inv.t_active] survey_inv.std = 0.05 * np.abs(fields_tot[survey_inv.t_active]) survey_inv.eps = 1e-11 # Setup and run inversion dmis = DataMisfit.l2_DataMisfit(survey_inv) w = mkvc((np.sum(np.array(problem_inv.A)**2, axis=0)))**0.5 w = w / np.max(w) reg = Regularization.SimpleSmall(mesh=mesh, indActive=actCells, cell_weights=w) opt = Optimization.ProjectedGNCG(maxIter=20, lower=0., upper=1e-2, maxIterLS=20, tolCG=1e-4) invProb = InvProblem.BaseInvProblem(dmis, reg, opt) directives = [ Directives.BetaSchedule(coolingFactor=2, coolingRate=1), Directives.TargetMisfit() ] inv = Inversion.BaseInversion(invProb, directiveList=directives) xi_0 = 1e-3 * np.ones(actCells.sum()) xi_rec = inv.run(xi_0)