- Timestamp:
- Dec 19, 2012, 3:25:32 PM (12 years ago)
- 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:
- 9e903b
- Parents:
- 63b9f7
- git-author:
- Frederik Heber <heber@…> (10/07/12 15:34:28)
- git-committer:
- Frederik Heber <heber@…> (12/19/12 15:25:32)
- Location:
- src/FunctionApproximation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FunctionApproximation/FunctionApproximation.cpp
r63b9f7 r371c8b 220 220 } 221 221 222 if (mode == ParameterDerivative) {223 double *err = new double[n];224 dlevmar_chkjac(225 &FunctionApproximation::LevMarCallback,226 &FunctionApproximation::LevMarDerivativeCallback,227 p, m, n, this, err);228 for(i=0; i<n; ++i)229 LOG(1, "INFO: gradient " << i << ", err " << err[i] << ".");230 delete[] err;231 }232 233 222 delete[] p; 234 223 delete[] x; 235 224 } 236 225 226 bool FunctionApproximation::checkParameterDerivatives() 227 { 228 double *p; 229 int m; 230 const FunctionModel::parameters_t backupparams = model.getParameters(); 231 prepareParameters(p,m); 232 int n = output_data.size(); 233 double *err = new double[n]; 234 dlevmar_chkjac( 235 &FunctionApproximation::LevMarCallback, 236 &FunctionApproximation::LevMarDerivativeCallback, 237 p, m, n, this, err); 238 int i; 239 for(i=0; i<n; ++i) 240 LOG(1, "INFO: gradient " << i << ", err " << err[i] << "."); 241 bool status = true; 242 for(i=0; i<n; ++i) 243 status &= err[i] > 0.5; 244 245 if (!status) { 246 int faulty; 247 ELOG(0, "At least one of the parameter derivatives are incorrect."); 248 for (faulty=1; faulty<=m; ++faulty) { 249 LOG(1, "INFO: Trying with only the first " << faulty << " parameters..."); 250 model.setParameters(backupparams); 251 dlevmar_chkjac( 252 &FunctionApproximation::LevMarCallback, 253 &FunctionApproximation::LevMarDerivativeCallback, 254 p, faulty, n, this, err); 255 bool status = true; 256 for(i=0; i<n; ++i) 257 status &= err[i] > 0.5; 258 for(i=0; i<n; ++i) 259 LOG(1, "INFO: gradient(" << faulty << ") " << i << ", err " << err[i] << "."); 260 if (!status) 261 break; 262 } 263 ELOG(0, "The faulty parameter derivative is with respect to the " << faulty << " parameter."); 264 } else 265 LOG(1, "INFO: parameter derivatives are ok."); 266 267 delete[] err; 268 delete[] p; 269 model.setParameters(backupparams); 270 271 return status; 272 } 273 237 274 double SquaredDifference(const double res1, const double res2) 238 275 { … … 242 279 void FunctionApproximation::prepareModel(double *p, int m) 243 280 { 244 ASSERT( (size_t)m == model.getParameterDimension(),245 "FunctionApproximation::prepareModel() - LevMar expects "+toString(m)246 +" parameters but the model function expects "+toString(model.getParameterDimension())+".");281 // ASSERT( (size_t)m == model.getParameterDimension(), 282 // "FunctionApproximation::prepareModel() - LevMar expects "+toString(m) 283 // +" parameters but the model function expects "+toString(model.getParameterDimension())+"."); 247 284 FunctionModel::parameters_t params(m, 0.); 248 285 std::copy(p, p+m, params.begin()); -
src/FunctionApproximation/FunctionApproximation.hpp
r63b9f7 r371c8b 128 128 void evaluateDerivative(double *p, double *jac, int m, int n, void *data); 129 129 130 /** This functions checks whether the parameter derivative of the FunctionModel 131 * has been correctly implemented by validating against finite differences. 132 * 133 * We use LevMar's dlevmar_chkjac() function. 134 * 135 * \return true - gradients are ok (>0.5), false - else 136 */ 137 bool checkParameterDerivatives(); 138 130 139 private: 131 140 static void LevMarCallback(double *p, double *x, int m, int n, void *data);
Note:
See TracChangeset
for help on using the changeset viewer.