Example #1
0
def estimate_hessian(dof, eps=1e-4):
    """Estimate the Hessian using the symmetric finite difference approximation.

       **Arguments:**

       dof
            A DOF object

       **Optional arguments:**

       eps
            The magnitude of the displacements
    """
    with log.section('HESS'), timer.section('Hessian'):
        # Loop over all displacements
        if log.do_medium:
            log('The following displacements are computed:')
            log('DOF     Dir Energy')
            log.hline()
        x1 = dof.x0.copy()
        rows = np.zeros((len(x1), len(x1)), float)
        for i in xrange(len(x1)):
            x1[i] = dof.x0[i] + eps
            epot, gradient_p = dof.fun(x1, do_gradient=True)
            if log.do_medium:
                log('% 7i pos %s' % (i, log.energy(epot)))
            x1[i] = dof.x0[i] - eps
            epot, gradient_m = dof.fun(x1, do_gradient=True)
            if log.do_medium:
                log('% 7i neg %s' % (i, log.energy(epot)))
            rows[i] = (gradient_p-gradient_m)/(2*eps)
            x1[i] = dof.x0[i]
        dof.reset()
        if log.do_medium:
            log.hline()

        # Enforce symmetry and return
        return 0.5*(rows + rows.T)
Example #2
0
def estimate_hessian(dof, eps=1e-4):
    """Estimate the Hessian using the symmetric finite difference approximation.

       **Arguments:**

       dof
            A DOF object

       **Optional arguments:**

       eps
            The magnitude of the displacements
    """
    with log.section('HESS'), timer.section('Hessian'):
        # Loop over all displacements
        if log.do_medium:
            log('The following displacements are computed:')
            log('DOF     Dir Energy')
            log.hline()
        x1 = dof.x0.copy()
        rows = np.zeros((len(x1), len(x1)), float)
        for i in xrange(len(x1)):
            x1[i] = dof.x0[i] + eps
            epot, gradient_p = dof.fun(x1, do_gradient=True)
            if log.do_medium:
                log('% 7i pos %s' % (i, log.energy(epot)))
            x1[i] = dof.x0[i] - eps
            epot, gradient_m = dof.fun(x1, do_gradient=True)
            if log.do_medium:
                log('% 7i neg %s' % (i, log.energy(epot)))
            rows[i] = (gradient_p - gradient_m) / (2 * eps)
            x1[i] = dof.x0[i]
        dof.reset()
        if log.do_medium:
            log.hline()

        # Enforce symmetry and return
        return 0.5 * (rows + rows.T)
Example #3
0
 def __call__(self):
     """Perform a trial move and calculate the associated energy difference,
     decide whether it is accepted or not, and update the state of the
     MC simulation accordingly
     """
     with timer.section("MC %s move" % self.log_name):
         e = self.compute()
         p = self.probability(e)
         if np.random.rand()>p:
             accepted = False
             self.reject()
         else:
             accepted = True
             self.mc.energy += e
             self.accept()
     if log.do_debug:
         log("MC %s: N = %d energy difference = %s acceptance probability = %6.2f %% accepted = %s"
             % (self.__class__.__name__, self.mc.N, log.energy(e), p*100.0, accepted))
     return accepted
Example #4
0
File: opt.py Project: boegel/yaff
 def __call__(self, iterative):
     if log.do_medium:
         if self.time0 is None:
             self.time0 = time.time()
             if log.do_medium:
                 log.hline()
                 log('Conv.val. =&the highest ratio of a convergence criterion over its threshold.')
                 log('N         =&the number of convergence criteria that is not met.')
                 log('Worst     =&the name of the convergence criterion that is worst.')
                 log('counter  Conv.val.  N           Worst     Energy   Walltime')
                 log.hline()
         log('%7i % 10.3e %2i %15s %s %10.1f' % (
             iterative.counter,
             iterative.dof.conv_val,
             iterative.dof.conv_count,
             iterative.dof.conv_worst,
             log.energy(iterative.epot),
             time.time() - self.time0,
         ))
Example #5
0
File: opt.py Project: molmod/yaff
 def __call__(self, iterative):
     if log.do_medium:
         if self.time0 is None:
             self.time0 = time.time()
             if log.do_medium:
                 log.hline()
                 log('Conv.val. =&the highest ratio of a convergence criterion over its threshold.')
                 log('N         =&the number of convergence criteria that is not met.')
                 log('Worst     =&the name of the convergence criterion that is worst.')
                 log('counter  Conv.val.  N           Worst     Energy   Walltime')
                 log.hline()
         log('%7i % 10.3e %2i %15s %s %10.1f' % (
             iterative.counter,
             iterative.dof.conv_val,
             iterative.dof.conv_count,
             iterative.dof.conv_worst,
             log.energy(iterative.epot),
             time.time() - self.time0,
         ))
Example #6
0
 def log(self):
     return '%10d %10.6f %s %s' % ( self.N, self.Nmean,
             log.energy(self.energy), log.energy(self.emean))
Example #7
0
 def log(self):
     return '%s %s %s %s' % ( log.volume(self.current_configuration.cell.volume),
             log.volume(self.Vmean), log.energy(self.energy), log.energy(self.emean))
Example #8
0
 def log(self):
     return '%s %s' % (log.energy(self.energy), log.energy(self.emean))