Ignore:
Timestamp:
Feb 24, 2013, 12:58:53 PM (12 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:
04cc7e
Parents:
ac868ee
git-author:
Frederik Heber <heber@…> (10/22/12 13:31:54)
git-committer:
Frederik Heber <heber@…> (02/24/13 12:58:53)
Message:

Angle training now also uses TrainingData.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/LevMartester.cpp

    rac868ee r52e7da  
    182182}
    183183
    184 double
    185 function_angle(
    186     const double &r_ij,
    187     const double &r_ik,
    188     const double &r_jk
    189   )
    190 {
    191 //  Info info(__func__);
    192   const double angle = pow(r_ij,2.) + pow(r_ik,2.) - pow(r_jk,2.);
    193   const double divisor = 2.* r_ij * r_ik;
    194 
    195 //  LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
    196   if (divisor == 0.)
    197     return 0.;
    198   else
    199     return angle/divisor;
    200 }
    201 
    202184int main(int argc, char **argv)
    203185{
     
    256238
    257239    // Afterwards we go through all of this type and gather the distance and the energy value
    258     typedef std::pair<
    259         FunctionApproximation::inputs_t,
    260         FunctionApproximation::outputs_t> InputOutputVector_t;
    261     InputOutputVector_t DistanceEnergyVector;
    262     std::pair<HomologyContainer::const_iterator, HomologyContainer::const_iterator> range =
    263         homologies.getHomologousGraphs(graph);
    264     for (HomologyContainer::const_iterator fragiter = range.first; fragiter != range.second; ++fragiter) {
    265       // get distance out of Fragment
    266       const double &energy = fragiter->second.second;
    267       const Fragment &fragment = fragiter->second.first;
    268       const Fragment::charges_t charges = fragment.getCharges();
    269       const Fragment::positions_t positions = fragment.getPositions();
    270       std::vector< std::pair<Vector, size_t> > DistanceVectors;
    271       for (Fragment::charges_t::const_iterator chargeiter = charges.begin();
    272           chargeiter != charges.end(); ++chargeiter) {
    273         if (*chargeiter == 6) {
    274           Fragment::positions_t::const_iterator positer = positions.begin();
    275           const size_t steps = std::distance(charges.begin(), chargeiter);
    276           std::advance(positer, steps);
    277           DistanceVectors.push_back(
    278               std::make_pair(Vector((*positer)[0], (*positer)[1], (*positer)[2]),
    279                   steps));
    280         }
    281       }
    282       if (DistanceVectors.size() == (size_t)3) {
    283         FunctionModel::arguments_t args(3);
    284         // we require specific ordering of the carbons: ij, ik, jk
    285         typedef std::vector< std::pair<size_t, size_t> > indices_t;
    286         indices_t indices;
    287         indices += std::make_pair(0,1), std::make_pair(0,2), std::make_pair(1,2);
    288         // create the three arguments
    289         for (indices_t::const_iterator iter = indices.begin(); iter != indices.end(); ++iter) {
    290           const size_t &firstindex = iter->first;
    291           const size_t &secondindex = iter->second;
    292           argument_t &arg = args[(size_t)std::distance(const_cast<const indices_t&>(indices).begin(), iter)];
    293           arg.indices.first = DistanceVectors[firstindex].second;
    294           arg.indices.second = DistanceVectors[secondindex].second;
    295           arg.distance = DistanceVectors[firstindex].first.distance(DistanceVectors[secondindex].first);
    296           arg.globalid = DistanceEnergyVector.first.size();
    297         }
    298         // make largest distance last to create correct angle
    299         // (this would normally depend on the order of the nodes in the subgraph)
    300         std::list<argument_t> sorted_args;
    301         double greatestdistance = 0.;
    302         for(FunctionModel::arguments_t::const_iterator iter = args.begin(); iter != args.end(); ++iter)
    303           greatestdistance = std::max(greatestdistance, iter->distance);
    304         for(FunctionModel::arguments_t::const_iterator iter = args.begin(); iter != args.end(); ++iter)
    305           if (iter->distance == greatestdistance)
    306             sorted_args.push_back(*iter);
    307           else
    308             sorted_args.push_front(*iter);
    309         // and add the training pair
    310         DistanceEnergyVector.first.push_back( FunctionModel::arguments_t(sorted_args.begin(), sorted_args.end()) );
    311         DistanceEnergyVector.second.push_back( FunctionModel::results_t(1,energy) );
    312       } else {
    313         ELOG(2, "main() - found not exactly three carbon atoms in fragment "
    314             << fragment << ".");
    315       }
    316     }
    317     // print training data for debugging
    318     {
    319       LOG(1, "INFO: I gathered the following (" << DistanceEnergyVector.first.size()
    320           << "," << DistanceEnergyVector.second.size() << ") data pairs: ");
    321       FunctionApproximation::inputs_t::const_iterator initer = DistanceEnergyVector.first.begin();
    322       FunctionApproximation::outputs_t::const_iterator outiter = DistanceEnergyVector.second.begin();
    323       for (; initer != DistanceEnergyVector.first.end(); ++initer, ++outiter) {
    324         std::stringstream stream;
    325         const double cos_angle = function_angle((*initer)[0].distance,(*initer)[1].distance,(*initer)[2].distance);
    326         for (size_t index = 0; index < (*initer).size(); ++index)
    327            stream << " (" << (*initer)[index].indices.first << "," << (*initer)[index].indices.second
    328               << ") " << (*initer)[index].distance;
    329         stream << " with energy " << *outiter << " and cos(angle) " << cos_angle;
    330         LOG(1, "INFO:" << stream.str());
    331       }
    332     }
     240    TrainingData AngleData(
     241        boost::bind(&Extractors::reorderArgumentsByIncreasingDistance,
     242            boost::bind(&Extractors::gatherAllSymmetricDistanceArguments,
     243                boost::bind(&Extractors::gatherPositionOfTuples,
     244                    _1, Fragment::charges_t(3,6.)
     245                ), _2 // gather carbon triples
     246            )
     247          )
     248        );
     249    AngleData(homologies.getHomologousGraphs(graph));
     250    LOG(1, "INFO: I gathered the following training data: " << AngleData);
    333251    // NOTICE that distance are in bohrradi as they come from MPQC!
    334252
     
    342260    angle.setParameters(params);
    343261    FunctionModel &model = angle;
    344     FunctionApproximation approximator(
    345         DistanceEnergyVector.first.begin()->size(),
    346         DistanceEnergyVector.second.begin()->size(),
    347         model);
    348     approximator.setTrainingData(DistanceEnergyVector.first,DistanceEnergyVector.second);
     262    FunctionApproximation approximator(AngleData, model);
    349263    if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
    350264      approximator(FunctionApproximation::ParameterDerivative);
     
    365279    TrainingData MorseData(
    366280        boost::bind(&Extractors::gatherAllSymmetricDistanceArguments,
    367             boost::bind(&Extractors::gatherDistanceOfTuples,
     281            boost::bind(&Extractors::gatherPositionOfTuples,
    368282                _1, Fragment::charges_t(2,6.)
    369283            ), _2 // gather first carbon pair
Note: See TracChangeset for help on using the changeset viewer.