Changeset 3400bb for src/Potentials


Ignore:
Timestamp:
Nov 4, 2016, 9:37:48 AM (8 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

MEMFIX: PotentialTrainer::operator() had potential memory leak.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/PotentialTrainer.cpp

    rd24750 r3400bb  
    7676{
    7777  // 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;
    8884  }
    8985
    9086  /******************** TRAINING ********************/
    9187  // fit potential
    92   FunctionModel::parameters_t bestparams(model->getParameterDimension(), 0.);
     88  FunctionModel::parameters_t bestparams(model.getParameterDimension(), 0.);
    9389  {
    9490    // 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());
    9692    data(_homologies.getHomologousGraphs(_graph));
    9793
     
    145141      ELOG(2, "threshold parameter always overrules max_runs, both are specified.");
    146142    // 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()) {
    149145      double l2error = std::numeric_limits<double>::max();
    150146      // seed with current time
     
    157153      do {
    158154        // generate new random initial parameter values
    159         model->setParametersToRandomInitialValues(data);
     155        model.setParametersToRandomInitialValues(data);
    160156        LOG(1, "INFO: Initial parameters of run " << runs << " are "
    161             << model->getParameters() << ".");
     157            << model.getParameters() << ".");
    162158        approximator(FunctionApproximation::ParameterDerivative);
    163159        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);
    166162        if (new_l2error < l2error) {
    167163          // store currently best parameters
    168164          l2error = new_l2error;
    169           bestparams = model->getParameters();
     165          bestparams = model.getParameters();
    170166          LOG(1, "STATUS: New fit from run " << runs
    171167              << " has better error of " << l2error << ".");
     
    173169      } while (( ++runs < max_runs) || (l2error > threshold));
    174170      // reset parameters from best fit
    175       model->setParameters(bestparams);
     171      model.setParameters(bestparams);
    176172      LOG(1, "INFO: Best parameters with L2 error of "
    177           << l2error << " are " << model->getParameters() << ".");
     173          << l2error << " are " << model.getParameters() << ".");
    178174    } else {
    179175      return false;
     
    183179    HomologyContainer::range_t fragmentrange = _homologies.getHomologousGraphs(_graph);
    184180    TrainingData::L2ErrorConfigurationIndexMap_t WorseFragmentMap =
    185         data.getWorstFragmentMap(*model, fragmentrange);
     181        data.getWorstFragmentMap(model, fragmentrange);
    186182    LOG(0, "RESULT: WorstFragmentMap " << WorseFragmentMap << ".");
    187183
    188184  }
    189   delete model;
    190185
    191186  return true;
Note: See TracChangeset for help on using the changeset viewer.