Changeset 82e5fb


Ignore:
Timestamp:
May 25, 2021, 11:04:50 PM (4 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
91793c
Parents:
889067e
git-author:
Frederik Heber <frederik.heber@…> (05/25/21 21:55:59)
git-committer:
Frederik Heber <frederik.heber@…> (05/25/21 23:04:50)
Message:

Added option error-file to fit potential actions.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • doc/userguide/userguide.xml

    r889067e r82e5fb  
    24302430      --set-threshold 1e-3 \
    24312431      --training-file test.dat
     2432      --error-file error.dat
    24322433   </programlisting>
    24332434          <para>Now, all empirical potential functions are summed up into a
     
    24372438          potential between oxygen and hydrogen and another angular potential
    24382439          for the angle between hydrogen, oxygen, and hydrogen atom. Then, we would
    2439           fit a function consisting of the sum of the two potentials functions in order to approximate the energy of a single
    2440           water molecule (actually, it&apos;s the sum of three potentials. As mentioned before, a constant potential is always added to compensate non-bonding energies, i.e. not depending on interatomic distances). Here, the threshold criterion takes the place of the
    2441 <emphasis role="bold"> take-best-of</emphasis> option. Here, the minimization is reiterated so often on random (but to some extent chosen from a sensible range) starting parameters until the final L2 error is below 1e-3. Also, all data used
    2442           for training, i.e. the tuples consisting of the fragments nuclei
    2443           coordinates and the associated energy value are written to the file
    2444           <filename>test.dat</filename>. This allows for graphical representation or other
    2445 way of analysis, e.g. for a Morse potential between oxygen and hydrogen the bonding energy can be plotted as a one-dimensional function and compared to the &quot;point cloud&quot; of sample points from the fragment term of Born-Oppenheimer surface. It is this point cloud, i.e. the training data, that is written to the file
    2446           <filename>test.dat</filename>.</para>
     2440          fit a function consisting of the sum of the two potentials functions in
     2441          order to approximate the energy of a single water molecule (actually,
     2442          it&apos;s the sum of three potentials. As mentioned before, a constant
     2443          potential is always added to compensate non-bonding energies, i.e. not
     2444          depending on interatomic distances). Here, the threshold criterion takes
     2445          the place of the<emphasis role="bold"> take-best-of</emphasis> option.
     2446          Here, the minimization is reiterated so often on random (but to some
     2447          extent chosen from a sensible range) starting parameters until the final
     2448          L2 error is below 1e-3. Also, all data used for training, i.e. the tuples
     2449          consisting of the fragments nuclei coordinates and the associated energy
     2450          value are written to the file <filename>test.dat</filename>. This allows
     2451          for graphical representation or other way of analysis, e.g. for a Morse
     2452          potential between oxygen and hydrogen the bonding energy can be plotted
     2453          as a one-dimensional function and compared to the &quot;point cloud&quot;
     2454          of sample points from the fragment term of Born-Oppenheimer surface.
     2455          It is this point cloud, i.e. the training data, that is written to the file
     2456          <filename>test.dat</filename>. Moreover, the error per fragment is written
     2457          to the file <filename>error.dat</filename></para>
    24472458          <para>Note that you can combine the two ways, i.e. start with a
    24482459          fit-potential call but give an empty potential file. The resulting
  • src/Actions/PotentialAction/FitCompoundPotentialAction.cpp

    r889067e r82e5fb  
    104104      graph,
    105105      params.training_file.get(),
     106      params.error_file.get(),
    106107      params.max_iterations.get(),
    107108      params.threshold.get(),
  • src/Actions/PotentialAction/FitCompoundPotentialAction.def

    r889067e r82e5fb  
    2323// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    2424// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    25 #define paramtypes (boost::filesystem::path)(std::vector<const element *>)(unsigned int)(double)(unsigned int)
    26 #define paramtokens ("training-file")("fragment-charges")("take-best-of")("set-threshold")("set-max-iterations")
    27 #define paramdescriptions ("optional file to write training data to")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")("sets the maximum number of iterations spent on the optimization of parameters")
    28 #define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(100))
    29 #define paramreferences (training_file)(fragment)(best_of_howmany)(threshold)(max_iterations)
     25#define paramtypes (boost::filesystem::path)(boost::filesystem::path)(std::vector<const element *>)(unsigned int)(double)(unsigned int)
     26#define paramtokens ("training-file")("error-file")("fragment-charges")("take-best-of")("set-threshold")("set-max-iterations")
     27#define paramdescriptions ("optional file to write training data to")("optional file to write error data to")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")("sets the maximum number of iterations spent on the optimization of parameters")
     28#define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(100))
     29#define paramreferences (training_file)(error_file)(fragment)(best_of_howmany)(threshold)(max_iterations)
    3030#define paramvalids \
     31(DummyValidator<boost::filesystem::path>()) \
    3132(DummyValidator<boost::filesystem::path>()) \
    3233(STLVectorValidator< std::vector<const element *> >(1,99, ElementValidator())) \
  • src/Actions/PotentialAction/FitPotentialAction.cpp

    r889067e r82e5fb  
    141141      graph,
    142142      params.training_file.get(),
     143      params.error_file.get(),
    143144      params.max_iterations.get(),
    144145      params.threshold.get(),
  • src/Actions/PotentialAction/FitPotentialAction.def

    r889067e r82e5fb  
    2323// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    2424// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    25 #define paramtypes (boost::filesystem::path)(std::string)(std::vector<const element *>)(std::vector<const element *>)(unsigned int)(double)(unsigned int)
    26 #define paramtokens ("training-file")("potential-type")("potential-charges")("fragment-charges")("take-best-of")("set-threshold")("set-max-iterations")
    27 #define paramdescriptions ("optional file to write training data to")("potential type to fit")("charges specifying the potential")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")("sets the maximum number of iterations spent on the optimization of parameters")
    28 #define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(100))
    29 #define paramreferences (training_file)(potentialtype)(charges)(fragment)(best_of_howmany)(threshold)(max_iterations)
     25#define paramtypes (boost::filesystem::path)(boost::filesystem::path)(std::string)(std::vector<const element *>)(std::vector<const element *>)(unsigned int)(double)(unsigned int)
     26#define paramtokens ("training-file")("error-file")("potential-type")("potential-charges")("fragment-charges")("take-best-of")("set-threshold")("set-max-iterations")
     27#define paramdescriptions ("optional file to write training data to")("optional file to write error data to")("potential type to fit")("charges specifying the potential")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")("sets the maximum number of iterations spent on the optimization of parameters")
     28#define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(100))
     29#define paramreferences (training_file)(error_file)(potentialtype)(charges)(fragment)(best_of_howmany)(threshold)(max_iterations)
    3030#define paramvalids \
     31(DummyValidator<boost::filesystem::path>()) \
    3132(DummyValidator<boost::filesystem::path>()) \
    3233(PotentialTypeValidator()) \
  • src/Potentials/PotentialTrainer.cpp

    r889067e r82e5fb  
    7171    const HomologyGraph &_graph,
    7272    const boost::filesystem::path &_trainingfile,
     73    const boost::filesystem::path &_errorfile,
    7374    const unsigned int _maxiterations,
    7475    const double _threshold,
     
    180181    TrainingData::L2ErrorConfigurationIndexMap_t WorseFragmentMap =
    181182        data.getWorstFragmentMap(model, fragmentrange);
    182     LOG(0, "RESULT: WorstFragmentMap " << WorseFragmentMap << ".");
    183 
     183    if (_errorfile.string().empty()) {
     184      LOG(0, "RESULT: WorstFragmentMap " << WorseFragmentMap << ".");
     185    } else {
     186      std::ofstream errorstream(_errorfile.string().c_str());
     187      if (errorstream.good()) {
     188        LOG(3, "DEBUG: Writing error data to file " <<
     189            _errorfile.string() << ".");
     190        errorstream << "step\terror" << std::endl;
     191        // resort into step as key
     192        typedef std::map< size_t, double > step_error_t;
     193        step_error_t step_error;
     194        for (TrainingData::L2ErrorConfigurationIndexMap_t::const_reverse_iterator iter = WorseFragmentMap.rbegin();
     195            iter != WorseFragmentMap.rend(); ++iter)
     196          step_error.insert( std::make_pair(iter->second, iter->first) );
     197        for (step_error_t::const_iterator iter = step_error.begin();
     198            iter != step_error.end(); ++iter)
     199          errorstream << iter->first << "\t" << iter->second << std::endl;
     200      }
     201      errorstream.close();
     202    }
    184203  }
    185204
  • src/Potentials/PotentialTrainer.hpp

    r889067e r82e5fb  
    3636        const HomologyGraph &_graph,
    3737        const boost::filesystem::path &_trainingfile,
     38        const boost::filesystem::path &_errorfile,
    3839        const unsigned int _maxiterations,
    3940        const double _threshold,
  • tests/Python/AllActions/options.dat

    r889067e r82e5fb  
    7878end_step        "1"
    7979enforce_net_zero_charge "0"
     80error_file      ""
    8081ExcludeHydrogen "1"
    8182fastparsing     "1"
  • tests/regression/Potential/FitCompoundPotential/testsuite-potential-fit-compound-potential.at

    r889067e r82e5fb  
    3535        --parse-potentials ${abs_top_srcdir}/tests/regression/Potential/FitCompoundPotential/pre/water.potentials \
    3636        --fit-compound-potential \
     37                --error-file error.csv \
    3738                --fragment-charges 1 8 1 \
    3839                --take-best-of 3 \
    3940        --save-potentials water.potentials], 0, [stdout], [ignore])
     41# check that error file was written
     42AT_CHECK([test -e error.csv], 0, [ignore], [ignore])
    4043# check that L_2 error
    4144AT_CHECK([grep "Best parameters with L2 error" stdout | awk '{if ($8 > 0.34) exit 1}'], 0, [ignore], [ignore])
Note: See TracChangeset for help on using the changeset viewer.