def calibrate_rho(self): method = 'L-BFGS-B' options = dict() rho0 = (self.rho_gr0, self.rho_fl0) rho_bounds = ((self.rho_gr_min, self.rho_gr_max), (self.rho_fl_min, self.rho_fl_max)) rho_par = minimize(self.rho_residual, rho0, method=method, bounds=rho_bounds, options=options) self.rho_gr = rho_par.x[0] self.rho_fl = rho_par.x[1] if self.rho_std is None: self.rho_std = np.std(self.rho - RP.rho(self.phi, self.rho_gr, self.rho_fl), 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 rho_residual(self, x): return np.mean((self.rho - RP.rho(self.phi, x[0], x[1]))**2)