def misfit(m): """ Objective function to minimize: misfit between modelled and observed group velocities """ # vector of parameters = [vs of crustal layers] # + [dz of sediment and crustal layers] vs_crust = m[:nb_crust_layers] # building the model vsmodel = psdepthmodel.VsModel(vs=np.r_[vs_sediments, vs_crust, vs_mantle], dz=m[nb_crust_layers:], ratio_vp_vs=ratio_vp_vs, ratio_rho_vs=ratio_rho_vs) return vsmodel.misfit_to_vg(periods=PERIODS, vg=meanvg, sigmavg=sigmavg)
'fun': lambda m: vs_mantle - m[nb_crust_layers - 1] - VS_MIN_INCREMENT } constraints.append(constr) # constrained optimization mopt = minimize(misfit, x0=m0, method='COBYLA', constraints=constraints)['x'] vscrustopt, dzsedopt, dzcrustopt = (mopt[:nb_crust_layers], mopt[nb_crust_layers], mopt[nb_crust_layers + 1:]) # using the best-fitting model as initial model of the MC exploration vsmodelinit = psdepthmodel.VsModel(vs=np.r_[vs_sediments, vscrustopt, vs_mantle], dz=np.r_[dzsedopt, dzcrustopt], ratio_vp_vs=ratio_vp_vs, ratio_rho_vs=ratio_rho_vs, name='Initial model') # ======================= # Monte-Carlo exploration # ======================= # initializing parameters vscrustlayers = [] dzcrustlayers = [] for i in range(nb_crust_layers): vscrustlayer = psmcsampling.Parameter( name='Vs of crustal layer #{}'.format(i + 1), minval=vs_crust_bounds[0], maxval=vs_crust_bounds[1],