def calibrate_vp(self): method = 'L-BFGS-B' options = dict() vp0 = (self.km0, self.gm0, self.alpha0, self.kfl0) vp_bounds = ((self.km_min, self.km_max), (self.gm_min, self.gm_max), (self.alpha_min, self.alpha_max), (self.kfl_min, self.kfl_max)) vp_par = minimize(self.vp_residual, vp0, method=method, bounds=vp_bounds, options=options) self.Km = vp_par.x[0] self.Gm = vp_par.x[1] self.alpha = vp_par.x[2] self.Kfl = vp_par.x[3] if self.vp_std is None: self.vp_std = np.std(self.vp - RP.Vp(self.Km, self.Gm, self.phi, self.alpha, self.Kfl, self.rho), ddof=0)
def sample(self, n=1): phi_std = self.phi_std*self.phi_std_factor phi = stats.norm.rvs(loc=self.phi_mean, scale=phi_std, size=n) rho_mean = RP.rho(phi, self.rho_gr, self.rho_fl) rho_std = self.rho_std*self.rho_std_factor rho = stats.norm.rvs(loc=rho_mean, scale=rho_std, size=n) vp_mean = RP.Vp(self.Km, self.Gm, phi, self.alpha, self.Kfl, rho) vp_std = self.vp_std*self.vp_std_factor vp = stats.norm.rvs(loc=vp_mean, scale=vp_std, size=n) if self.otherspm is not None: others = self.otherspm.sample(n) return np.vstack([phi, rho, vp, others.T]).T else: return np.vstack([phi, rho, vp]).T
def prob(self, x): phi = x[:, 0] rho = x[:, 1] vp = x[:, 2] phi_std = self.phi_std*self.phi_std_factor p_phi = stats.norm.pdf(phi, loc=self.phi_mean, scale=phi_std) rho_mean = RP.rho(phi, self.rho_gr, self.rho_fl) rho_std = self.rho_std*self.rho_std_factor p_rho = stats.norm.pdf(rho, loc=rho_mean, scale=rho_std) vp_mean = RP.Vp(self.Km, self.Gm, phi, self.alpha, self.Kfl, rho) vp_std = self.vp_std*self.vp_std_factor p_vp = stats.norm.pdf(vp, loc=vp_mean, scale=vp_std) p_others = 1.0 if self.otherspm is not None: p_others = self.otherspm.prob(x[:, 3:]) return p_phi*p_rho*p_vp*p_others
def vp_residual(self, x): return np.mean((self.vp - RP.Vp(x[0], x[1], self.phi, x[2], x[3], self.rho))**2)