Changeset e47ac7 for src/FunctionApproximation
- Timestamp:
- Nov 4, 2016, 9:37:50 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:
- c7aac9
- Parents:
- 16c6f7
- git-author:
- Frederik Heber <heber@…> (10/02/16 13:59:35)
- git-committer:
- Frederik Heber <heber@…> (11/04/16 09:37:50)
- Location:
- src/FunctionApproximation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FunctionApproximation/Extractors.cpp
r16c6f7 re47ac7 55 55 56 56 using namespace boost::assign; 57 58 FunctionModel::arguments_t59 Extractors::gatherAllDistanceArguments(60 const Fragment::positions_t& positions,61 const Fragment::charges_t& charges,62 const size_t globalid)63 {64 FunctionModel::arguments_t result;65 66 // go through current configuration and gather all other distances67 Fragment::positions_t::const_iterator firstpositer = positions.begin();68 for (;firstpositer != positions.end(); ++firstpositer) {69 Fragment::positions_t::const_iterator secondpositer = positions.begin();//firstpositer;70 for (; secondpositer != positions.end(); ++secondpositer) {71 if (firstpositer == secondpositer)72 continue;73 argument_t arg;74 const Vector firsttemp((*firstpositer)[0],(*firstpositer)[1],(*firstpositer)[2]);75 const Vector secondtemp((*secondpositer)[0],(*secondpositer)[1],(*secondpositer)[2]);76 arg.distance = firsttemp.distance(secondtemp);77 arg.types = std::make_pair(78 charges[ std::distance(positions.begin(), firstpositer) ],79 charges[ std::distance(positions.begin(), secondpositer) ]80 );81 arg.indices = std::make_pair(82 std::distance(83 positions.begin(), firstpositer),84 std::distance(85 positions.begin(), secondpositer)86 );87 arg.globalid = globalid;88 result.push_back(arg);89 }90 }91 92 return result;93 }94 57 95 58 FunctionModel::arguments_t … … 131 94 } 132 95 133 Fragment::positions_t Extractors::_detail::gatherPositionsFromTargets(134 const Fragment::positions_t& positions,135 const Fragment::charges_t& charges,136 const chargeiters_t &targets137 )138 {139 Fragment::positions_t filtered_positions;140 for (chargeiters_t::const_iterator firstpairiter = targets.begin();141 firstpairiter != targets.end(); ++firstpairiter) {142 Fragment::positions_t::const_iterator positer = positions.begin();143 const size_t steps = std::distance(charges.begin(), *firstpairiter);144 std::advance(positer, steps);145 filtered_positions.push_back(*positer);146 }147 return filtered_positions;148 }149 150 FunctionModel::arguments_t Extractors::_detail::gatherDistancesFromTargets(151 const Fragment::positions_t& positions,152 const Fragment::charges_t& charges,153 const chargeiters_t &targets,154 const size_t globalid155 )156 {157 Fragment::positions_t filtered_positions;158 Fragment::charges_t filtered_charges;159 for (chargeiters_t::const_iterator firstpairiter = targets.begin();160 firstpairiter != targets.end(); ++firstpairiter) {161 Fragment::positions_t::const_iterator positer = positions.begin();162 const size_t steps = std::distance(charges.begin(), *firstpairiter);163 std::advance(positer, steps);164 filtered_positions.push_back(*positer);165 filtered_charges.push_back(**firstpairiter);166 }167 return Extractors::gatherAllSymmetricDistanceArguments(168 filtered_positions,169 filtered_charges,170 globalid);171 }172 173 96 Extractors::elementcounts_t 174 97 Extractors::_detail::getElementCounts( … … 188 111 return elementcounts; 189 112 } 190 191 Extractors::elementtargets_t192 Extractors::_detail::convertElementcountsToTargets(193 const Fragment::charges_t &charges,194 const elementcounts_t &elementcounts195 )196 {197 elementtargets_t elementtargets;198 for (elementcounts_t::const_iterator countiter = elementcounts.begin();199 countiter != elementcounts.end();200 ++countiter) {201 chargeiter_t chargeiter = charges.begin();202 const element_t &element = countiter->first;203 const count_t &count = countiter->second;204 for (count_t i = 0; i < count; ++i) {205 chargeiter_t tempiter = std::find(chargeiter, charges.end(), element);206 if (tempiter != charges.end()) {207 // try to insert new list208 std::pair< elementtargets_t::iterator, bool> inserter =209 elementtargets.insert( std::make_pair( countiter->first, chargeiters_t(1, tempiter)) );210 // if already present, append to it211 if (!inserter.second) {212 inserter.first->second.push_back(tempiter);213 } else { // if created, increase vector's reserve to known size214 inserter.first->second.reserve(countiter->second);215 }216 // search from this element onwards then217 chargeiter = ++tempiter;218 } else {219 ELOG(1, "Could not find desired number " << count << " of element "220 << element << " in fragment with " << charges << ".");221 return Extractors::elementtargets_t();222 }223 }224 }225 return elementtargets;226 }227 228 Extractors::elementtargets_t229 Extractors::_detail::convertChargesToTargetMap(230 const Fragment::charges_t& charges,231 Fragment::charges_t elements232 )233 {234 // place each charge into a map235 elementtargets_t completeelementtargets;236 for (chargeiter_t chargeiter = charges.begin();237 chargeiter != charges.end();238 ++chargeiter) {239 std::pair< elementtargets_t::iterator, bool> inserter =240 completeelementtargets.insert( std::make_pair( *chargeiter, chargeiters_t(1, chargeiter)) );241 // if already present, append to it242 if (!inserter.second) {243 inserter.first->second.push_back(chargeiter);244 }245 }246 // pick out desired charges only247 std::sort(elements.begin(), elements.end());248 Fragment::charges_t::iterator eraseiter =249 std::unique(elements.begin(), elements.end());250 elements.erase(eraseiter, elements.end());251 elementtargets_t elementtargets;252 for(Fragment::charges_t::const_iterator iter = elements.begin();253 iter != elements.end();254 ++iter) {255 elementtargets_t::const_iterator finditer = completeelementtargets.find(*iter);256 ASSERT( finditer != completeelementtargets.end(),257 "Extractors::_detail::convertChargesToTargetMap() - no element "+toString(*iter)+" present?");258 std::pair< elementtargets_t::iterator, bool> inserter =259 elementtargets.insert( std::make_pair( finditer->first, finditer->second) );260 ASSERT( inserter.second,261 "Extractors::_detail::convertChargesToTargetMap() - key twice?");262 }263 return elementtargets;264 }265 266 267 Extractors::chargeiters_t268 Extractors::_detail::realignElementtargets(269 const elementtargets_t &elementtargets,270 const Fragment::charges_t elements,271 const elementcounts_t &elementcounts272 )273 {274 chargeiters_t targets;275 elementcounts_t counts; // how many chargeiters of this element have been used276 if (!elements.empty()) { // skip if no elements given277 targets.reserve(elements.size());278 for (Fragment::charges_t::const_iterator elementiter = elements.begin();279 elementiter != elements.end(); ++elementiter) {280 const element_t &element = *elementiter;281 count_t &count = counts[element]; // if not present, std::map creates instances with default of 0282 #ifndef NDEBUG283 {284 elementcounts_t::const_iterator testiter = elementcounts.find(element);285 ASSERT( (testiter != elementcounts.end()) && (count < testiter->second),286 "Extractors::_detail::realignElementTargets() - we want to use more chargeiters for element "287 +toString(element)+" than we counted initially.");288 }289 #endif290 elementtargets_t::const_iterator targetiter = elementtargets.find(element);291 if (targetiter != elementtargets.end()) {292 const chargeiters_t &chargeiters = targetiter->second;293 const chargeiter_t &chargeiter = chargeiters[count++];294 targets.push_back(chargeiter);295 }296 }297 }298 return targets;299 }300 301 FunctionModel::arguments_t302 Extractors::gatherAllDistancesFromFragment(303 const Fragment::positions_t& positions,304 const Fragment::charges_t& charges,305 const Fragment::charges_t elements,306 const size_t globalid307 )308 {309 /// The main problem here is that we have to know how many same310 /// elements (but different atoms!) we are required to find. Hence,311 /// we first have to count same elements, then get different targets312 /// for each and then associated them in correct order back again.313 314 // 0. if no elements given, we return empty arguments315 if (elements.empty())316 return FunctionModel::arguments_t();317 318 // 1. we have to place each charge into a map as unique chargeiter, i.e. map319 elementtargets_t elementtargets =320 Extractors::_detail::convertChargesToTargetMap(321 charges,322 elements);323 324 // 2. now we have to combine elementcounts out of elementtargets per desired element325 // in a combinatorial fashion326 targets_per_combination_t combinations =327 Extractors::_detail::CombineChargesAndTargets(328 elements,329 elementtargets);330 331 // 3. finally, convert chargeiters into argument list332 FunctionModel::arguments_t args =333 Extractors::_detail::convertTargetsToArguments(334 positions,335 charges,336 combinations,337 globalid);338 339 return args;340 }341 342 Extractors::targets_per_combination_t343 Extractors::_detail::CombineChargesAndTargets(344 const Fragment::charges_t& elements,345 const elementtargets_t& elementtargets346 )347 {348 // recursively create all correct combinations of targets349 targets_per_combination_t combinations;350 chargeiters_t currenttargets;351 boost::function<void (const chargeiters_t ¤ttargets)> addFunction =352 boost::bind(&targets_per_combination_t::push_back,353 boost::ref(combinations),354 _1);355 pickLastElementAsTarget(elements, elementtargets, currenttargets, addFunction);356 357 return combinations;358 }359 360 const Fragment::position_t& getPositionToChargeIter(361 const Fragment::positions_t& positions,362 const Fragment::charges_t& charges,363 const Extractors::chargeiter_t &iter364 )365 {366 Fragment::positions_t::const_iterator positer = positions.begin();367 std::advance(positer, std::distance(charges.begin(), iter));368 const Fragment::position_t &position = *positer;369 return position;370 }371 372 373 FunctionModel::arguments_t374 Extractors::_detail::convertTargetsToArguments(375 const Fragment::positions_t& positions,376 const Fragment::charges_t& charges,377 const targets_per_combination_t combinations,378 const size_t globalid379 )380 {381 FunctionModel::arguments_t args;382 // create arguments from each combination. We cannot use383 // gatherallSymmetricDistanceArguments() because it would not create the384 // correct indices.385 for (targets_per_combination_t::const_iterator iter = combinations.begin();386 iter != combinations.end();387 ++iter) {388 for(chargeiters_t::const_iterator firstiter = iter->begin();389 firstiter != iter->end();390 ++firstiter) {391 const Fragment::position_t &firstpos =392 getPositionToChargeIter(positions, charges, *firstiter);393 const Vector firsttemp(firstpos[0],firstpos[1],firstpos[2]);394 for(chargeiters_t::const_iterator seconditer = firstiter;395 seconditer != iter->end();396 ++seconditer) {397 if (firstiter == seconditer)398 continue;399 const Fragment::position_t &secondpos =400 getPositionToChargeIter(positions, charges, *seconditer);401 const Vector secondtemp(secondpos[0],secondpos[1],secondpos[2]);402 argument_t arg;403 arg.distance = firsttemp.distance(secondtemp);404 arg.indices.first = std::distance(charges.begin(), *firstiter);405 arg.indices.second = std::distance(charges.begin(), *seconditer);406 arg.types.first = **firstiter;407 arg.types.second = **seconditer;408 args.push_back( arg );409 }410 }411 }412 413 return args;414 }415 416 void417 Extractors::_detail::pickLastElementAsTarget(418 Fragment::charges_t elements,419 elementtargets_t elementtargets,420 chargeiters_t ¤ttargets,421 boost::function<void (const chargeiters_t ¤ttargets)> &addFunction422 )423 {424 // get last element from charges425 ASSERT( !elements.empty(),426 "Extractors::_detail::pickLastElementAsTarget() - no elements given to pick targets for.");427 const Fragment::charge_t charge = elements.back();428 elements.pop_back();429 elementtargets_t::iterator iter = elementtargets.find(charge);430 if (iter == elementtargets.end())431 return;432 bool NotEmpty = !iter->second.empty();433 while (NotEmpty) {434 // get last target from the vector of chargeiters435 chargeiter_t target = iter->second.back();436 iter->second.pop_back();437 // remove this key if empty438 if (iter->second.empty()) {439 elementtargets.erase(iter);440 NotEmpty = false;441 }442 currenttargets.push_back(target);443 if (elements.empty()) {444 // call add function445 {446 std::stringstream targetstream;447 BOOST_FOREACH( chargeiter_t target, currenttargets ) {448 targetstream << " " << *target;449 }450 LOG(3, "DEBUG: Adding set" << targetstream.str() << ".");451 }452 addFunction(currenttargets);453 } else {454 // if not, call us recursively455 pickLastElementAsTarget(elements, elementtargets, currenttargets, addFunction);456 }457 // pop last in currenset again458 currenttargets.pop_back();459 }460 }461 462 Extractors::chargeiters_t463 Extractors::_detail::gatherTargetsFromFragment(464 const Fragment::charges_t& charges,465 const Fragment::charges_t elements466 )467 {468 /// The main problem here is that we have to know how many same469 /// elements (but different atoms!) we are required to find. Hence,470 /// we first have to count same elements, then get different targets471 /// for each and then associated them in correct order back again.472 473 // 1. we have to make elements unique with counts, hence convert to map474 elementcounts_t elementcounts =475 Extractors::_detail::getElementCounts(elements);476 477 // 2. then for each element we need as many targets (chargeiters) as counts478 elementtargets_t elementtargets =479 Extractors::_detail::convertElementcountsToTargets(charges, elementcounts);480 481 // 3. we go again through elements and use one found target for each count482 // in that order483 chargeiters_t targets =484 Extractors::_detail::realignElementtargets(elementtargets, elements, elementcounts);485 486 #ifndef NDEBUG487 // check all for debugging488 for (chargeiters_t::const_iterator chargeiter = targets.begin();489 chargeiter != targets.end();490 ++chargeiter)491 ASSERT( *chargeiter != charges.end(),492 "Extractors::gatherTargetsFromFragment() - we have not found enough targets?!");493 #endif494 495 return targets;496 }497 498 Fragment::positions_t499 Extractors::gatherPositionsFromFragment(500 const Fragment::positions_t positions,501 const Fragment::charges_t charges,502 const Fragment::charges_t& elements503 )504 {505 // 1.-3. gather correct charge positions506 chargeiters_t targets =507 Extractors::_detail::gatherTargetsFromFragment(charges, elements);508 // 4. convert position_t to Vector509 return Extractors::_detail::gatherPositionsFromTargets(510 positions,511 charges,512 targets);513 }514 515 FunctionModel::arguments_t516 Extractors::gatherDistancesFromFragment(517 const Fragment::positions_t positions,518 const Fragment::charges_t charges,519 const Fragment::charges_t& elements,520 const size_t globalid521 )522 {523 // 1.-3. gather correct charge positions524 chargeiters_t targets =525 Extractors::_detail::gatherTargetsFromFragment(charges, elements);526 // 4. convert position_t to Vector527 return Extractors::_detail::gatherDistancesFromTargets(528 positions,529 charges,530 targets,531 globalid);532 }533 534 FunctionModel::list_of_arguments_t Extractors::reorderArgumentsByIncreasingDistance(535 const FunctionModel::list_of_arguments_t &listargs536 )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 }546 return returnargs;547 }548 549 113 550 114 struct ParticleTypesComparator { -
src/FunctionApproximation/Extractors.hpp
r16c6f7 re47ac7 52 52 */ 53 53 namespace _detail { 54 /** Gather all distance arguments from the same aligned vector of charges.55 *56 * Basically, we filter the positions indicated by the targets but57 * from a different vector that has the same layout.58 *59 * \param positions all nuclei positions60 * \param charges all nuclei charges61 * \param targets iterators on charges62 * \return filtered distance arguments63 */64 FunctionModel::arguments_t gatherDistancesFromTargets(65 const Fragment::positions_t& positions,66 const Fragment::charges_t& charges,67 const chargeiters_t &targets,68 const size_t globalid69 );70 71 /** Gather all positions from the same aligned vector of charges.72 *73 * Basically, we filter the positions indicated by the targets but74 * from a different vector that has the same layout.75 *76 * \param positions all nuclei positions77 * \param charges all nuclei charges78 * \param targets iterators on charges79 * \return filtered positions80 */81 Fragment::positions_t gatherPositionsFromTargets(82 const Fragment::positions_t& positions,83 const Fragment::charges_t& charges,84 const chargeiters_t& targets85 );86 54 87 55 /** Counts all same elements in the vector and places into map of elements. … … 94 62 ); 95 63 96 /** Gather iterators to the elements related to the desired elementcounts.97 *98 * \param charges charges wherein to search for the elements99 * \param elementcounts number of desired hits per element100 * \return iterators equal to the initial vector of elements101 */102 elementtargets_t convertElementcountsToTargets(103 const Fragment::charges_t &charges,104 const elementcounts_t &elementcounts105 );106 107 /** Convert the alignment back to as it was in the original vector.108 *109 * We lost the information by storing it in a map. Hence, we need this110 * final step.111 *112 * \param elementtargets targets as they are in the map \a elementcounts113 * \param elements the original order of the elements114 * \param elementcounts the count per element for debugging checks115 * \return vector of targets in the order as they are in \a element116 */117 chargeiters_t realignElementtargets(118 const elementtargets_t &elementtargets,119 const Fragment::charges_t elements,120 const elementcounts_t &elementcounts121 );122 123 /** Searches for desired elements in charges in a unique manner.124 *125 * The idea is to have e.g. a fragment with charges 8,1,1,2 and126 * elements as 1,8,1 (e.g. for an angle HOH) and we get the127 * chargeiters in the desired manner on indices: 1,0,3.128 *129 * \param charges charges to look through130 * \param elements vector of elements to find131 */132 chargeiters_t133 gatherTargetsFromFragment(134 const Fragment::charges_t& charges,135 const Fragment::charges_t elements136 );137 138 /** Brings all charges together in a map.139 *140 * @param charges charges as possible keys and their iterators as values in the map141 * @param elements list of charges to pick as keys142 * @return map of key and a vector of charge iterators143 */144 elementtargets_t convertChargesToTargetMap(145 const Fragment::charges_t& charges,146 Fragment::charges_t elements147 );148 149 /** Brings combinatorially together desired list of \a charges and \a targets.150 *151 * @param charges list of desired charges152 * @param elementtargets map of available targets per element153 * @return vector of chargeiters with all unique combinations154 */155 targets_per_combination_t156 CombineChargesAndTargets(157 const Fragment::charges_t& charges,158 const elementtargets_t& elementtargets159 );160 161 /** Recursive function to pick the next target.162 *163 * This is used by \sa CombineChargesAndTargets()164 *165 * @param charges set of charges, reduced by one per recursion166 * @param elementtargets targets, map of targets to pick from167 * @param currenttargets current set of targets, "global" through recursion168 * @param addFunction bound function to add a set when complete169 */170 void pickLastElementAsTarget(171 Fragment::charges_t elements,172 elementtargets_t elementtargets,173 chargeiters_t& currenttargets,174 boost::function<void (const chargeiters_t ¤ttargets)> &addFunction175 );176 177 /** Converts a list of chargeiters to a list of respective arguments.178 *179 * @param positions positions from fragment180 * @param charges charges associated to each element in \a positions181 * @param combinations vector of chargeiters182 * \param globalid refers to the index within the global set of configurations183 * @return list of arguments184 */185 FunctionModel::arguments_t186 convertTargetsToArguments(187 const Fragment::positions_t& positions,188 const Fragment::charges_t& charges,189 const targets_per_combination_t combinations,190 const size_t globalid191 );192 64 } 193 194 /** Gather all distances from a given set of positions.195 *196 * \param positions all nuclei positions197 * \param charges all nuclei charges198 * \param globalid index to associated in argument_t with199 * \return vector of argument_ , each with a distance200 */201 FunctionModel::arguments_t202 gatherAllDistanceArguments(203 const Fragment::positions_t& positions,204 const Fragment::charges_t& charges,205 const size_t globalid);206 65 207 66 /** Gather all distances from a given set of positions. … … 219 78 const Fragment::charges_t& charges, 220 79 const size_t globalid); 221 222 /** Simple extractor of all unique pair distances of a given \a fragment.223 *224 * \param positions all nuclei positions225 * \param charges all nuclei charges226 * \param index index refers to the index within the global set of configurations227 * \return vector of of argument_t containing all found distances228 */229 inline FunctionModel::arguments_t gatherAllDistances(230 const Fragment::positions_t& positions,231 const Fragment::charges_t& charges,232 const size_t index233 ) {234 // get distance out of Fragment235 return gatherAllDistanceArguments(positions, charges, index);236 }237 80 238 81 /** Simple extractor of all unique pair distances of a given \a fragment, where … … 252 95 return gatherAllSymmetricDistanceArguments(positions, charges, index); 253 96 } 254 255 /** Filters only those positions out of given \a fragment that match \a elements.256 *257 * \param positions all nuclei positions258 * \param charges all nuclei charges259 * \param elements tuple of desired elements260 * \return vector of positions_t containing261 */262 Fragment::positions_t gatherPositionsFromFragment(263 const Fragment::positions_t positions,264 const Fragment::charges_t charges,265 const Fragment::charges_t& elements266 );267 268 /** Filters only those distances out of given \a fragment that match \a elements.269 *270 * \param positions all nuclei positions271 * \param charges all nuclei charges272 * \param elements tuple of desired elements273 * \param globalid refers to the index within the global set of configurations274 * \return vector of arguments_t containing those matched with elements275 */276 FunctionModel::arguments_t gatherDistancesFromFragment(277 const Fragment::positions_t positions,278 const Fragment::charges_t charges,279 const Fragment::charges_t& elements,280 const size_t globalid281 );282 283 /** Gather all combinations of charges as distance arguments from the fragment.284 *285 * E.g. we have a water fragment, i.e. (8,1,1) and we we want elements (8,1),286 * then two arguments are returned, first to second and first to third.287 *288 * With \sa gatherDistancesFromFragment() only the first distance would be289 * returned.290 *291 * @param positions positions in fragment292 * @param charges charges in fragment293 * @param elements list of desired elements294 * @param globalid some global id to discern training data tuples295 * @return list of arguments with distances296 */297 FunctionModel::arguments_t gatherAllDistancesFromFragment(298 const Fragment::positions_t& positions,299 const Fragment::charges_t& charges,300 const Fragment::charges_t elements,301 const size_t globalid302 );303 304 /** Reorder arguments by increasing distance.305 *306 * \param listargs list of arguments to reorder each307 * \return reordered args308 */309 FunctionModel::list_of_arguments_t reorderArgumentsByIncreasingDistance(310 const FunctionModel::list_of_arguments_t &listargs311 );312 97 313 98 /** Reorder the arguments to bring adjacent ones together. -
src/FunctionApproximation/unittests/ExtractorsUnitTest.cpp
r16c6f7 re47ac7 72 72 } 73 73 74 /** UnitTest for gatherAll DistanceArguments()74 /** UnitTest for gatherAllSymmetricDistances() 75 75 */ 76 void ExtractorsTest::gatherAll DistanceArgumentsTest()76 void ExtractorsTest::gatherAllSymmetricDistancesTest() 77 77 { 78 78 // create positions … … 90 90 // create distances 91 91 FunctionModel::arguments_t args = 92 Extractors::gatherAll DistanceArguments(positions, charges, 0);93 CPPUNIT_ASSERT_EQUAL( (size_t)(5*4 ), args.size() );92 Extractors::gatherAllSymmetricDistances(positions, charges, 0); 93 CPPUNIT_ASSERT_EQUAL( (size_t)(5*4/2), args.size() ); 94 94 95 95 // check created args 96 for (size_t i=0; i< 5*4; ++i)96 for (size_t i=0; i< (5*4)/2; ++i) 97 97 CPPUNIT_ASSERT( (args[i].distance >= 0) && (args[i].distance <= 4)); 98 98 } 99 100 /** UnitTest for gatherPositionsFromFragment()101 */102 void ExtractorsTest::gatherPositionsFromFragmentTest()103 {104 // create positions105 Fragment::positions_t positions;106 Fragment::position_t pos(3, 0.);107 for (double i = 0; i < 5; i+=1.) {108 pos[0] = i;109 positions.push_back(pos);110 }111 112 // create charges113 Fragment::charges_t charges;114 charges += 6., 6., 1., 1., 1.;115 116 {117 // extract carbon pairs118 Fragment::charges_t carbonpair;119 carbonpair += 6.,6.;120 Fragment::positions_t filtered_positions =121 Extractors::gatherPositionsFromFragment(positions, charges, carbonpair);122 CPPUNIT_ASSERT_EQUAL( (size_t)2, filtered_positions.size() );123 }124 125 {126 // extract hydrogen triple127 Fragment::charges_t hydrogentriple;128 hydrogentriple += 1.,1.,1.;129 Fragment::positions_t filtered_positions =130 Extractors::gatherPositionsFromFragment(positions, charges, hydrogentriple);131 CPPUNIT_ASSERT_EQUAL( (size_t)3, filtered_positions.size() );132 }133 }134 135 /** UnitTest for gatherDistancesFromFragment()136 */137 void ExtractorsTest::gatherDistancesFromFragmentTest()138 {139 // create positions140 Fragment::positions_t positions;141 Fragment::position_t pos(3, 0.);142 for (double i = 0; i < 5; i+=1.) {143 pos[0] = i;144 positions.push_back(pos);145 }146 147 // create charges148 Fragment::charges_t charges;149 charges += 6., 6., 1., 1., 1.;150 151 {152 // extract carbon pairs153 Fragment::charges_t carbonpair;154 carbonpair += 6.,6.;155 FunctionModel::arguments_t args =156 Extractors::gatherDistancesFromFragment(positions, charges, carbonpair, 0);157 CPPUNIT_ASSERT_EQUAL( (size_t)1, args.size() );158 }159 160 {161 // extract hydrogen triple162 Fragment::charges_t hydrogentriple;163 hydrogentriple += 1.,1.,1.;164 FunctionModel::arguments_t args =165 Extractors::gatherDistancesFromFragment(positions, charges, hydrogentriple, 0);166 CPPUNIT_ASSERT_EQUAL( (size_t)3, args.size() );167 }168 }169 170 /** UnitTest for reorderArgumentsByIncreasingDistance()171 */172 void ExtractorsTest::reorderArgumentsByIncreasingDistanceTest()173 {174 // prepare some arguments175 FunctionModel::arguments_t args;176 argument_t arg;177 arg.distance = 0.1;178 args.push_back(arg);179 arg.distance = 0.9;180 args.push_back(arg);181 arg.distance = 0.3;182 args.push_back(arg);183 CPPUNIT_ASSERT_EQUAL( (size_t)3, args.size() );184 FunctionModel::list_of_arguments_t listargs(1, args);185 186 // reorder187 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());191 CPPUNIT_ASSERT_EQUAL( (size_t)3, args_sorted.size() );192 CPPUNIT_ASSERT_EQUAL( args[0].distance, args_sorted[0].distance );193 CPPUNIT_ASSERT_EQUAL( args[1].distance, args_sorted[2].distance );194 CPPUNIT_ASSERT_EQUAL( args[2].distance, args_sorted[1].distance );195 } -
src/FunctionApproximation/unittests/ExtractorsUnitTest.hpp
r16c6f7 re47ac7 22 22 { 23 23 CPPUNIT_TEST_SUITE( ExtractorsTest) ; 24 CPPUNIT_TEST ( gatherAllDistanceArgumentsTest ); 25 CPPUNIT_TEST ( reorderArgumentsByIncreasingDistanceTest ); 26 CPPUNIT_TEST ( gatherPositionsFromFragmentTest ); 27 CPPUNIT_TEST ( gatherDistancesFromFragmentTest ); 24 CPPUNIT_TEST ( gatherAllSymmetricDistancesTest ); 28 25 CPPUNIT_TEST_SUITE_END(); 29 26 … … 31 28 void setUp(); 32 29 void tearDown(); 33 void gatherAllDistanceArgumentsTest(); 34 void reorderArgumentsByIncreasingDistanceTest(); 35 void gatherPositionsFromFragmentTest(); 36 void gatherDistancesFromFragmentTest(); 30 void gatherAllSymmetricDistancesTest(); 37 31 38 32 private:
Note:
See TracChangeset
for help on using the changeset viewer.