def logp_err(self, err, data_id=None): """ Error is represemted as a normal. See BaseBackCalculator for more info :param err: :param data_id: """ logp = normal_loglike(err, mu=0, sig=self.errSig_) return logp
def logp_params(self, params): """ Parameters are represented as normals. See BaseBackCalculator for more info :param params: :return: """ logp = normal_loglike(params[0], mu=self.gmu_, sig=self.gstd_) return logp
def calc_opt_params(self, n, beta_sig, sig_eps, exp_val): """ Analytically calculate the optimal back-calculation error. For more info see BaseBackCalculator :param n: number of structures :param beta_sig: [sum of shift back calculations, std for this atom] :param sig_eps: :param exp_val: :return: optimal back calculator error in a list """ beta = beta_sig[0] / n sig_bc = beta_sig[1] alpha = (sig_bc ** 2 / sig_eps ** 2) eps_back_opt = (alpha * (beta - exp_val)) / (1 + alpha) f = normal_loglike(eps_back_opt, mu=0, sig=sig_bc) exp_err = beta - exp_val - eps_back_opt f += normal_loglike(exp_err, mu=0, sig=sig_eps) return [eps_back_opt], f
def calc_opt_params(self, n, beta_sig, sig_eps, exp_val): """ Analytically calculate the optimal back-calculation error. For more info see BaseBackCalculator :param n: number of structures :param beta_sig: [sum of shift back calculations, std for this atom] :param sig_eps: :param exp_val: :return: optimal back calculator error in a list """ beta = beta_sig[0] / n sig_bc = beta_sig[1] alpha = (sig_bc**2 / sig_eps**2) eps_back_opt = (alpha * (beta - exp_val)) / (1 + alpha) f = normal_loglike(eps_back_opt, mu=0, sig=sig_bc) exp_err = beta - exp_val - eps_back_opt f += normal_loglike(exp_err, mu=0, sig=sig_eps) return [eps_back_opt], f
def logp_err(self, err, data_id): """ Error represented as gaussian with std from get_err_sig See BaseBackCalculator for more info :param err: :param data_id: :return: """ sig_err = self.get_err_sig(data_id) logp = normal_loglike(err, mu=0, sig=sig_err) return logp
def logp_params(self, params): """ Parameters are represented as normals. See BaseBackCalculator for more info :param params: :return: """ logp = 0 for i in range(self.nParams_): logp += normal_loglike(params[i], mu=self.muParams_[i], sig=self.sigParams_[i]) return logp
def calc_opt_params(self, n, alphas, sig_eps, exp_val): """ Analytically calculate the optimal A, B and C in the Karplus equation. For more info see BaseBackCalculator :param n: number of structures :param alphas: pre-calculated sum over cosines of phi angles :param sig_eps: :param exp_val: :return: optimal A, B, C in a list """ alpha1 = alphas[0] alpha2 = alphas[1] a = np.zeros((3, 3)) b = np.zeros((3,)) b[0] = ((self.muParams_[0] / self.sigParams_[0] ** 2) + ( (exp_val * alpha2) / (n * sig_eps ** 2))) b[1] = ((self.muParams_[1] / self.sigParams_[1] ** 2) + ( (exp_val * alpha1) / (n * sig_eps ** 2))) b[2] = ((self.muParams_[2] / self.sigParams_[2] ** 2) + ( exp_val / (sig_eps ** 2))) a[0, 0] = ( (1 / self.sigParams_[0] ** 2) + ( alpha2 ** 2 / (sig_eps ** 2 * n ** 2))) a[1, 1] = ( (1 / self.sigParams_[1] ** 2) + ( alpha1 ** 2 / (sig_eps ** 2 * n ** 2))) a[2, 2] = ((1 / self.sigParams_[2] ** 2) + (1 / (sig_eps ** 2))) a[0, 1] = (1 / (sig_eps ** 2 * n ** 2)) * alpha2 * alpha1 a[1, 0] = (1 / (sig_eps ** 2 * n ** 2)) * alpha2 * alpha1 a[0, 2] = (alpha2 / (n * sig_eps ** 2)) a[1, 2] = (alpha1 / (n * sig_eps ** 2)) a[2, 0] = (alpha2 / (n * sig_eps ** 2)) a[2, 1] = (alpha1 / (n * sig_eps ** 2)) opt_params = solve_3_eqs(a, b) exp_err = exp_val - (opt_params[0] * alpha2 / n) - ( opt_params[1] * alpha1 / n) - opt_params[2] f = self.logp_params(opt_params) f += normal_loglike(exp_err, mu=0, sig=sig_eps) return opt_params, f
def calc_opt_params(self, n, alphas, sig_eps, exp_val): """ Analytically calculate the optimal A, B and C in the Karplus equation. For more info see BaseBackCalculator :param n: number of structures :param alphas: pre-calculated sum over cosines of phi angles :param sig_eps: :param exp_val: :return: optimal A, B, C in a list """ alpha1 = alphas[0] alpha2 = alphas[1] a = np.zeros((3, 3)) b = np.zeros((3, )) b[0] = ((self.muParams_[0] / self.sigParams_[0]**2) + ((exp_val * alpha2) / (n * sig_eps**2))) b[1] = ((self.muParams_[1] / self.sigParams_[1]**2) + ((exp_val * alpha1) / (n * sig_eps**2))) b[2] = ((self.muParams_[2] / self.sigParams_[2]**2) + (exp_val / (sig_eps**2))) a[0, 0] = ((1 / self.sigParams_[0]**2) + (alpha2**2 / (sig_eps**2 * n**2))) a[1, 1] = ((1 / self.sigParams_[1]**2) + (alpha1**2 / (sig_eps**2 * n**2))) a[2, 2] = ((1 / self.sigParams_[2]**2) + (1 / (sig_eps**2))) a[0, 1] = (1 / (sig_eps**2 * n**2)) * alpha2 * alpha1 a[1, 0] = (1 / (sig_eps**2 * n**2)) * alpha2 * alpha1 a[0, 2] = (alpha2 / (n * sig_eps**2)) a[1, 2] = (alpha1 / (n * sig_eps**2)) a[2, 0] = (alpha2 / (n * sig_eps**2)) a[2, 1] = (alpha1 / (n * sig_eps**2)) opt_params = solve_3_eqs(a, b) exp_err = exp_val - (opt_params[0] * alpha2 / n) - (opt_params[1] * alpha1 / n) - opt_params[2] f = self.logp_params(opt_params) f += normal_loglike(exp_err, mu=0, sig=sig_eps) return opt_params, f
def calc_opt_params(self, n, alpha, sig_eps, exp_val): """ Analytically calculate the optimal gamma value For more info see BaseBackCalculator :param n: number of structures :param alpha: pre-calculated sum of r^-6 values :param sig_eps: experimental error :param exp_val: experimental data point :return: optimal gamma in a one-element list and the log likelihood of the result """ alpha = alpha[0] num = n ** 3 * sig_eps ** 4 * self.gmu_ num += n ** 2 * sig_eps ** 2 * self.gstd_ ** 2 * alpha * exp_val den = n ** 3 * sig_eps ** 4 den += n * sig_eps ** 2 * self.gstd_ ** 2 * alpha ** 2 opt_params = [num / den] exp_err = exp_val - ((opt_params[0] * alpha) / n) f = self.logp_params(opt_params) f += normal_loglike(exp_err, mu=0, sig=sig_eps) return opt_params, f
def calc_opt_params(self, n, alpha, sig_eps, exp_val): """ Analytically calculate the optimal gamma value For more info see BaseBackCalculator :param n: number of structures :param alpha: pre-calculated sum of r^-6 values :param sig_eps: experimental error :param exp_val: experimental data point :return: optimal gamma in a one-element list and the log likelihood of the result """ alpha = alpha[0] num = n**3 * sig_eps**4 * self.gmu_ num += n**2 * sig_eps**2 * self.gstd_**2 * alpha * exp_val den = n**3 * sig_eps**4 den += n * sig_eps**2 * self.gstd_**2 * alpha**2 opt_params = [num / den] exp_err = exp_val - ((opt_params[0] * alpha) / n) f = self.logp_params(opt_params) f += normal_loglike(exp_err, mu=0, sig=sig_eps) return opt_params, f