Changeset d03292


Ignore:
Timestamp:
Dec 19, 2012, 3:26:11 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
17b3598
Parents:
f48ad3
git-author:
Frederik Heber <heber@…> (10/05/12 19:18:28)
git-committer:
Frederik Heber <heber@…> (12/19/12 15:26:11)
Message:

Implemented box constraints for FunctionModel, using a feature of LevMar.

  • we need lower and upper bounds for each parameter. These can be passed on to specific function of LevMar.
  • LevMartester checks whether isBoxConstraints apply and requires parameter derivatives in this case.
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/FunctionApproximation/FunctionApproximation.cpp

    rf48ad3 rd03292  
    169169    // give this pointer as additional data to construct function pointer in
    170170    // LevMarCallback and call
    171     if (mode == FiniteDifferences) {
    172       ret=dlevmar_dif(
    173           &FunctionApproximation::LevMarCallback,
    174           p, x, m, n, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
    175     } else if (mode == ParameterDerivative) {
    176       ret=dlevmar_der(
    177           &FunctionApproximation::LevMarCallback,
    178           &FunctionApproximation::LevMarDerivativeCallback,
    179           p, x, m, n, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
     171    if (model.isBoxConstraint()) {
     172      FunctionModel::parameters_t lowerbound = model.getLowerBoxConstraints();
     173      FunctionModel::parameters_t upperbound = model.getUpperBoxConstraints();
     174      double *lb = new double[m];
     175      double *ub = new double[m];
     176      for (size_t i=0;i<m;++i) {
     177        lb[i] = lowerbound[i];
     178        ub[i] = upperbound[i];
     179      }
     180      if (mode == FiniteDifferences) {
     181        ret=dlevmar_bc_dif(
     182            &FunctionApproximation::LevMarCallback,
     183            p, x, m, n, lb, ub, NULL, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
     184      } else if (mode == ParameterDerivative) {
     185        ret=dlevmar_bc_der(
     186            &FunctionApproximation::LevMarCallback,
     187            &FunctionApproximation::LevMarDerivativeCallback,
     188            p, x, m, n, lb, ub, NULL, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
     189      } else {
     190        ASSERT(0, "FunctionApproximation::operator() - Unknown jacobian method chosen.");
     191      }
     192      delete[] lb;
     193      delete[] ub;
    180194    } else {
    181195      ASSERT(0, "FunctionApproximation::operator() - Unknown jacobian method chosen.");
     196      if (mode == FiniteDifferences) {
     197        ret=dlevmar_dif(
     198            &FunctionApproximation::LevMarCallback,
     199            p, x, m, n, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
     200      } else if (mode == ParameterDerivative) {
     201        ret=dlevmar_der(
     202            &FunctionApproximation::LevMarCallback,
     203            &FunctionApproximation::LevMarDerivativeCallback,
     204            p, x, m, n, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
     205      } else {
     206        ASSERT(0, "FunctionApproximation::operator() - Unknown jacobian method chosen.");
     207      }
    182208    }
    183209
  • src/FunctionApproximation/FunctionModel.hpp

    rf48ad3 rd03292  
    7878   */
    7979  virtual results_t parameter_derivative(const arguments_t &arguments, const size_t index) const=0;
     80
     81  /** States whether lower and upper boundaries should be used to constraint
     82   * the parameter search for this function model.
     83   *
     84   * \return true - constraints should be used, false - else
     85   */
     86  virtual bool isBoxConstraint() const=0;
     87
     88  /** Returns a vector which are the lower boundaries for each parameter_t
     89   * of this FunctionModel.
     90   *
     91   * \return vector of parameter_t resembling lowest allowed values
     92   */
     93  virtual parameters_t getLowerBoxConstraints() const=0;
     94
     95  /** Returns a vector which are the upper boundaries for each parameter_t
     96   * of this FunctionModel.
     97   *
     98   * \return vector of parameter_t resembling highest allowed values
     99   */
     100  virtual parameters_t getUpperBoxConstraints() const=0;
    80101};
    81102
  • src/LevMartester.cpp

    rf48ad3 rd03292  
    318318    FunctionApproximation approximator(1, 1, model);
    319319    approximator.setTrainingData(DistanceEnergyVector.first,DistanceEnergyVector.second);
    320     approximator(FunctionApproximation::ParameterDerivative);
     320    if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
     321      approximator(FunctionApproximation::ParameterDerivative);
     322    else
     323      ELOG(0, "We require parameter derivatives for a box constraint minimization.");
    321324    params = model.getParameters();
    322325
     
    392395        model); // CH4 has 5 atoms, hence 5*4/2 distances
    393396    approximator.setTrainingData(DistanceEnergyVector.first,DistanceEnergyVector.second);
    394     approximator(FunctionApproximation::FiniteDifferences);
     397    if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
     398      approximator(FunctionApproximation::ParameterDerivative);
     399    else
     400      ELOG(0, "We require parameter derivatives for a box constraint minimization.");
    395401    params = model.getParameters();
    396402
  • src/Potentials/Specifics/ManyBodyPotential_Tersoff.hpp

    rf48ad3 rd03292  
    1616#include <boost/function.hpp>
    1717#include <cmath>
     18#include <limits>
    1819
    1920#include "CodePatterns/Assert.hpp"
     
    120121   */
    121122  results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
     123
     124  /** States whether lower and upper boundaries should be used to constraint
     125   * the parameter search for this function model.
     126   *
     127   * \return true - constraints should be used, false - else
     128   */
     129  bool isBoxConstraint() const {
     130    return true;
     131  }
     132
     133  /** Returns a vector which are the lower boundaries for each parameter_t
     134   * of this FunctionModel.
     135   *
     136   * \return vector of parameter_t resembling lowest allowed values
     137   */
     138  parameters_t getLowerBoxConstraints() const {
     139    parameters_t lowerbound(getParameterDimension(), -std::numeric_limits<double>::max());
     140//    lowerbound[R] = 0.;
     141//    lowerbound[S] = 0.;
     142//    lowerbound[lambda3] = 0.;
     143//    lowerbound[alpha] = 0.;
     144    lowerbound[beta] = std::numeric_limits<double>::min();
     145    lowerbound[n] = std::numeric_limits<double>::min();
     146    lowerbound[c] = std::numeric_limits<double>::min();
     147    lowerbound[d] = std::numeric_limits<double>::min();
     148    return lowerbound;
     149  }
     150
     151  /** Returns a vector which are the upper boundaries for each parameter_t
     152   * of this FunctionModel.
     153   *
     154   * \return vector of parameter_t resembling highest allowed values
     155   */
     156  parameters_t getUpperBoxConstraints() const {
     157    return parameters_t(getParameterDimension(), std::numeric_limits<double>::max());
     158  }
    122159
    123160private:
  • src/Potentials/Specifics/PairPotential_Harmonic.hpp

    rf48ad3 rd03292  
    1414#include <config.h>
    1515#endif
     16
     17#include <limits>
    1618
    1719#include "CodePatterns/Assert.hpp"
     
    98100  results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
    99101
     102  /** States whether lower and upper boundaries should be used to constraint
     103   * the parameter search for this function model.
     104   *
     105   * \return true - constraints should be used, false - else
     106   */
     107  bool isBoxConstraint() const {
     108    return true;
     109  }
     110
     111  /** Returns a vector which are the lower boundaries for each parameter_t
     112   * of this FunctionModel.
     113   *
     114   * \return vector of parameter_t resembling lowest allowed values
     115   */
     116  parameters_t getLowerBoxConstraints() const {
     117    parameters_t lowerbounds(getParameterDimension(), -std::numeric_limits<double>::max());
     118    lowerbounds[equilibrium_distance] = 0.;
     119    return lowerbounds;
     120  }
     121
     122  /** Returns a vector which are the upper boundaries for each parameter_t
     123   * of this FunctionModel.
     124   *
     125   * \return vector of parameter_t resembling highest allowed values
     126   */
     127  parameters_t getUpperBoxConstraints() const {
     128    return parameters_t(getParameterDimension(), std::numeric_limits<double>::max());
     129  }
     130
    100131  enum parameter_enum_t {
    101132    spring_constant=0,
  • src/Potentials/Specifics/PairPotential_Morse.hpp

    rf48ad3 rd03292  
    1414#include <config.h>
    1515#endif
     16
     17#include <limits>
    1618
    1719#include "CodePatterns/Assert.hpp"
     
    99101  results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
    100102
     103  /** States whether lower and upper boundaries should be used to constraint
     104   * the parameter search for this function model.
     105   *
     106   * \return true - constraints should be used, false - else
     107   */
     108  bool isBoxConstraint() const {
     109    return true;
     110  }
     111
     112  /** Returns a vector which are the lower boundaries for each parameter_t
     113   * of this FunctionModel.
     114   *
     115   * \return vector of parameter_t resembling lowest allowed values
     116   */
     117  parameters_t getLowerBoxConstraints() const {
     118    parameters_t lowerbound(getParameterDimension(), -std::numeric_limits<double>::max());
     119    lowerbound[equilibrium_distance] = 0.;
     120    return lowerbound;
     121  }
     122
     123  /** Returns a vector which are the upper boundaries for each parameter_t
     124   * of this FunctionModel.
     125   *
     126   * \return vector of parameter_t resembling highest allowed values
     127   */
     128  parameters_t getUpperBoxConstraints() const {
     129    return parameters_t(getParameterDimension(), std::numeric_limits<double>::max());
     130  }
     131
    101132  enum parameter_enum_t {
    102133    spring_constant=0,
Note: See TracChangeset for help on using the changeset viewer.