Ignore:
Timestamp:
Jun 27, 2014, 9:32:55 PM (11 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:
550f2a
Parents:
16227a
git-author:
Frederik Heber <heber@…> (02/27/14 20:15:41)
git-committer:
Frederik Heber <heber@…> (06/27/14 21:32:55)
Message:

FunctionModel now uses list_of_arguments to split sequence of subsets of distances.

  • this fixes ambiguities with the set of distances: Imagine the distances within a water molecule as OH (A) and HH (B). We then may have a sequence of argument_t as AABAAB. And with the current implementation of CompoundPotential::splitUpArgumentsByModels() we would always choose the latter (and more complex) model. Hence, we make two calls to TriplePotential_Angle, instead of calls twice to PairPotential_Harmonic for A, one to PairPotential_Harmonic for B, and once to TriplePotential_Angle for AAB.
  • now, we new list looks like A,A,B,AAB where each tuple of distances can be uniquely associated with a specific potential.
  • changed signatures of EmpiricalPotential::operator(), ::derivative(), ::parameter_derivative(). This involved changing all of the current specific potentials and CompoundPotential.
  • TrainingData must discern between the InputVector_t (just all distances) and the FilteredInputVector_t (tuples of subsets of distances).
  • FunctionApproximation now has list_of_arguments_t as parameter to evaluate() and evaluate_derivative().
  • DOCU: docu change in TrainingData.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/CompoundPotential.cpp

    r16227a re1fe7e  
    228228{
    229229  arguments_by_model_t partial_args;
    230   // go through each model and have it filter out its arguments
     230  // go through each model and have it filter out its arguments, this already
     231  // returns a list of tuples associated with the specific model
    231232  for(models_t::const_iterator modeliter = models.begin();
    232233      modeliter != models.end(); ++modeliter) {
    233234    FunctionModel::filter_t filterfunction = (*modeliter)->getSpecificFilter();
    234     arguments_t tempargs = filterfunction(arguments);
     235    list_of_arguments_t tempargs = filterfunction(arguments);
    235236    // then split up all the bunches, too.
    236     arguments_t::const_iterator advanceiter = tempargs.begin();
    237     for (arguments_t::const_iterator argiter = tempargs.begin();
    238         argiter != tempargs.end(); argiter = advanceiter) {
    239       advanceiter += (*modeliter)->getSpecificArgumentCount();
     237    for (list_of_arguments_t::const_iterator argiter = tempargs.begin();
     238        argiter != tempargs.end(); ++argiter) {
     239      const arguments_t &args = *argiter;
    240240      partial_args.push_back(
    241241          std::make_pair(
    242242              *modeliter,
    243               arguments_t(argiter, advanceiter)
     243              args
    244244            )
    245245          );
     
    251251
    252252CompoundPotential::arguments_by_model_t CompoundPotential::splitUpArgumentsByModels(
    253     const arguments_t &arguments) const
     253    const list_of_arguments_t &listarguments) const
    254254{
    255255  arguments_by_model_t partial_args;
    256   arguments_t::const_iterator argiter = arguments.begin();
    257256  particletypes_per_model_t::const_iterator typesiter = particletypes_per_model.begin();
    258257  models_t::const_iterator modeliter = models.begin();
    259258
    260   // add constant model (which is always first model) with empty args if present
     259  /// add constant model (which is always first model) with empty args if present
    261260  if (typesiter->empty()) {
    262261    partial_args.push_back(
     
    266265    ++typesiter;
    267266  }
     267
    268268  // then check other models
    269   while (argiter != arguments.end()) {
     269  /// we only have to check whether the current model still matches or whether
     270  /// have to use the next model.
     271  for (list_of_arguments_t::const_iterator argiter = listarguments.begin();
     272      argiter != listarguments.end(); ++argiter) {
     273    const arguments_t &arguments = *argiter;
    270274    if (typesiter+1 != particletypes_per_model.end()) {
    271275      // check whether next argument bunch is for same model or different one
     
    275279
    276280      // we always expect N(N-1)/2 distances for N particle types
    277       arguments_t::const_iterator enditer = argiter+(types.size()*(types.size()-1)/2);
    278       arguments_t::const_iterator nextenditer = argiter+(nexttypes.size()*(nexttypes.size()-1)/2);
    279       arguments_t args(argiter, enditer);
    280       arguments_t nextargs(argiter, nextenditer);
    281       if (types.size() < nexttypes.size()) {
    282         if (areValidArguments(nexttypes, nextargs)) {
     281      // check first from sizes alone
     282      const size_t tuplesize = types.size()*(types.size()-1)/2;
     283      const size_t nexttuplesize = nexttypes.size()*(nexttypes.size()-1)/2;
     284      if ((tuplesize != nexttuplesize)) {
     285        if ((arguments.size() == tuplesize) &&  areValidArguments(types, arguments)) {
     286          // only former still matches, don't increment
     287          partial_args.push_back(
     288              std::make_pair(*modeliter, arguments)
     289              );
     290        } else if ((arguments.size() == nexttuplesize) &&  areValidArguments(nexttypes, arguments)) {
    283291          // latter matches, increment
    284292          ++typesiter;
    285293          partial_args.push_back(
    286               std::make_pair(*(++modeliter), arguments_t(argiter, nextenditer))
     294              std::make_pair(*(++modeliter), arguments)
    287295              );
    288           argiter = nextenditer;
    289         } else if (areValidArguments(types, args)) {
    290           // only former matches, don't increment
    291           partial_args.push_back(
    292               std::make_pair(*modeliter, arguments_t(argiter, enditer))
    293               );
    294           argiter = enditer;
    295         } else
     296        } else {
    296297          ASSERT(0,
    297               "CompoundPotential::splitUpArgumentsByModels() - neither type matches its argument bunch.");
    298       } else {
    299         if (areValidArguments(types, args)) {
    300           // only former matches, don't increment
    301           partial_args.push_back(
    302               std::make_pair(*modeliter, arguments_t(argiter, enditer))
    303               );
    304           argiter = enditer;
    305         } else if (areValidArguments(nexttypes, nextargs)) {
    306           // latter matches, increment
    307           ++typesiter;
    308           partial_args.push_back(
    309               std::make_pair(*(++modeliter), arguments_t(argiter, nextenditer))
    310               );
    311           argiter = nextenditer;
     298              "CompoundPotential::splitUpArgumentsByModels() - neither this model nor next model match (size) with current tuple.");
     299        }
     300      } else { // same size, now we have to check the types individually
     301        size_t encodeValidity = 0;
     302        encodeValidity += 1*areValidArguments(types, arguments);
     303        encodeValidity += 2*areValidArguments(nexttypes, arguments);
     304
     305        switch (encodeValidity) {
     306          case 1:
     307            // only former still matches, don't increment
     308            partial_args.push_back(
     309                std::make_pair(*modeliter, arguments)
     310                );
     311            break;
     312          case 2:
     313            ++typesiter;
     314            partial_args.push_back(
     315                std::make_pair(*(++modeliter), arguments)
     316                );
     317            break;
     318          case 0:
     319          case 3:
     320          default:
     321            ASSERT(0,
     322                "CompoundPotential::splitUpArgumentsByModels() - neither this model nor next model match (type) with current tuple.");
     323            break;
    312324        }
    313325      }
    314326    } else {
    315327      const SerializablePotential::ParticleTypes_t &types = *typesiter;
    316       // we always expect N(N-1)/2 distances for N particle types
    317       arguments_t::const_iterator enditer = argiter+(types.size()*(types.size()-1)/2);
    318       partial_args.push_back(
    319           std::make_pair(*modeliter, arguments_t(argiter, enditer))
    320           );
    321       argiter = enditer;
     328      if (areValidArguments(types, arguments)) {
     329        // only former matches, don't increment
     330        partial_args.push_back(
     331            std::make_pair(*modeliter, arguments)
     332            );
     333      } else {
     334        ASSERT(0,
     335            "CompoundPotential::splitUpArgumentsByModels() - last model does not match with current tuple.");
     336      }
    322337    }
    323338  }
     
    326341}
    327342
    328 CompoundPotential::results_t CompoundPotential::operator()(const arguments_t &arguments) const
     343CompoundPotential::results_t CompoundPotential::operator()(
     344    const list_of_arguments_t &listarguments) const
    329345{
    330346  /// first, we have to split up the given arguments
    331347  arguments_by_model_t partial_args =
    332       splitUpArgumentsByModels(arguments);
     348      splitUpArgumentsByModels(listarguments);
    333349  // print split up argument list for debugging
    334350  if (DoLog(4)) {
     
    348364      iter != partial_args.end(); ++iter) {
    349365    partial_results.push_back(
    350         (*iter->first)(iter->second)
     366        (*iter->first)(
     367            FunctionModel::list_of_arguments_t(1, iter->second))
    351368    );
    352369  }
     
    366383}
    367384
    368 CompoundPotential::results_t CompoundPotential::parameter_derivative(const arguments_t &arguments, const size_t index) const
     385CompoundPotential::results_t CompoundPotential::parameter_derivative(
     386    const list_of_arguments_t &listarguments,
     387    const size_t index) const
    369388{
    370389  // first, we have to split up the given arguments
    371390  arguments_by_model_t partial_args =
    372       splitUpArgumentsByModels(arguments);
     391      splitUpArgumentsByModels(listarguments);
    373392  // then, with each bunch of arguments, we call the specific model
    374393  // get parameter dimensions per model
     
    399418      const size_t indexbase = (iter == dimensions.begin()) ? 0 : *(iter-1);
    400419      CompoundPotential::results_t results =
    401           model->parameter_derivative(argiter->second, index-indexbase);
     420          model->parameter_derivative(
     421              FunctionModel::list_of_arguments_t(1, argiter->second), index-indexbase);
    402422
    403423      // either set results or add
     
    462482  // create initial returnfunction
    463483  FunctionModel::filter_t returnfunction =
    464       boost::bind(&Helpers::returnEmptyArguments);
     484      boost::bind(&Helpers::returnEmptyListArguments);
    465485
    466486  // every following fragments combines its arguments with the initial function
     
    468488      modeliter != models.end(); ++modeliter) {
    469489    returnfunction =
    470           boost::bind(&Extractors::concatenateArguments,
     490          boost::bind(&Extractors::concatenateListOfArguments,
    471491              boost::bind(returnfunction, _1),
    472492              boost::bind((*modeliter)->getSpecificFilter(), _1)
Note: See TracChangeset for help on using the changeset viewer.