Changeset e1fe7e for src/FunctionApproximation
- Timestamp:
- Jun 27, 2014, 9:32:55 PM (11 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:
- 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)
- Location:
- src/FunctionApproximation
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FunctionApproximation/Extractors.cpp
r16227a re1fe7e 532 532 } 533 533 534 FunctionModel::arguments_t Extractors::reorderArgumentsByIncreasingDistance( 535 const FunctionModel::arguments_t &args 536 ) 537 { 538 FunctionModel::arguments_t returnargs(args); 539 std::sort(returnargs.begin(), returnargs.end(), argument_t::DistanceComparator); 534 FunctionModel::list_of_arguments_t Extractors::reorderArgumentsByIncreasingDistance( 535 const FunctionModel::list_of_arguments_t &listargs 536 ) 537 { 538 FunctionModel::list_of_arguments_t returnargs; 539 for (FunctionModel::list_of_arguments_t::const_iterator iter = listargs.begin(); 540 iter != listargs.end(); ++iter) { 541 const FunctionModel::arguments_t &args = *iter; 542 FunctionModel::arguments_t sortedargs(args); 543 std::sort(sortedargs.begin(), sortedargs.end(), argument_t::DistanceComparator); 544 returnargs.push_back(sortedargs); 545 } 540 546 return returnargs; 541 547 } … … 587 593 } 588 594 589 FunctionModel::arguments_t Extractors::reorderArgumentsByParticleTypes( 595 FunctionModel::list_of_arguments_t Extractors::reorderArgumentsByParticleTypes( 596 const FunctionModel::list_of_arguments_t &listargs, 597 const ParticleTypes_t &_types 598 ) 599 { 600 FunctionModel::list_of_arguments_t returnargs; 601 for (FunctionModel::list_of_arguments_t::const_iterator iter = listargs.begin(); 602 iter != listargs.end(); ++iter) { 603 const FunctionModel::arguments_t &args = *iter; 604 /// We place all arguments into multimap according to particle type pair. 605 // here, we need a special comparator such that types in key pair are always 606 // properly ordered. 607 typedef std::multimap< 608 argument_t::types_t, 609 argument_t, 610 ParticleTypesComparator> TypePair_Argument_Map_t; 611 TypePair_Argument_Map_t argument_map; 612 for(FunctionModel::arguments_t::const_iterator iter = args.begin(); 613 iter != args.end(); ++iter) { 614 argument_map.insert( std::make_pair(iter->types, *iter) ); 615 } 616 LOG(4, "DEBUG: particle_type map is " << argument_map << "."); 617 618 /// Then, we create the desired unique keys 619 typedef std::vector<argument_t::types_t> UniqueTypes_t; 620 UniqueTypes_t UniqueTypes; 621 for (ParticleTypes_t::const_iterator firstiter = _types.begin(); 622 firstiter != _types.end(); 623 ++firstiter) { 624 for (ParticleTypes_t::const_iterator seconditer = firstiter; 625 seconditer != _types.end(); 626 ++seconditer) { 627 if (seconditer == firstiter) 628 continue; 629 UniqueTypes.push_back( std::make_pair(*firstiter, *seconditer) ); 630 } 631 } 632 LOG(4, "DEBUG: Created unique types as keys " << UniqueTypes << "."); 633 634 /// Finally, we use the unique key list to pick corresponding arguments from the map 635 FunctionModel::arguments_t sortedargs; 636 sortedargs.reserve(args.size()); 637 while (!argument_map.empty()) { 638 // note that particle_types_t may be flipped, i.e. 1,8 is equal to 8,1, but we 639 // must maintain the correct order in indices in accordance with the order 640 // in _types, i.e. 1,8,1 must match with e.g. ids 1,0,2 where 1 has type 1, 641 // 0 has type 8, and 2 has type 2. 642 // In other words: We do not want to flip/modify arguments such that they match 643 // with the specific type pair we seek but then this comes at the price that we 644 // have flip indices when the types in a pair are flipped. 645 646 typedef std::vector<size_t> indices_t; 647 //!> here, we gather the indices as we discover them 648 indices_t indices; 649 indices.resize(_types.size(), (size_t)-1); 650 651 // these are two iterators that create index pairs in the same way as we have 652 // created type pairs. If a -1 is still present in indices, then the index is 653 // still arbitrary but is then set by the next found index 654 indices_t::iterator firstindex = indices.begin(); 655 indices_t::iterator secondindex = firstindex+1; 656 657 //!> here, we gather the current bunch of arguments as we find them 658 FunctionModel::arguments_t argumentbunch; 659 argumentbunch.reserve(UniqueTypes.size()); 660 661 for (UniqueTypes_t::const_iterator typeiter = UniqueTypes.begin(); 662 typeiter != UniqueTypes.end(); ++typeiter) { 663 // have all arguments to same type pair as list within the found range 664 std::pair< 665 TypePair_Argument_Map_t::iterator, 666 TypePair_Argument_Map_t::iterator> range_t = 667 argument_map.equal_range(*typeiter); 668 LOG(4, "DEBUG: Set of arguments to current key [" << typeiter->first << "," 669 << typeiter->second << "] is " << std::list<argument_t>( 670 MapValueIterator<TypePair_Argument_Map_t::iterator>(range_t.first), 671 MapValueIterator<TypePair_Argument_Map_t::iterator>(range_t.second) 672 ) << "."); 673 // the first key is always easy and is pivot which the rest has to be associated to 674 if (typeiter == UniqueTypes.begin()) { 675 const argument_t & arg = range_t.first->second; 676 if ((typeiter->first == arg.types.first) && (typeiter->second == arg.types.second)) { 677 // store in correct order 678 *firstindex = arg.indices.first; 679 *secondindex = arg.indices.second; 680 } else { 681 // store in flipped order 682 *firstindex = arg.indices.second; 683 *secondindex = arg.indices.first; 684 } 685 argumentbunch.push_back(arg); 686 argument_map.erase(range_t.first); 687 LOG(4, "DEBUG: Gathered first argument " << arg << "."); 688 } else { 689 // go through the range and pick the first argument matching the index constraints 690 for (TypePair_Argument_Map_t::iterator argiter = range_t.first; 691 argiter != range_t.second; ++argiter) { 692 // seconditer may be -1 still 693 const argument_t &arg = argiter->second; 694 if (arg.indices.first == *firstindex) { 695 if ((arg.indices.second == *secondindex) || (*secondindex == (size_t)-1)) { 696 if (*secondindex == (size_t)-1) 697 *secondindex = arg.indices.second; 698 argumentbunch.push_back(arg); 699 argument_map.erase(argiter); 700 LOG(4, "DEBUG: Gathered another argument " << arg << "."); 701 break; 702 } 703 } else if ((arg.indices.first == *secondindex) || (*secondindex == (size_t)-1)) { 704 if (arg.indices.second == *firstindex) { 705 if (*secondindex == (size_t)-1) 706 *secondindex = arg.indices.first; 707 argumentbunch.push_back(arg); 708 argument_map.erase(argiter); 709 LOG(4, "DEBUG: Gathered another (flipped) argument " << arg << "."); 710 break; 711 } 712 } 713 } 714 } 715 // move along in indices and check bounds 716 ++secondindex; 717 if (secondindex == indices.end()) { 718 ++firstindex; 719 if (firstindex != indices.end()-1) 720 secondindex = firstindex+1; 721 } 722 } 723 ASSERT( (firstindex == indices.end()-1) && (secondindex == indices.end()), 724 "Extractors::reorderArgumentsByParticleTypes() - we have not gathered enough arguments."); 725 ASSERT( argumentbunch.size() == UniqueTypes.size(), 726 "Extractors::reorderArgumentsByParticleTypes() - we have not gathered enough arguments."); 727 // place bunch of arguments in return args 728 LOG(3, "DEBUG: Given types " << _types << " and found indices " << indices << "."); 729 LOG(3, "DEBUG: Final bunch of arguments is " << argumentbunch << "."); 730 sortedargs.insert(sortedargs.end(), argumentbunch.begin(), argumentbunch.end()); 731 } 732 returnargs.push_back(sortedargs); 733 } 734 735 return returnargs; 736 } 737 738 FunctionModel::list_of_arguments_t Extractors::filterArgumentsByParticleTypes( 590 739 const FunctionModel::arguments_t &args, 591 740 const ParticleTypes_t &_types 592 741 ) 593 742 { 594 /// We place all arguments into multimap according to particle type pair. 595 // here, we need a special comparator such that types in key pair are always 596 // properly ordered. 597 typedef std::multimap< 598 argument_t::types_t, 599 argument_t, 600 ParticleTypesComparator> TypePair_Argument_Map_t; 601 TypePair_Argument_Map_t argument_map; 602 for(FunctionModel::arguments_t::const_iterator iter = args.begin(); 603 iter != args.end(); ++iter) { 604 argument_map.insert( std::make_pair(iter->types, *iter) ); 605 } 606 LOG(4, "DEBUG: particle_type map is " << argument_map << "."); 607 608 /// Then, we create the desired unique keys 609 typedef std::vector<argument_t::types_t> UniqueTypes_t; 610 UniqueTypes_t UniqueTypes; 743 typedef std::list< argument_t > ListArguments_t; 744 ListArguments_t availableList(args.begin(), args.end()); 745 LOG(2, "DEBUG: Initial list of args is " << args << "."); 746 747 748 // TODO: fill a lookup map such that we don't have O(M^3) scaling, if M is number 749 // of types (and we always must have M(M-1)/2 args) but O(M^2 log(M)). However, as 750 // M is very small (<=3), this is not necessary fruitful now. 751 // typedef ParticleTypes_t firsttype; 752 // typedef ParticleTypes_t secondtype; 753 // typedef std::map< firsttype, std::map< secondtype, boost::ref(args) > > ArgsLookup_t; 754 // ArgsLookup_t ArgsLookup; 755 756 // basically, we have two choose any two pairs out of types but only those 757 // where the first is less than the latter. Hence, we start the second 758 // iterator at the current position of the first one and skip the equal case. 759 FunctionModel::arguments_t allargs; 760 allargs.reserve(args.size()); 611 761 for (ParticleTypes_t::const_iterator firstiter = _types.begin(); 612 762 firstiter != _types.end(); … … 617 767 if (seconditer == firstiter) 618 768 continue; 619 UniqueTypes.push_back( std::make_pair(*firstiter, *seconditer) ); 620 } 621 } 622 LOG(4, "DEBUG: Created unique types as keys " << UniqueTypes << "."); 623 624 /// Finally, we use the unique key list to pick corresponding arguments from the map 625 FunctionModel::arguments_t returnargs; 626 returnargs.reserve(args.size()); 627 while (!argument_map.empty()) { 628 // note that particle_types_t may be flipped, i.e. 1,8 is equal to 8,1, but we 629 // must maintain the correct order in indices in accordance with the order 630 // in _types, i.e. 1,8,1 must match with e.g. ids 1,0,2 where 1 has type 1, 631 // 0 has type 8, and 2 has type 2. 632 // In other words: We do not want to flip/modify arguments such that they match 633 // with the specific type pair we seek but then this comes at the price that we 634 // have flip indices when the types in a pair are flipped. 635 636 typedef std::vector<size_t> indices_t; 637 //!> here, we gather the indices as we discover them 638 indices_t indices; 639 indices.resize(_types.size(), (size_t)-1); 640 641 // these are two iterators that create index pairs in the same way as we have 642 // created type pairs. If a -1 is still present in indices, then the index is 643 // still arbitrary but is then set by the next found index 644 indices_t::iterator firstindex = indices.begin(); 645 indices_t::iterator secondindex = firstindex+1; 646 647 //!> here, we gather the current bunch of arguments as we find them 648 FunctionModel::arguments_t argumentbunch; 649 argumentbunch.reserve(UniqueTypes.size()); 650 651 for (UniqueTypes_t::const_iterator typeiter = UniqueTypes.begin(); 652 typeiter != UniqueTypes.end(); ++typeiter) { 653 // have all arguments to same type pair as list within the found range 654 std::pair< 655 TypePair_Argument_Map_t::iterator, 656 TypePair_Argument_Map_t::iterator> range_t = 657 argument_map.equal_range(*typeiter); 658 LOG(4, "DEBUG: Set of arguments to current key [" << typeiter->first << "," 659 << typeiter->second << "] is " << std::list<argument_t>( 660 MapValueIterator<TypePair_Argument_Map_t::iterator>(range_t.first), 661 MapValueIterator<TypePair_Argument_Map_t::iterator>(range_t.second) 662 ) << "."); 663 // the first key is always easy and is pivot which the rest has to be associated to 664 if (typeiter == UniqueTypes.begin()) { 665 const argument_t & arg = range_t.first->second; 666 if ((typeiter->first == arg.types.first) && (typeiter->second == arg.types.second)) { 667 // store in correct order 668 *firstindex = arg.indices.first; 669 *secondindex = arg.indices.second; 670 } else { 671 // store in flipped order 672 *firstindex = arg.indices.second; 673 *secondindex = arg.indices.first; 674 } 675 argumentbunch.push_back(arg); 676 argument_map.erase(range_t.first); 677 LOG(4, "DEBUG: Gathered first argument " << arg << "."); 678 } else { 679 // go through the range and pick the first argument matching the index constraints 680 for (TypePair_Argument_Map_t::iterator argiter = range_t.first; 681 argiter != range_t.second; ++argiter) { 682 // seconditer may be -1 still 683 const argument_t &arg = argiter->second; 684 if (arg.indices.first == *firstindex) { 685 if ((arg.indices.second == *secondindex) || (*secondindex == (size_t)-1)) { 686 if (*secondindex == (size_t)-1) 687 *secondindex = arg.indices.second; 688 argumentbunch.push_back(arg); 689 argument_map.erase(argiter); 690 LOG(4, "DEBUG: Gathered another argument " << arg << "."); 691 break; 692 } 693 } else if ((arg.indices.first == *secondindex) || (*secondindex == (size_t)-1)) { 694 if (arg.indices.second == *firstindex) { 695 if (*secondindex == (size_t)-1) 696 *secondindex = arg.indices.first; 697 argumentbunch.push_back(arg); 698 argument_map.erase(argiter); 699 LOG(4, "DEBUG: Gathered another (flipped) argument " << arg << "."); 700 break; 701 } 702 } 703 } 704 } 705 // move along in indices and check bounds 706 ++secondindex; 707 if (secondindex == indices.end()) { 708 ++firstindex; 709 if (firstindex != indices.end()-1) 710 secondindex = firstindex+1; 711 } 712 } 713 ASSERT( (firstindex == indices.end()-1) && (secondindex == indices.end()), 714 "Extractors::reorderArgumentsByParticleTypes() - we have not gathered enough arguments."); 715 ASSERT( argumentbunch.size() == UniqueTypes.size(), 716 "Extractors::reorderArgumentsByParticleTypes() - we have not gathered enough arguments."); 717 // place bunch of arguments in return args 718 LOG(3, "DEBUG: Given types " << _types << " and found indices " << indices << "."); 719 LOG(3, "DEBUG: Final bunch of arguments is " << argumentbunch << "."); 720 returnargs.insert(returnargs.end(), argumentbunch.begin(), argumentbunch.end()); 721 } 722 723 return returnargs; 724 } 725 726 FunctionModel::arguments_t Extractors::filterArgumentsByParticleTypes( 727 const FunctionModel::arguments_t &args, 728 const ParticleTypes_t &_types 729 ) 730 { 731 typedef std::list< argument_t > ListArguments_t; 732 ListArguments_t availableList(args.begin(), args.end()); 733 LOG(2, "DEBUG: Initial list of args is " << args << "."); 734 735 736 // TODO: fill a lookup map such that we don't have O(M^3) scaling, if M is number 737 // of types (and we always must have M(M-1)/2 args) but O(M^2 log(M)). However, as 738 // M is very small (<=3), this is not necessary fruitful now. 739 // typedef ParticleTypes_t firsttype; 740 // typedef ParticleTypes_t secondtype; 741 // typedef std::map< firsttype, std::map< secondtype, boost::ref(args) > > ArgsLookup_t; 742 // ArgsLookup_t ArgsLookup; 743 744 // basically, we have two choose any two pairs out of types but only those 745 // where the first is less than the latter. Hence, we start the second 746 // iterator at the current position of the first one and skip the equal case. 747 FunctionModel::arguments_t returnargs; 748 returnargs.reserve(args.size()); 749 for (ParticleTypes_t::const_iterator firstiter = _types.begin(); 750 firstiter != _types.end(); 751 ++firstiter) { 752 for (ParticleTypes_t::const_iterator seconditer = firstiter; 753 seconditer != _types.end(); 754 ++seconditer) { 755 if (seconditer == firstiter) 756 continue; 769 LOG(3, "DEBUG: Looking for (" << *firstiter << "," << *seconditer << ") in all args."); 757 770 758 771 // search the right one in _args (we might allow switching places of … … 760 773 ListArguments_t::iterator iter = availableList.begin(); 761 774 while (iter != availableList.end()) { 762 LOG( 3, "DEBUG: Current args is " << *iter << ".");775 LOG(4, "DEBUG: Current args is " << *iter << "."); 763 776 if ((iter->types.first == *firstiter) 764 777 && (iter->types.second == *seconditer)) { 765 returnargs.push_back( *iter );778 allargs.push_back( *iter ); 766 779 iter = availableList.erase(iter); 767 780 LOG(4, "DEBUG: Accepted argument."); 768 781 } else if ((iter->types.first == *seconditer) 769 782 && (iter->types.second == *firstiter)) { 770 returnargs.push_back( *iter );783 allargs.push_back( *iter ); 771 784 iter = availableList.erase(iter); 772 785 LOG(4, "DEBUG: Accepted (flipped) argument."); … … 778 791 } 779 792 } 780 LOG(2, "DEBUG: Final list of args is " << returnargs << "."); 793 LOG(2, "DEBUG: Final list of args is " << allargs << "."); 794 795 // first, we bring together tuples of distances that belong together 796 FunctionModel::list_of_arguments_t singlelist_allargs; 797 singlelist_allargs.push_back(allargs); 798 FunctionModel::list_of_arguments_t sortedargs = 799 reorderArgumentsByParticleTypes(singlelist_allargs, _types); 800 ASSERT( sortedargs.size() == (size_t)1, 801 "Extractors::filterArgumentsByParticleTypes() - reordering did not generate a single list."); 802 // then we split up the tuples of arguments and place each into single list 803 FunctionModel::list_of_arguments_t returnargs; 804 FunctionModel::arguments_t::const_iterator argiter = sortedargs.begin()->begin(); 805 const size_t num_types = _types.size(); 806 const size_t args_per_tuple = num_types * (num_types-1) / 2; 807 while (argiter != sortedargs.begin()->end()) { 808 FunctionModel::arguments_t currenttuple(args_per_tuple); 809 const FunctionModel::arguments_t::const_iterator startiter = argiter; 810 std::advance(argiter, args_per_tuple); 811 #ifndef NDEBUG 812 FunctionModel::arguments_t::const_iterator endoutiter = 813 #endif 814 std::copy(startiter, argiter, currenttuple.begin()); 815 ASSERT( endoutiter == currenttuple.end(), 816 "Extractors::filterArgumentsByParticleTypes() - currenttuple not initialized to right size."); 817 returnargs.push_back(currenttuple); 818 } 819 820 LOG(2, "DEBUG: We have generated " << returnargs.size() << " tuples of distances."); 781 821 782 822 return returnargs; … … 807 847 } 808 848 849 FunctionModel::list_of_arguments_t Extractors::concatenateListOfArguments( 850 const FunctionModel::list_of_arguments_t &firstlistargs, 851 const FunctionModel::list_of_arguments_t &secondlistargs) 852 { 853 FunctionModel::list_of_arguments_t listargs(firstlistargs); 854 listargs.insert(listargs.end(), secondlistargs.begin(), secondlistargs.end()); 855 return listargs; 856 } -
src/FunctionApproximation/Extractors.hpp
r16227a re1fe7e 304 304 /** Reorder arguments by increasing distance. 305 305 * 306 * \param args arguments to reorder306 * \param listargs list of arguments to reorder each 307 307 * \return reordered args 308 308 */ 309 FunctionModel:: arguments_t reorderArgumentsByIncreasingDistance(310 const FunctionModel:: arguments_t &args309 FunctionModel::list_of_arguments_t reorderArgumentsByIncreasingDistance( 310 const FunctionModel::list_of_arguments_t &listargs 311 311 ); 312 312 … … 318 318 * \sa filterArgumentsByParticleTypes() 319 319 * 320 * \param listargs list of arguments to reorder each 321 * \param _types particle type vector 322 * \return reordered args 323 */ 324 FunctionModel::list_of_arguments_t reorderArgumentsByParticleTypes( 325 const FunctionModel::list_of_arguments_t &eachargs, 326 const ParticleTypes_t &_types 327 ); 328 329 /** Filter arguments according to types, allowing multiples. 330 * 331 * If particle types is (0,1,2) and three arguments, each with a pair of types, 332 * are given, then the alignment will be: (0,1), (0,2), and (1,2). 333 * 320 334 * \param args arguments to reorder 321 335 * \param _types particle type vector 322 * \return reordered args 323 */ 324 FunctionModel::arguments_t reorderArgumentsByParticleTypes( 325 const FunctionModel::arguments_t &args, 326 const ParticleTypes_t &_types 327 ); 328 329 /** Filter arguments according to types. 330 * 331 * If particle types is (0,1,2) and three arguments, each with a pair of types, 332 * are given, then the alignment will be: (0,1), (0,2), and (1,2). 333 * 334 * \param args arguments to reorder 335 * \param _types particle type vector 336 * \return filtered args 337 */ 338 FunctionModel::arguments_t filterArgumentsByParticleTypes( 336 * \return filtered list of args 337 */ 338 FunctionModel::list_of_arguments_t filterArgumentsByParticleTypes( 339 339 const FunctionModel::arguments_t &args, 340 340 const ParticleTypes_t &_types … … 361 361 const FunctionModel::arguments_t &secondargs); 362 362 363 /** Combines two argument lists by concatenation. 364 * 365 * @param firstlistargs first list of argument tuples 366 * @param secondlistargs second list of argument tuples 367 * @return concatenated lists 368 */ 369 FunctionModel::list_of_arguments_t concatenateListOfArguments( 370 const FunctionModel::list_of_arguments_t &firstlistargs, 371 const FunctionModel::list_of_arguments_t &secondlistargs); 372 363 373 }; /* namespace Extractors */ 364 374 -
src/FunctionApproximation/FunctionApproximation.cpp
r16227a re1fe7e 64 64 {} 65 65 66 void FunctionApproximation::setTrainingData(const inputs_t &input, const outputs_t &output)66 void FunctionApproximation::setTrainingData(const filtered_inputs_t &input, const outputs_t &output) 67 67 { 68 68 ASSERT( input.size() == output.size(), … … 334 334 +" outputs but we provide "+toString(output_data.size())+"."); 335 335 if (!output_data.empty()) { 336 inputs_t::const_iterator initer = input_data.begin();336 filtered_inputs_t::const_iterator initer = input_data.begin(); 337 337 outputs_t::const_iterator outiter = output_data.begin(); 338 338 size_t index = 0; … … 362 362 +" outputs but we provide "+toString(output_data.size())+"."); 363 363 if (!output_data.empty()) { 364 inputs_t::const_iterator initer = input_data.begin();364 filtered_inputs_t::const_iterator initer = input_data.begin(); 365 365 outputs_t::const_iterator outiter = output_data.begin(); 366 366 size_t index = 0; -
src/FunctionApproximation/FunctionApproximation.hpp
r16227a re1fe7e 71 71 //!> typedef for a vector of input arguments 72 72 typedef std::vector<FunctionModel::arguments_t> inputs_t; 73 //!> typedef for a vector of input arguments 74 typedef std::vector<FunctionModel::list_of_arguments_t> filtered_inputs_t; 73 75 //!> typedef for a vector of output values 74 76 typedef std::vector<FunctionModel::results_t> outputs_t; … … 110 112 * FunctionApproximation::output_dimension size 111 113 */ 112 void setTrainingData(const inputs_t &input, const outputs_t &output);114 void setTrainingData(const filtered_inputs_t &input, const outputs_t &output); 113 115 114 116 /** Setter for the model function to be used in the approximation. … … 191 193 192 194 //!> current input set of training data 193 inputs_t input_data;195 filtered_inputs_t input_data; 194 196 //!> current output set of training data 195 197 outputs_t output_data; -
src/FunctionApproximation/FunctionModel.hpp
r16227a re1fe7e 15 15 16 16 #include <boost/function.hpp> 17 #include <list> 17 18 #include <vector> 18 19 … … 58 59 //!> typedef for the whole set of parameters of the function 59 60 typedef std::vector<parameter_t> parameters_t; 60 //!> typedef for the argument vector as input to the function 61 //!> typedef for the argument vector as input to the function (subset of distances) 61 62 typedef std::vector<argument_t> arguments_t; 63 //!> typedef for a list of argument vectors as input to the function (list of subsets) 64 typedef std::list<arguments_t> list_of_arguments_t; 62 65 //!> typedef for a single result degree of freedom 63 66 typedef double result_t; … … 65 68 typedef std::vector<result_t> results_t; 66 69 //!> typedef for a function containing how to extract required information from a Fragment. 67 typedef boost::function< arguments_t (const Fragment &, const size_t)> extractor_t;70 typedef boost::function< list_of_arguments_t (const Fragment &, const size_t)> extractor_t; 68 71 //!> typedef for a function containing how to filter required distances from a full argument list. 69 typedef boost::function< arguments_t (const arguments_t &)> filter_t;72 typedef boost::function< list_of_arguments_t (const arguments_t &)> filter_t; 70 73 //!> typedef for the magic triple function that gets the other two distances for a given argument 71 74 typedef boost::function< std::vector<arguments_t>(const argument_t &, const double)> triplefunction_t; … … 114 117 * \return result of the function 115 118 */ 116 virtual results_t operator()(const arguments_t &arguments) const=0;119 virtual results_t operator()(const list_of_arguments_t &arguments) const=0; 117 120 118 121 /** Evaluates the derivative of the function with the given \a arguments … … 124 127 * input 125 128 */ 126 virtual results_t parameter_derivative(const arguments_t &arguments, const size_t index) const=0;129 virtual results_t parameter_derivative(const list_of_arguments_t &arguments, const size_t index) const=0; 127 130 128 131 /** States whether lower and upper boundaries should be used to constraint -
src/FunctionApproximation/TrainingData.cpp
r16227a re1fe7e 68 68 EnergyVector.push_back( FunctionModel::results_t(1, energy) ); 69 69 // filter distances out of list of all arguments 70 FunctionModel:: arguments_t args = filter(all_args);70 FunctionModel::list_of_arguments_t args = filter(all_args); 71 71 LOG(3, "DEBUG: Filtered arguments are " << args << "."); 72 72 ArgumentVector.push_back( args ); … … 78 78 double L2sum = 0.; 79 79 80 F unctionApproximation::inputs_t::const_iterator initer = ArgumentVector.begin();81 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();80 FilteredInputVector_t::const_iterator initer = ArgumentVector.begin(); 81 OutputVector_t::const_iterator outiter = EnergyVector.begin(); 82 82 for (; initer != ArgumentVector.end(); ++initer, ++outiter) { 83 83 const FunctionModel::results_t result = model((*initer)); … … 92 92 double Lmax = 0.; 93 93 // size_t maxindex = -1; 94 F unctionApproximation::inputs_t::const_iterator initer = ArgumentVector.begin();95 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();94 FilteredInputVector_t::const_iterator initer = ArgumentVector.begin(); 95 OutputVector_t::const_iterator outiter = EnergyVector.begin(); 96 96 for (; initer != ArgumentVector.end(); ++initer, ++outiter) { 97 97 const FunctionModel::results_t result = model((*initer)); … … 113 113 const range_t &range) const 114 114 { 115 TrainingData::L2ErrorConfigurationIndexMap_t WorseFragmentMap;115 L2ErrorConfigurationIndexMap_t WorseFragmentMap; 116 116 // fragments make it into the container in reversed order, hence count from top down 117 117 size_t index= std::distance(range.first, range.second)-1; 118 InputVector_t::const_iterator initer = ArgumentVector.begin(); 118 InputVector_t::const_iterator distanceiter = DistanceVector.begin(); 119 FilteredInputVector_t::const_iterator initer = ArgumentVector.begin(); 119 120 OutputVector_t::const_iterator outiter = EnergyVector.begin(); 120 for (; initer != ArgumentVector.end(); ++initer, ++outiter ) {121 for (; initer != ArgumentVector.end(); ++initer, ++outiter, ++distanceiter) { 121 122 // calculate value from potential 122 const FunctionModel:: arguments_t &args = *initer;123 const FunctionModel::list_of_arguments_t &args = *initer; 123 124 const FunctionModel::results_t result = model(args); 124 125 const double energy = (*outiter)[0]; … … 131 132 // give only the distances in the debugging text 132 133 std::stringstream streamargs; 133 BOOST_FOREACH (argument_t arg, args) {134 BOOST_FOREACH (argument_t arg, *distanceiter) { 134 135 streamargs << " " << arg.distance; 135 136 } … … 148 149 /// extract distance member variable from argument_t and first value from results_t 149 150 OutputVector_t::const_iterator ergiter = EnergyVector.begin(); 150 for (InputVector_t::const_iterator iter = ArgumentVector.begin();151 iter != ArgumentVector.end(); ++iter, ++ergiter) {151 for (InputVector_t::const_iterator iter = DistanceVector.begin(); 152 iter != DistanceVector.end(); ++iter, ++ergiter) { 152 153 ASSERT( ergiter != EnergyVector.end(), 153 154 "TrainingData::getDistanceEnergyTable() - less output than input values."); -
src/FunctionApproximation/TrainingData.hpp
r16227a re1fe7e 27 27 * Fragment. 28 28 * 29 * In TrainingData::operator() we construct first all pair-wise distances as30 * list of all arguments. Then, these are filtered depending on the specific31 * FunctionModel's Filter and only these are handed to down to evaluate it.29 * TrainingData::operator() takes the set of all possible pair-wise distances 30 * (InputVector_t) and transforms it via the given filter into a list of subsets 31 * of distances (FilteredInputVector_t) that is feedable to the model. 32 32 * 33 33 */ … … 41 41 //!> Training tuple input vector pair 42 42 typedef FunctionApproximation::inputs_t InputVector_t; 43 //!> Training tuple modified input vector pair 44 typedef FunctionApproximation::filtered_inputs_t FilteredInputVector_t; 43 45 //!> Training tuple output vector pair 44 46 typedef FunctionApproximation::outputs_t OutputVector_t; … … 47 49 //!> Typedef for a map of each fragment with error. 48 50 typedef std::multimap< double, size_t > L2ErrorConfigurationIndexMap_t; 49 50 51 51 52 public: … … 75 76 * \return const ref to training tuple of input vector 76 77 */ 77 const InputVector_t& getTrainingInputs() const {78 const FilteredInputVector_t& getTrainingInputs() const { 78 79 return ArgumentVector; 79 80 } … … 142 143 OutputVector_t EnergyVector; 143 144 //!> list of all filtered arguments over all tuples 144 InputVector_t ArgumentVector;145 FilteredInputVector_t ArgumentVector; 145 146 //!> function to be used for training input data extraction from a fragment 146 147 const FunctionModel::filter_t filter; -
src/FunctionApproximation/unittests/ExtractorsUnitTest.cpp
r16227a re1fe7e 182 182 args.push_back(arg); 183 183 CPPUNIT_ASSERT_EQUAL( (size_t)3, args.size() ); 184 FunctionModel::list_of_arguments_t listargs(1, args); 184 185 185 186 // reorder 186 FunctionModel::arguments_t args_sorted = 187 Extractors::reorderArgumentsByIncreasingDistance(args); 187 FunctionModel::list_of_arguments_t listargs_sorted = 188 Extractors::reorderArgumentsByIncreasingDistance(listargs); 189 CPPUNIT_ASSERT_EQUAL( (size_t)1, listargs_sorted.size() ); 190 FunctionModel::arguments_t args_sorted = *(listargs_sorted.begin()); 188 191 CPPUNIT_ASSERT_EQUAL( (size_t)3, args_sorted.size() ); 189 192 CPPUNIT_ASSERT_EQUAL( args[0].distance, args_sorted[0].distance );
Note:
See TracChangeset
for help on using the changeset viewer.