Ignore:
Timestamp:
Nov 4, 2016, 9:37:50 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:
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)
Message:

REFACTOR: Removed many unused functions from Extractor namespace.

  • TESTFIX: Extractor unit test now only checks on getAllSymmetricDistances().
Location:
src/FunctionApproximation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/FunctionApproximation/Extractors.cpp

    r16c6f7 re47ac7  
    5555
    5656using namespace boost::assign;
    57 
    58 FunctionModel::arguments_t
    59 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 distances
    67   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 }
    9457
    9558FunctionModel::arguments_t
     
    13194}
    13295
    133 Fragment::positions_t Extractors::_detail::gatherPositionsFromTargets(
    134     const Fragment::positions_t& positions,
    135     const Fragment::charges_t& charges,
    136     const chargeiters_t &targets
    137     )
    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 globalid
    155     )
    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 
    17396Extractors::elementcounts_t
    17497Extractors::_detail::getElementCounts(
     
    188111  return elementcounts;
    189112}
    190 
    191 Extractors::elementtargets_t
    192 Extractors::_detail::convertElementcountsToTargets(
    193     const Fragment::charges_t &charges,
    194     const elementcounts_t &elementcounts
    195     )
    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 list
    208         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 it
    211         if (!inserter.second) {
    212           inserter.first->second.push_back(tempiter);
    213         } else { // if created, increase vector's reserve to known size
    214           inserter.first->second.reserve(countiter->second);
    215         }
    216         // search from this element onwards then
    217         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_t
    229 Extractors::_detail::convertChargesToTargetMap(
    230     const Fragment::charges_t& charges,
    231     Fragment::charges_t elements
    232     )
    233 {
    234   // place each charge into a map
    235   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 it
    242     if (!inserter.second) {
    243       inserter.first->second.push_back(chargeiter);
    244     }
    245   }
    246   // pick out desired charges only
    247   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_t
    268 Extractors::_detail::realignElementtargets(
    269     const elementtargets_t &elementtargets,
    270     const Fragment::charges_t elements,
    271     const elementcounts_t &elementcounts
    272     )
    273 {
    274   chargeiters_t targets;
    275   elementcounts_t counts; // how many chargeiters of this element have been used
    276   if (!elements.empty()) {  // skip if no elements given
    277     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 0
    282 #ifndef NDEBUG
    283       {
    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 #endif
    290       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_t
    302 Extractors::gatherAllDistancesFromFragment(
    303     const Fragment::positions_t& positions,
    304     const Fragment::charges_t& charges,
    305     const Fragment::charges_t elements,
    306     const size_t globalid
    307     )
    308 {
    309   /// The main problem here is that we have to know how many same
    310   /// elements (but different atoms!) we are required to find. Hence,
    311   /// we first have to count same elements, then get different targets
    312   /// for each and then associated them in correct order back again.
    313 
    314   // 0. if no elements given, we return empty arguments
    315   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. map
    319   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 element
    325   //    in a combinatorial fashion
    326   targets_per_combination_t combinations =
    327       Extractors::_detail::CombineChargesAndTargets(
    328           elements,
    329           elementtargets);
    330 
    331   // 3. finally, convert chargeiters into argument list
    332   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_t
    343 Extractors::_detail::CombineChargesAndTargets(
    344     const Fragment::charges_t& elements,
    345     const elementtargets_t& elementtargets
    346     )
    347 {
    348   // recursively create all correct combinations of targets
    349   targets_per_combination_t combinations;
    350   chargeiters_t currenttargets;
    351   boost::function<void (const chargeiters_t &currenttargets)> 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 &iter
    364     )
    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_t
    374 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 globalid
    379     )
    380 {
    381   FunctionModel::arguments_t args;
    382   // create arguments from each combination. We cannot use
    383   // gatherallSymmetricDistanceArguments() because it would not create the
    384   // 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 void
    417 Extractors::_detail::pickLastElementAsTarget(
    418     Fragment::charges_t elements,
    419     elementtargets_t elementtargets,
    420     chargeiters_t &currenttargets,
    421     boost::function<void (const chargeiters_t &currenttargets)> &addFunction
    422     )
    423 {
    424   // get last element from charges
    425   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 chargeiters
    435     chargeiter_t target = iter->second.back();
    436     iter->second.pop_back();
    437     // remove this key if empty
    438     if (iter->second.empty()) {
    439       elementtargets.erase(iter);
    440       NotEmpty = false;
    441     }
    442     currenttargets.push_back(target);
    443     if (elements.empty()) {
    444       // call add function
    445       {
    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 recursively
    455       pickLastElementAsTarget(elements, elementtargets, currenttargets, addFunction);
    456     }
    457     // pop last in currenset again
    458     currenttargets.pop_back();
    459   }
    460 }
    461 
    462 Extractors::chargeiters_t
    463 Extractors::_detail::gatherTargetsFromFragment(
    464     const Fragment::charges_t& charges,
    465     const Fragment::charges_t elements
    466     )
    467 {
    468   /// The main problem here is that we have to know how many same
    469   /// elements (but different atoms!) we are required to find. Hence,
    470   /// we first have to count same elements, then get different targets
    471   /// 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 map
    474   elementcounts_t elementcounts =
    475       Extractors::_detail::getElementCounts(elements);
    476 
    477   // 2. then for each element we need as many targets (chargeiters) as counts
    478   elementtargets_t elementtargets =
    479       Extractors::_detail::convertElementcountsToTargets(charges, elementcounts);
    480 
    481   // 3. we go again through elements and use one found target for each count
    482   // in that order
    483   chargeiters_t targets =
    484       Extractors::_detail::realignElementtargets(elementtargets, elements, elementcounts);
    485 
    486 #ifndef NDEBUG
    487   // check all for debugging
    488   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 #endif
    494 
    495   return targets;
    496 }
    497 
    498 Fragment::positions_t
    499 Extractors::gatherPositionsFromFragment(
    500     const Fragment::positions_t positions,
    501     const Fragment::charges_t charges,
    502     const Fragment::charges_t& elements
    503     )
    504 {
    505   // 1.-3. gather correct charge positions
    506   chargeiters_t targets =
    507       Extractors::_detail::gatherTargetsFromFragment(charges, elements);
    508   // 4. convert position_t to Vector
    509   return Extractors::_detail::gatherPositionsFromTargets(
    510           positions,
    511           charges,
    512           targets);
    513 }
    514 
    515 FunctionModel::arguments_t
    516 Extractors::gatherDistancesFromFragment(
    517     const Fragment::positions_t positions,
    518     const Fragment::charges_t charges,
    519     const Fragment::charges_t& elements,
    520     const size_t globalid
    521     )
    522 {
    523   // 1.-3. gather correct charge positions
    524   chargeiters_t targets =
    525       Extractors::_detail::gatherTargetsFromFragment(charges, elements);
    526   // 4. convert position_t to Vector
    527   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 &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   }
    546   return returnargs;
    547 }
    548 
    549113
    550114struct ParticleTypesComparator {
  • src/FunctionApproximation/Extractors.hpp

    r16c6f7 re47ac7  
    5252   */
    5353  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 but
    57      * from a different vector that has the same layout.
    58      *
    59      * \param positions all nuclei positions
    60      * \param charges all nuclei charges
    61      * \param targets iterators on charges
    62      * \return filtered distance arguments
    63      */
    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 globalid
    69         );
    70 
    71     /** Gather all positions from the same aligned vector of charges.
    72      *
    73      * Basically, we filter the positions indicated by the targets but
    74      * from a different vector that has the same layout.
    75      *
    76      * \param positions all nuclei positions
    77      * \param charges all nuclei charges
    78      * \param targets iterators on charges
    79      * \return filtered positions
    80      */
    81     Fragment::positions_t gatherPositionsFromTargets(
    82         const Fragment::positions_t& positions,
    83         const Fragment::charges_t& charges,
    84         const chargeiters_t& targets
    85         );
    8654
    8755    /** Counts all same elements in the vector and places into map of elements.
     
    9462        );
    9563
    96     /** Gather iterators to the elements related to the desired elementcounts.
    97      *
    98      * \param charges charges wherein to search for the elements
    99      * \param elementcounts number of desired hits per element
    100      * \return iterators equal to the initial vector of elements
    101      */
    102     elementtargets_t convertElementcountsToTargets(
    103         const Fragment::charges_t &charges,
    104         const elementcounts_t &elementcounts
    105         );
    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 this
    110      * final step.
    111      *
    112      * \param elementtargets targets as they are in the map \a elementcounts
    113      * \param elements the original order of the elements
    114      * \param elementcounts the count per element for debugging checks
    115      * \return vector of targets in the order as they are in \a element
    116      */
    117     chargeiters_t realignElementtargets(
    118         const elementtargets_t &elementtargets,
    119         const Fragment::charges_t elements,
    120         const elementcounts_t &elementcounts
    121         );
    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 and
    126      * elements as 1,8,1 (e.g. for an angle HOH) and we get the
    127      * chargeiters in the desired manner on indices: 1,0,3.
    128      *
    129      * \param charges charges to look through
    130      * \param elements vector of elements to find
    131      */
    132     chargeiters_t
    133     gatherTargetsFromFragment(
    134         const Fragment::charges_t& charges,
    135         const Fragment::charges_t elements
    136         );
    137 
    138     /** Brings all charges together in a map.
    139      *
    140      * @param charges charges as possible keys and their iterators as values in the map
    141      * @param elements list of charges to pick as keys
    142      * @return map of key and a vector of charge iterators
    143      */
    144     elementtargets_t convertChargesToTargetMap(
    145         const Fragment::charges_t& charges,
    146         Fragment::charges_t elements
    147         );
    148 
    149     /** Brings combinatorially together desired list of \a charges and \a targets.
    150      *
    151      * @param charges list of desired charges
    152      * @param elementtargets map of available targets per element
    153      * @return vector of chargeiters with all unique combinations
    154      */
    155     targets_per_combination_t
    156     CombineChargesAndTargets(
    157         const Fragment::charges_t& charges,
    158         const elementtargets_t& elementtargets
    159         );
    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 recursion
    166      * @param elementtargets targets, map of targets to pick from
    167      * @param currenttargets current set of targets, "global" through recursion
    168      * @param addFunction bound function to add a set when complete
    169      */
    170     void pickLastElementAsTarget(
    171         Fragment::charges_t elements,
    172         elementtargets_t elementtargets,
    173         chargeiters_t& currenttargets,
    174         boost::function<void (const chargeiters_t &currenttargets)> &addFunction
    175         );
    176 
    177     /** Converts a list of chargeiters to a list of respective arguments.
    178      *
    179      * @param positions positions from fragment
    180      * @param charges charges associated to each element in \a positions
    181      * @param combinations vector of chargeiters
    182      * \param globalid refers to the index within the global set of configurations
    183      * @return list of arguments
    184      */
    185     FunctionModel::arguments_t
    186     convertTargetsToArguments(
    187         const Fragment::positions_t& positions,
    188         const Fragment::charges_t& charges,
    189         const targets_per_combination_t combinations,
    190         const size_t globalid
    191         );
    19264  }
    193 
    194   /** Gather all distances from a given set of positions.
    195    *
    196    * \param positions all nuclei positions
    197    * \param charges all nuclei charges
    198    * \param globalid index to associated in argument_t with
    199    * \return vector of argument_ , each with a distance
    200    */
    201   FunctionModel::arguments_t
    202   gatherAllDistanceArguments(
    203       const Fragment::positions_t& positions,
    204       const Fragment::charges_t& charges,
    205       const size_t globalid);
    20665
    20766  /** Gather all distances from a given set of positions.
     
    21978      const Fragment::charges_t& charges,
    22079      const size_t globalid);
    221 
    222   /** Simple extractor of all unique pair distances of a given \a fragment.
    223    *
    224    * \param positions all nuclei positions
    225    * \param charges all nuclei charges
    226    * \param index index refers to the index within the global set of configurations
    227    * \return vector of of argument_t containing all found distances
    228    */
    229   inline FunctionModel::arguments_t gatherAllDistances(
    230       const Fragment::positions_t& positions,
    231       const Fragment::charges_t& charges,
    232       const size_t index
    233       ) {
    234     // get distance out of Fragment
    235     return gatherAllDistanceArguments(positions, charges, index);
    236   }
    23780
    23881  /** Simple extractor of all unique pair distances of a given \a fragment, where
     
    25295    return gatherAllSymmetricDistanceArguments(positions, charges, index);
    25396  }
    254 
    255   /** Filters only those positions out of given \a fragment that match \a elements.
    256    *
    257    * \param positions all nuclei positions
    258    * \param charges all nuclei charges
    259    * \param elements tuple of desired elements
    260    * \return vector of positions_t containing
    261    */
    262   Fragment::positions_t gatherPositionsFromFragment(
    263       const Fragment::positions_t positions,
    264       const Fragment::charges_t charges,
    265       const Fragment::charges_t& elements
    266       );
    267 
    268   /** Filters only those distances out of given \a fragment that match \a elements.
    269    *
    270    * \param positions all nuclei positions
    271    * \param charges all nuclei charges
    272    * \param elements tuple of desired elements
    273    * \param globalid refers to the index within the global set of configurations
    274    * \return vector of arguments_t containing those matched with elements
    275    */
    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 globalid
    281       );
    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 be
    289    * returned.
    290    *
    291    * @param positions positions in fragment
    292    * @param charges charges in fragment
    293    * @param elements list of desired elements
    294    * @param globalid some global id to discern training data tuples
    295    * @return list of arguments with distances
    296    */
    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 globalid
    302       );
    303 
    304   /** Reorder arguments by increasing distance.
    305    *
    306    * \param listargs list of arguments to reorder each
    307    * \return reordered args
    308    */
    309   FunctionModel::list_of_arguments_t reorderArgumentsByIncreasingDistance(
    310       const FunctionModel::list_of_arguments_t &listargs
    311       );
    31297
    31398  /** Reorder the arguments to bring adjacent ones together.
  • src/FunctionApproximation/unittests/ExtractorsUnitTest.cpp

    r16c6f7 re47ac7  
    7272}
    7373
    74 /** UnitTest for gatherAllDistanceArguments()
     74/** UnitTest for gatherAllSymmetricDistances()
    7575 */
    76 void ExtractorsTest::gatherAllDistanceArgumentsTest()
     76void ExtractorsTest::gatherAllSymmetricDistancesTest()
    7777{
    7878  // create positions
     
    9090  // create distances
    9191  FunctionModel::arguments_t args =
    92       Extractors::gatherAllDistanceArguments(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() );
    9494
    9595  // check created args
    96   for (size_t i=0; i< 5*4; ++i)
     96  for (size_t i=0; i< (5*4)/2; ++i)
    9797    CPPUNIT_ASSERT( (args[i].distance >= 0) && (args[i].distance <= 4));
    9898}
    99 
    100 /** UnitTest for gatherPositionsFromFragment()
    101  */
    102 void ExtractorsTest::gatherPositionsFromFragmentTest()
    103 {
    104   // create positions
    105   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 charges
    113   Fragment::charges_t charges;
    114   charges += 6., 6., 1., 1., 1.;
    115 
    116   {
    117     // extract carbon pairs
    118     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 triple
    127     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 positions
    140   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 charges
    148   Fragment::charges_t charges;
    149   charges += 6., 6., 1., 1., 1.;
    150 
    151   {
    152     // extract carbon pairs
    153     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 triple
    162     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 arguments
    175   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   // reorder
    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());
    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  
    2222{
    2323    CPPUNIT_TEST_SUITE( ExtractorsTest) ;
    24     CPPUNIT_TEST ( gatherAllDistanceArgumentsTest );
    25     CPPUNIT_TEST ( reorderArgumentsByIncreasingDistanceTest );
    26     CPPUNIT_TEST ( gatherPositionsFromFragmentTest );
    27     CPPUNIT_TEST ( gatherDistancesFromFragmentTest );
     24    CPPUNIT_TEST ( gatherAllSymmetricDistancesTest );
    2825    CPPUNIT_TEST_SUITE_END();
    2926
     
    3128      void setUp();
    3229      void tearDown();
    33       void gatherAllDistanceArgumentsTest();
    34       void reorderArgumentsByIncreasingDistanceTest();
    35       void gatherPositionsFromFragmentTest();
    36       void gatherDistancesFromFragmentTest();
     30      void gatherAllSymmetricDistancesTest();
    3731
    3832private:
Note: See TracChangeset for help on using the changeset viewer.