Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
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])
Ejemplo n.º 4
0
def test_likelihood_iso():
    d_star_sq = flex.double(10, 0.250)
    f_obs = flex.double(10, 1.0)
    sigma_f_obs = flex.double(10, 0.0000)
    sigma_sq = flex.double(10, 1.0)
    epsilon = flex.double(10, 1.0)
    gamma = flex.double(10, 0.0)
    centric = flex.bool(10, True)
    acentric = flex.bool(10, False)
    p_scale = 0.0
    p_B_wilson = 0.0

    centric_single_trans = scaling.wilson_single_nll(
        d_star_sq=d_star_sq[0],
        f_obs=f_obs[0],
        sigma_f_obs=sigma_f_obs[0],
        epsilon=epsilon[0],
        sigma_sq=sigma_sq[0],
        gamma_prot=gamma[0],
        centric=centric[0],
        p_scale=p_scale,
        p_B_wilson=p_B_wilson,
        transform=True)

    centric_single_no_trans = scaling.wilson_single_nll(
        d_star_sq=d_star_sq[0],
        f_obs=f_obs[0],
        sigma_f_obs=sigma_f_obs[0],
        epsilon=epsilon[0],
        sigma_sq=sigma_sq[0],
        gamma_prot=gamma[0],
        centric=centric[0],
        p_scale=1.0,
        p_B_wilson=p_B_wilson,
        transform=False)

    assert approx_equal(centric_single_trans, 1.072364)  ## from Mathematica
    assert approx_equal(centric_single_trans, centric_single_no_trans)

    acentric_single_trans = scaling.wilson_single_nll(
        d_star_sq=d_star_sq[0],
        f_obs=f_obs[0],
        sigma_f_obs=sigma_f_obs[0],
        epsilon=epsilon[0],
        sigma_sq=sigma_sq[0],
        gamma_prot=gamma[0],
        centric=acentric[0],
        p_scale=p_scale,
        p_B_wilson=p_B_wilson)

    acentric_single_no_trans = scaling.wilson_single_nll(
        d_star_sq=d_star_sq[0],
        f_obs=f_obs[0],
        sigma_f_obs=sigma_f_obs[0],
        epsilon=epsilon[0],
        sigma_sq=sigma_sq[0],
        gamma_prot=gamma[0],
        centric=acentric[0],
        p_scale=1.0,
        p_B_wilson=p_B_wilson,
        transform=False)

    assert approx_equal(acentric_single_trans, 0.306853)  ## from Mathematica
    assert approx_equal(acentric_single_trans, acentric_single_no_trans)

    centric_total = 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,
                                             p_scale=p_scale,
                                             p_B_wilson=p_B_wilson)

    acentric_total = 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=acentric,
                                              p_scale=p_scale,
                                              p_B_wilson=p_B_wilson)

    assert approx_equal(centric_total, centric_single_trans * 10.0)
    assert approx_equal(acentric_total, acentric_single_trans * 10.0)
Ejemplo n.º 5
0
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])
Ejemplo n.º 6
0
def test_likelihood_iso():
  d_star_sq = flex.double(10,0.250)
  f_obs = flex.double(10,1.0)
  sigma_f_obs = flex.double(10,0.0000)
  sigma_sq = flex.double(10,1.0)
  epsilon = flex.double(10,1.0)
  gamma = flex.double(10,0.0)
  centric = flex.bool(10,True)
  acentric = flex.bool(10,False)
  p_scale = 0.0
  p_B_wilson = 0.0



  centric_single_trans = scaling.wilson_single_nll(
    d_star_sq = d_star_sq[0],
    f_obs = f_obs[0],
    sigma_f_obs = sigma_f_obs[0],
    epsilon = epsilon[0],
    sigma_sq = sigma_sq[0],
    gamma_prot = gamma[0],
    centric = centric[0],
    p_scale = p_scale,
    p_B_wilson = p_B_wilson,
    transform = True)

  centric_single_no_trans = scaling.wilson_single_nll(
    d_star_sq = d_star_sq[0],
    f_obs = f_obs[0],
    sigma_f_obs = sigma_f_obs[0],
    epsilon = epsilon[0],
    sigma_sq = sigma_sq[0],
    gamma_prot = gamma[0],
    centric = centric[0],
    p_scale = 1.0,
    p_B_wilson = p_B_wilson,
    transform = False)

  assert approx_equal(centric_single_trans,  1.072364 ) ## from Mathematica
  assert approx_equal(centric_single_trans, centric_single_no_trans)

  acentric_single_trans = scaling.wilson_single_nll(
    d_star_sq = d_star_sq[0],
    f_obs = f_obs[0],
    sigma_f_obs = sigma_f_obs[0],
    epsilon = epsilon[0],
    sigma_sq = sigma_sq[0],
    gamma_prot = gamma[0],
    centric = acentric[0],
    p_scale = p_scale,
    p_B_wilson = p_B_wilson)

  acentric_single_no_trans  = scaling.wilson_single_nll(
    d_star_sq = d_star_sq[0],
    f_obs = f_obs[0],
    sigma_f_obs = sigma_f_obs[0],
    epsilon = epsilon[0],
    sigma_sq = sigma_sq[0],
    gamma_prot = gamma[0],
    centric = acentric[0],
    p_scale = 1.0,
    p_B_wilson =p_B_wilson,
    transform = False)

  assert approx_equal(acentric_single_trans, 0.306853) ## from Mathematica
  assert approx_equal(acentric_single_trans, acentric_single_no_trans)


  centric_total = 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,
    p_scale = p_scale,
    p_B_wilson = p_B_wilson)

  acentric_total = 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 = acentric,
    p_scale = p_scale,
    p_B_wilson = p_B_wilson)

  assert approx_equal(centric_total, centric_single_trans*10.0)
  assert approx_equal(acentric_total, acentric_single_trans*10.0)