Exemplo n.º 1
0
 def hessian_analytical(self, x):
   x1,x2,x3 = x
   result = flex.double(flex.grid(3,3), 0)
   for ti in meyer_function.ts:
     denominator = ti + x3
     assert denominator != 0
     denominator_sq = denominator**2
     assert denominator_sq != 0
     denominator_cu = denominator**3
     assert denominator_cu != 0
     denominator_qa = denominator**4
     assert denominator_qa != 0
     term = math.exp(x2/denominator)
     result[(0,0)] -= 0
     result[(0,1)] -= term/denominator
     result[(0,2)] -= -x2*term/denominator_sq
     result[(1,1)] -= x1*term/denominator_sq
     result[(1,2)] -= -x1*x2*term/denominator_cu - x1*term/denominator_sq
     result[(2,2)] -= x1*x2**2*term/denominator_qa \
                    + 2*x1*x2*term/denominator_cu
   for i in range(0,3):
     for j in range(i+1,3):
       result[(j,i)] = result[(i,j)]
   j = self.jacobian_analytical(x=x)
   result += j.matrix_transpose().matrix_multiply(j)
   return result
Exemplo n.º 2
0
 def hessian_analytical(self, x):
   x1,x2,x3 = x
   result = flex.double(flex.grid(3,3), 0)
   for ti in meyer_function.ts:
     denominator = ti + x3
     assert denominator != 0
     denominator_sq = denominator**2
     assert denominator_sq != 0
     denominator_cu = denominator**3
     assert denominator_cu != 0
     denominator_qa = denominator**4
     assert denominator_qa != 0
     term = math.exp(x2/denominator)
     result[(0,0)] -= 0
     result[(0,1)] -= term/denominator
     result[(0,2)] -= -x2*term/denominator_sq
     result[(1,1)] -= x1*term/denominator_sq
     result[(1,2)] -= -x1*x2*term/denominator_cu - x1*term/denominator_sq
     result[(2,2)] -= x1*x2**2*term/denominator_qa \
                    + 2*x1*x2*term/denominator_cu
   for i in xrange(0,3):
     for j in xrange(i+1,3):
       result[(j,i)] = result[(i,j)]
   j = self.jacobian_analytical(x=x)
   result += j.matrix_transpose().matrix_multiply(j)
   return result
Exemplo n.º 3
0
def exercise_1():
    x = flex.double()
    y = flex.double()
    for x_ in range(0, 10):
        x_ = x_ / 10.
        x.append(x_)
        y.append(2. * math.exp(-3. * x_**2))
    r = scitbx.math.gaussian_fit_1d_analytical(x=x, y=y)
    assert approx_equal(r.a, 2., 1.e-6)
    assert approx_equal(r.b, 3., 1.e-6)
def exercise_1():
  x = flex.double()
  y = flex.double()
  for x_ in xrange(0, 10):
    x_ = x_/10.
    x.append(x_)
    y.append( 2.*math.exp(-3.*x_**2) )
  r = scitbx.math.gaussian_fit_1d_analytical(x = x, y = y)
  assert approx_equal(r.a, 2., 1.e-6)
  assert approx_equal(r.b, 3., 1.e-6)
Exemplo n.º 5
0
 def f(self, x):
   x1,x2,x3 = x
   result = flex.double()
   for yi,ti in zip(meyer_function.ys,
                    meyer_function.ts):
     denominator = ti + x3
     assert denominator != 0
     result.append(x1 * math.exp(x2/denominator) - yi)
   if (x[0] > 100): # numerical instability on some platforms
     raise MeyerFunctionError
   return result
Exemplo n.º 6
0
 def f(self, x):
   x1,x2,x3 = x
   result = flex.double()
   for yi,ti in zip(meyer_function.ys,
                    meyer_function.ts):
     denominator = ti + x3
     assert denominator != 0
     result.append(x1 * math.exp(x2/denominator) - yi)
   if (x[0] > 100): # numerical instability on some platforms
     raise MeyerFunctionError
   return result
Exemplo n.º 7
0
  def mod_scores( self, x, k ):
    if x> 10: x=10.0
    gam = gamma_complete(k/2.0)
    part1 = 2**(k/2.0)
    part2 = x**((k/2.0)-1)
    part3 = math.exp(-x/2.0)
    tot1  = part2*part3/(part1*gam)

    bart1 = gamma_incomplete_complement(k/2.0, x/2.0)
    tot2  = bart1/gam

    return math.log(tot1), math.log(tot2)
Exemplo n.º 8
0
 def jacobian_analytical(self, x):
   x1,x2,x3 = x
   result = flex.double()
   for ti in meyer_function.ts:
     denominator = ti + x3
     assert denominator != 0
     denominator_sq = denominator**2
     assert denominator_sq != 0
     term = math.exp(x2/denominator)
     result.extend(flex.double([
       term,
       x1*term/denominator,
       -x1*term*x2/denominator_sq]))
   result.resize(flex.grid(self.m, self.n))
   return result
Exemplo n.º 9
0
 def jacobian_analytical(self, x):
   x1,x2,x3 = x
   result = flex.double()
   for ti in meyer_function.ts:
     denominator = ti + x3
     assert denominator != 0
     denominator_sq = denominator**2
     assert denominator_sq != 0
     term = math.exp(x2/denominator)
     result.extend(flex.double([
       term,
       x1*term/denominator,
       -x1*term*x2/denominator_sq]))
   result.resize(flex.grid(self.m, self.n))
   return result
Exemplo n.º 10
0
 def compute_all( self ):
   self.rg2s = []
   self.lnis = []
   self.free_scores = []
   self.stop_qs = []
   self.start_qs = []
   for lim in self.lims:
     rg2, lni, score, free_score, stop_q, start_q = self.compute_rg( lim[0], lim[1] )
     rg2, lni, score, free_score, start_q, stop_q = self.filter( rg2, lni, score, free_score, stop_q, start_q  )
     if rg2 is not None:
       self.accumulator.add_data( math.sqrt(rg2), math.exp(lni), free_score )
       self.rg2s.append( math.sqrt(rg2) )
       self.lnis.append( lni )
       self.free_scores.append( score )
       self.stop_qs.append( stop_q )
       self.start_qs.append( stop_q )
Exemplo n.º 11
0
 def gradient(self, occupancy):
     if (occupancy > self.occupancy_max): return 0
     if (occupancy < -1): occupancy = -1 - math.log(-occupancy)
     s = self.penalty_scale
     return -s * self.penalty_factor * math.exp(
         -s * occupancy * self.penalty_factor)
Exemplo n.º 12
0
 def functional(self, occupancy):
     if (occupancy > self.occupancy_max): return 0
     if (occupancy < -1): occupancy = -1 - math.log(-occupancy)
     s = self.penalty_scale
     return math.exp(-s * occupancy * self.penalty_factor)
Exemplo n.º 13
0
 def gradient(self, occupancy):
   if (occupancy > self.occupancy_max): return 0
   if (occupancy < -1): occupancy = -1 - math.log(-occupancy)
   s = self.penalty_scale
   return -s*self.penalty_factor*math.exp(-s*occupancy*self.penalty_factor)
Exemplo n.º 14
0
 def functional(self, occupancy):
   if (occupancy > self.occupancy_max): return 0
   if (occupancy < -1): occupancy = -1 - math.log(-occupancy)
   s = self.penalty_scale
   return math.exp(-s*occupancy*self.penalty_factor)