def run_inversion( self, maxIter=60, m0=0.0, mref=0.0, percentage=5, floor=0.1, chifact=1, beta0_ratio=1.0, coolingFactor=1, n_iter_per_beta=1, alpha_s=1.0, alpha_x=1.0, alpha_z=1.0, use_target=False, use_tikhonov=True, use_irls=False, p_s=2, p_x=2, p_y=2, p_z=2, beta_start=None, ): self.uncertainty = percentage * abs(self.data_prop.dobs) * 0.01 + floor m0 = np.ones(self.mesh_prop.nC) * m0 mref = np.ones(self.mesh_prop.nC) * mref if ~use_tikhonov: reg = regularization.Sparse( self.mesh_prop, alpha_s=alpha_s, alpha_x=alpha_x, alpha_y=alpha_z, mref=mref, mapping=maps.IdentityMap(self.mesh_prop), cell_weights=self.mesh_prop.vol, ) else: reg = regularization.Tikhonov( self.mesh_prop, alpha_s=alpha_s, alpha_x=alpha_x, alpha_y=alpha_z, mref=mref, mapping=maps.IdentityMap(self.mesh_prop), ) dataObj = data.Data(self.survey_prop, dobs=self.dobs, noise_floor=self.uncertainty) dmis = data_misfit.L2DataMisfit(simulation=self.simulation_prop, data=dataObj) dmis.W = 1.0 / self.uncertainty opt = optimization.ProjectedGNCG(maxIter=maxIter, maxIterCG=20) opt.lower = 0.0 opt.remember("xc") opt.tolG = 1e-10 opt.eps = 1e-10 invProb = inverse_problem.BaseInvProblem(dmis, reg, opt) beta_schedule = directives.BetaSchedule(coolingFactor=coolingFactor, coolingRate=n_iter_per_beta) save = directives.SaveOutputEveryIteration() print(chifact) if use_irls: IRLS = directives.Update_IRLS(f_min_change=1e-4, minGNiter=1, silent=False, max_irls_iterations=40, beta_tol=5e-1, coolEpsFact=1.3, chifact_start=chifact) if beta_start is None: directives_list = [ directives.BetaEstimate_ByEig(beta0_ratio=beta0_ratio), IRLS, save, ] else: directives_list = [IRLS, save] invProb.beta = beta_start reg.norms = np.c_[p_s, p_x, p_z, 2] else: target = directives.TargetMisfit(chifact=chifact) directives_list = [ directives.BetaEstimate_ByEig(beta0_ratio=beta0_ratio), beta_schedule, save, ] if use_target: directives_list.append(target) inv = inversion.BaseInversion(invProb, directiveList=directives_list) mopt = inv.run(m0) model = opt.recall("xc") model.append(mopt) pred = [] for m in model: pred.append(self.simulation_prop.dpred(m)) return model, pred, save
maxIterLS=20, maxIterCG=10, tolCG=1e-3) invProb = inverse_problem.BaseInvProblem(global_misfit, reg, opt) betaest = directives.BetaEstimate_ByEig(beta0_ratio=1e-1) # Here is where the norms are applied # Use pick a threshold parameter empirically based on the distribution of # model parameters update_IRLS = directives.Update_IRLS( f_min_change=1e-4, max_irls_iterations=0, coolEpsFact=1.5, beta_tol=1e-2, ) saveDict = directives.SaveOutputEveryIteration(save_txt=False) update_Jacobi = directives.UpdatePreconditioner() sensitivity_weights = directives.UpdateSensitivityWeights(everyIter=False) inv = inversion.BaseInversion( invProb, directiveList=[ update_IRLS, sensitivity_weights, betaest, update_Jacobi, saveDict ], ) # Run the inversion mrec = inv.run(m0) # Plot the result ax = plt.subplot(1, 2, 1) mesh.plotSlice(inject_global * model, normal="Y", ax=ax, grid=True)
# # Apply and update sensitivity weighting as the model updates update_sensitivity_weighting = directives.UpdateSensitivityWeights() # Defining a starting value for the trade-off parameter (beta) between the data # misfit and the regularization. starting_beta = directives.BetaEstimate_ByEig(beta0_ratio=1e1) # Set the rate of reduction in trade-off parameter (beta) each time the # the inverse problem is solved. And set the number of Gauss-Newton iterations # for each trade-off paramter value. beta_schedule = directives.BetaSchedule(coolingFactor=3, coolingRate=2) # Options for outputting recovered models and predicted data for each beta. save_iteration = directives.SaveOutputEveryIteration(save_txt=False) # Setting a stopping criteria for the inversion. target_misfit = directives.TargetMisfit(chifact=1) # Update preconditioner update_jacobi = directives.UpdatePreconditioner() directives_list = [ update_sensitivity_weighting, starting_beta, beta_schedule, save_iteration, target_misfit, update_jacobi, ]