Changeset 3400bb for src/Potentials
- Timestamp:
- Nov 4, 2016, 9:37:48 AM (8 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, 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_ChronosMutex, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids_IntegrationTest, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
- Children:
- 2d1280
- Parents:
- d24750
- git-author:
- Frederik Heber <heber@…> (11/03/16 11:17:49)
- git-committer:
- Frederik Heber <heber@…> (11/04/16 09:37:48)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Potentials/PotentialTrainer.cpp
rd24750 r3400bb 76 76 { 77 77 // fit potential 78 FunctionModel *model = new CompoundPotential(_graph); 79 ASSERT( model != NULL, 80 "PotentialTrainer::operator() - model is NULL."); 81 82 { 83 CompoundPotential *compound = static_cast<CompoundPotential *>(model); 84 if (compound->begin() == compound->end()) { 85 ELOG(1, "Could not find any suitable potentials for the compound potential."); 86 return false; 87 } 78 CompoundPotential compound(_graph); 79 FunctionModel &model = assert_cast<FunctionModel &>(compound); 80 81 if (compound.begin() == compound.end()) { 82 ELOG(1, "Could not find any suitable potentials for the compound potential."); 83 return false; 88 84 } 89 85 90 86 /******************** TRAINING ********************/ 91 87 // fit potential 92 FunctionModel::parameters_t bestparams(model ->getParameterDimension(), 0.);88 FunctionModel::parameters_t bestparams(model.getParameterDimension(), 0.); 93 89 { 94 90 // Afterwards we go through all of this type and gather the distance and the energy value 95 TrainingData data(model ->getSpecificFilter());91 TrainingData data(model.getSpecificFilter()); 96 92 data(_homologies.getHomologousGraphs(_graph)); 97 93 … … 145 141 ELOG(2, "threshold parameter always overrules max_runs, both are specified."); 146 142 // now perform the function approximation by optimizing the model function 147 FunctionApproximation approximator(data, *model, _threshold, _maxiterations);148 if (model ->isBoxConstraint() && approximator.checkParameterDerivatives()) {143 FunctionApproximation approximator(data, model, _threshold, _maxiterations); 144 if (model.isBoxConstraint() && approximator.checkParameterDerivatives()) { 149 145 double l2error = std::numeric_limits<double>::max(); 150 146 // seed with current time … … 157 153 do { 158 154 // generate new random initial parameter values 159 model ->setParametersToRandomInitialValues(data);155 model.setParametersToRandomInitialValues(data); 160 156 LOG(1, "INFO: Initial parameters of run " << runs << " are " 161 << model ->getParameters() << ".");157 << model.getParameters() << "."); 162 158 approximator(FunctionApproximation::ParameterDerivative); 163 159 LOG(1, "INFO: Final parameters of run " << runs << " are " 164 << model ->getParameters() << ".");165 const double new_l2error = data.getL2Error( *model);160 << model.getParameters() << "."); 161 const double new_l2error = data.getL2Error(model); 166 162 if (new_l2error < l2error) { 167 163 // store currently best parameters 168 164 l2error = new_l2error; 169 bestparams = model ->getParameters();165 bestparams = model.getParameters(); 170 166 LOG(1, "STATUS: New fit from run " << runs 171 167 << " has better error of " << l2error << "."); … … 173 169 } while (( ++runs < max_runs) || (l2error > threshold)); 174 170 // reset parameters from best fit 175 model ->setParameters(bestparams);171 model.setParameters(bestparams); 176 172 LOG(1, "INFO: Best parameters with L2 error of " 177 << l2error << " are " << model ->getParameters() << ".");173 << l2error << " are " << model.getParameters() << "."); 178 174 } else { 179 175 return false; … … 183 179 HomologyContainer::range_t fragmentrange = _homologies.getHomologousGraphs(_graph); 184 180 TrainingData::L2ErrorConfigurationIndexMap_t WorseFragmentMap = 185 data.getWorstFragmentMap( *model, fragmentrange);181 data.getWorstFragmentMap(model, fragmentrange); 186 182 LOG(0, "RESULT: WorstFragmentMap " << WorseFragmentMap << "."); 187 183 188 184 } 189 delete model;190 185 191 186 return true;
Note:
See TracChangeset
for help on using the changeset viewer.