def __call__(self, x, f, g, diag=None, diagco=False):
   for i,v in enumerate(x): self.x[i] = v
   for i,v in enumerate(g): self.g[i] = v
   if (diag is not None):
     for i,v in enumerate(diag): self.diag[i] = v
   from fortran_lbfgs import lbfgs as fortran_lbfgs
   fortran_lbfgs(
     self.n, self.m,
     self.x, f, self.g, diagco, self.diag,
     self.iprint, self.eps, self.xtol, self.w, self.iflag)
   for i,v in enumerate(self.x): x[i] = v
   for i,v in enumerate(self.g): g[i] = v
   if (diag is not None):
     for i,v in enumerate(self.diag): diag[i] = v
示例#2
0
def run_fortran(target_evaluator, termination_params=None, core_params=None):
    "For debugging only!"
    from scitbx.python_utils.misc import store
    from fortran_lbfgs import lbfgs as fortran_lbfgs
    import Numeric
    if (termination_params is None):
        termination_params = termination_parameters()
    if (core_params is None):
        core_params = core_parameters()
    assert termination_params.traditional_convergence_test
    assert core_params.maxfev == 20
    x = target_evaluator.x
    n = x.size()
    m = core_params.m
    gtol = core_params.gtol
    xtol = core_params.xtol
    stpmin = core_params.stpmin
    stpmax = core_params.stpmax
    eps = termination_params.traditional_convergence_test_eps
    x_numeric = Numeric.array(Numeric.arange(n), Numeric.Float64)
    g_numeric = Numeric.array(Numeric.arange(n), Numeric.Float64)
    size_w = n * (2 * m + 1) + 2 * m
    w = Numeric.array(Numeric.arange(size_w), Numeric.Float64)
    diag = Numeric.array(Numeric.arange(n), Numeric.Float64)
    iprint = [1, 0]
    diagco = 0
    iflag = Numeric.array([0], Numeric.Int32)
    minimizer = store(error=None)
    while 1:
        f, g = target_evaluator.compute_functional_and_gradients()
        for i, xi in enumerate(x):
            x_numeric[i] = xi
        for i, gi in enumerate(g):
            g_numeric[i] = gi
        fortran_lbfgs(n, m, x_numeric, f, g_numeric, diagco, diag, iprint, eps,
                      xtol, w, iflag)
        for i, xi in enumerate(x_numeric):
            x[i] = xi
        if (iflag[0] == 0):
            break
        if (iflag[0] < 0):
            minimizer.error = "fortran lbfgs error"
            break
    return minimizer
示例#3
0
def run_fortran(target_evaluator,
                termination_params=None,
                core_params=None):
  "For debugging only!"
  from scitbx.python_utils.misc import store
  from fortran_lbfgs import lbfgs as fortran_lbfgs
  import Numeric
  if (termination_params is None):
    termination_params = termination_parameters()
  if (core_params is None):
    core_params = core_parameters()
  assert termination_params.traditional_convergence_test
  assert core_params.maxfev == 20
  x = target_evaluator.x
  n = x.size()
  m = core_params.m
  gtol = core_params.gtol
  xtol = core_params.xtol
  stpmin = core_params.stpmin
  stpmax = core_params.stpmax
  eps = termination_params.traditional_convergence_test_eps
  x_numeric = Numeric.array(Numeric.arange(n), Numeric.Float64)
  g_numeric = Numeric.array(Numeric.arange(n), Numeric.Float64)
  size_w = n*(2*m+1)+2*m
  w = Numeric.array(Numeric.arange(size_w), Numeric.Float64)
  diag = Numeric.array(Numeric.arange(n), Numeric.Float64)
  iprint = [1, 0]
  diagco = 0
  iflag = Numeric.array([0], Numeric.Int32)
  minimizer = store(error=None)
  while 1:
    f, g = target_evaluator.compute_functional_and_gradients()
    for i,xi in enumerate(x): x_numeric[i] = xi
    for i,gi in enumerate(g): g_numeric[i] = gi
    fortran_lbfgs(n, m, x_numeric, f, g_numeric, diagco, diag,
      iprint, eps, xtol, w, iflag)
    for i,xi in enumerate(x_numeric): x[i] = xi
    if (iflag[0] == 0):
      break
    if (iflag[0] < 0):
      minimizer.error = "fortran lbfgs error"
      break
  return minimizer