def compute_functional_and_gradients(self): f = scaling.wilson_total_nll(d_star_sq=self.d_star_sq, f_obs=self.f_obs, sigma_f_obs=self.sigma_f_obs, epsilon=self.epsilon, sigma_sq=self.sigma_prot_sq, gamma_prot=self.gamma_prot, centric=self.centric, p_scale=self.x[0], p_B_wilson=self.x[1]) g = flex.double( scaling.wilson_total_nll_gradient(d_star_sq=self.d_star_sq, f_obs=self.f_obs, sigma_f_obs=self.sigma_f_obs, epsilon=self.epsilon, sigma_sq=self.sigma_prot_sq, gamma_prot=self.gamma_prot, centric=self.centric, p_scale=self.x[0], p_B_wilson=self.x[1])) self.f = f return f, g
def compute_functional_and_gradients(self): f = scaling.wilson_total_nll( d_star_sq=self.d_star_sq, f_obs=self.f_obs, sigma_f_obs=self.sigma_f_obs, epsilon=self.epsilon, sigma_sq=self.sigma_prot_sq, gamma_prot=self.gamma_prot, centric=self.centric, p_scale=self.x[0], p_B_wilson=self.x[1]) g = flex.double( scaling.wilson_total_nll_gradient( d_star_sq=self.d_star_sq, f_obs=self.f_obs, sigma_f_obs=self.sigma_f_obs, epsilon=self.epsilon, sigma_sq=self.sigma_prot_sq, gamma_prot=self.gamma_prot, centric=self.centric, p_scale=self.x[0], p_B_wilson=self.x[1]) ) self.f = f return f, g
def finite_diffs_iso(p_scale=0.0, p_B_wilson=0.0, centric=False, h=0.0001): d_star_sq = flex.double(10, 0.25) f_obs = flex.double(10, 1.0) centric_array = flex.bool(10, centric) sigma_f_obs = f_obs / 10.0 sigma_sq = flex.double(10, 1.0) epsilon = flex.double(10, 1.0) gamma = flex.double(10, 0.0) stmp1 = scaling.wilson_total_nll(d_star_sq=d_star_sq, f_obs=f_obs, sigma_f_obs=sigma_f_obs, epsilon=epsilon, sigma_sq=sigma_sq, gamma_prot=gamma, centric=centric_array, p_scale=p_scale - h, p_B_wilson=p_B_wilson) stmp2 = scaling.wilson_total_nll(d_star_sq=d_star_sq, f_obs=f_obs, sigma_f_obs=sigma_f_obs, epsilon=epsilon, sigma_sq=sigma_sq, gamma_prot=gamma, centric=centric_array, p_scale=p_scale + h, p_B_wilson=p_B_wilson) s_grad_diff = (stmp1 - stmp2) / (-2.0 * h) btmp1 = scaling.wilson_total_nll(d_star_sq=d_star_sq, f_obs=f_obs, sigma_f_obs=sigma_f_obs, epsilon=epsilon, sigma_sq=sigma_sq, gamma_prot=gamma, centric=centric_array, p_scale=p_scale, p_B_wilson=p_B_wilson - h) btmp2 = scaling.wilson_total_nll(d_star_sq=d_star_sq, f_obs=f_obs, sigma_f_obs=sigma_f_obs, epsilon=epsilon, sigma_sq=sigma_sq, gamma_prot=gamma, centric=centric_array, p_scale=p_scale, p_B_wilson=p_B_wilson + h) b_grad_diff = (btmp1 - btmp2) / (-2.0 * h) grad = scaling.wilson_total_nll_gradient(d_star_sq=d_star_sq, f_obs=f_obs, sigma_f_obs=sigma_f_obs, epsilon=epsilon, sigma_sq=sigma_sq, gamma_prot=gamma, centric=centric_array, p_scale=p_scale, p_B_wilson=p_B_wilson) assert approx_equal(s_grad_diff, grad[0]) assert approx_equal(b_grad_diff, grad[1])
def finite_diffs_iso(p_scale=0.0,p_B_wilson=0.0,centric=False,h=0.0001): d_star_sq = flex.double(10,0.25) f_obs = flex.double(10,1.0) centric_array = flex.bool(10,centric) sigma_f_obs = f_obs/10.0 sigma_sq = flex.double(10,1.0) epsilon = flex.double(10,1.0) gamma =flex.double(10,0.0) stmp1 = scaling.wilson_total_nll(d_star_sq = d_star_sq, f_obs = f_obs, sigma_f_obs = sigma_f_obs, epsilon = epsilon, sigma_sq = sigma_sq, gamma_prot = gamma, centric = centric_array, p_scale = p_scale-h, p_B_wilson = p_B_wilson ) stmp2 = scaling.wilson_total_nll(d_star_sq = d_star_sq, f_obs = f_obs, sigma_f_obs = sigma_f_obs, epsilon = epsilon, sigma_sq = sigma_sq, gamma_prot = gamma, centric = centric_array, p_scale = p_scale+h, p_B_wilson = p_B_wilson) s_grad_diff = (stmp1-stmp2)/(-2.0*h) btmp1 = scaling.wilson_total_nll(d_star_sq = d_star_sq, f_obs = f_obs, sigma_f_obs = sigma_f_obs, epsilon = epsilon, sigma_sq = sigma_sq, gamma_prot = gamma, centric = centric_array, p_scale = p_scale, p_B_wilson = p_B_wilson-h) btmp2 = scaling.wilson_total_nll(d_star_sq = d_star_sq, f_obs = f_obs, sigma_f_obs = sigma_f_obs, epsilon = epsilon, sigma_sq = sigma_sq, gamma_prot = gamma, centric = centric_array, p_scale = p_scale, p_B_wilson = p_B_wilson+h) b_grad_diff = (btmp1-btmp2)/(-2.0*h) grad = scaling.wilson_total_nll_gradient(d_star_sq = d_star_sq, f_obs = f_obs, sigma_f_obs = sigma_f_obs, epsilon = epsilon, sigma_sq = sigma_sq, gamma_prot = gamma, centric = centric_array, p_scale = p_scale, p_B_wilson = p_B_wilson) assert approx_equal(s_grad_diff, grad[0]) assert approx_equal(b_grad_diff, grad[1])