Ignore:
Timestamp:
Apr 10, 2018, 6:43:12 AM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization_continued, Exclude_Hydrogens_annealWithBondGraph, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, PythonUI_with_named_parameters, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
d3e1d5
Parents:
075357
git-author:
Frederik Heber <frederik.heber@…> (09/12/17 09:55:19)
git-committer:
Frederik Heber <frederik.heber@…> (04/10/18 06:43:12)
Message:

FIX: annealWithBondgraph() did not check for zero GradientDifference.

  • extracted Barzilai-Borwein stepwidth into extra function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Dynamics/ForceAnnealing.hpp

    r075357 re21d55  
    123123  }
    124124
     125  /** Helper function to calculate the Barzilai-Borwein stepwidth.
     126   *
     127   * \param _PositionDifference difference in position between current and last step
     128   * \param _GradientDifference difference in gradient between current and last step
     129   * \return step width according to Barzilai-Borwein
     130   */
     131  double getBarzilaiBorweinStepwidth(const Vector &_PositionDifference, const Vector &_GradientDifference)
     132  {
     133    double stepwidth = 0.;
     134    if (_GradientDifference.NormSquared() > MYEPSILON)
     135      stepwidth = fabs(_PositionDifference.ScalarProduct(_GradientDifference))/
     136          _GradientDifference.NormSquared();
     137    if (fabs(stepwidth) < 1e-10) {
     138      // dont' warn in first step, deltat usage normal
     139      if (currentStep != 1)
     140        ELOG(1, "INFO: Barzilai-Borwein stepwidth is zero, using deltat " << currentDeltat << " instead.");
     141      stepwidth = currentDeltat;
     142    }
     143    return stepwidth;
     144  }
     145
    125146  /** Performs Gradient optimization on the atoms.
    126147   *
     
    150171
    151172      // we use Barzilai-Borwein update with position reversed to get descent
    152       const Vector PositionDifference = currentPosition - oldPosition;
    153       const Vector GradientDifference = (currentGradient - oldGradient);
    154       double stepwidth = 0.;
    155       if (GradientDifference.Norm() > MYEPSILON)
    156         stepwidth = fabs(PositionDifference.ScalarProduct(GradientDifference))/
    157             GradientDifference.NormSquared();
    158       if (fabs(stepwidth) < 1e-10) {
    159         // dont' warn in first step, deltat usage normal
    160         if (currentStep != 1)
    161           ELOG(1, "INFO: Barzilai-Borwein stepwidth is zero, using deltat " << currentDeltat << " instead.");
    162         stepwidth = currentDeltat;
    163       }
     173      const double stepwidth = getBarzilaiBorweinStepwidth(
     174          currentPosition - oldPosition, currentGradient - oldGradient);
    164175      Vector PositionUpdate = stepwidth * currentGradient;
    165176      LOG(3, "DEBUG: Update would be " << stepwidth << "*" << currentGradient << " = " << PositionUpdate);
     
    232243
    233244      // we use Barzilai-Borwein update with position reversed to get descent
    234       const Vector GradientDifference = (currentGradient - oldGradient);
    235       const double stepwidth =
    236           fabs((currentPosition - oldPosition).ScalarProduct(GradientDifference))/
    237           GradientDifference.NormSquared();
    238       Vector PositionUpdate = stepwidth * currentGradient;
    239       if (fabs(stepwidth) < 1e-10) {
    240         // dont' warn in first step, deltat usage normal
    241         if (currentStep != 1)
    242           ELOG(1, "INFO: Barzilai-Borwein stepwidth is zero, using deltat " << currentDeltat << " instead.");
    243         PositionUpdate = currentDeltat * currentGradient;
    244       }
    245       LOG(3, "DEBUG: Update would be " << PositionUpdate);
     245      const double stepwidth = getBarzilaiBorweinStepwidth(
     246          currentPosition - oldPosition, currentGradient - oldGradient);
     247      const Vector PositionUpdate = stepwidth * currentGradient;
     248      LOG(3, "DEBUG: Update would be " << stepwidth << "*" << currentGradient << " = " << PositionUpdate);
    246249
    247250//      // add update to central atom
Note: See TracChangeset for help on using the changeset viewer.