| 1 | /* | 
|---|
| 2 | * Extractors.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: 15.10.2012 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef TRAININGDATA_EXTRACTORS_HPP_ | 
|---|
| 9 | #define TRAININGDATA_EXTRACTORS_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <boost/function.hpp> | 
|---|
| 17 |  | 
|---|
| 18 | #include "Fragmentation/Summation/SetValues/Fragment.hpp" | 
|---|
| 19 | #include "FunctionApproximation/FunctionModel.hpp" | 
|---|
| 20 |  | 
|---|
| 21 | class Fragment; | 
|---|
| 22 | class HomologyGraph; | 
|---|
| 23 |  | 
|---|
| 24 | /** Namespace containing all simple extractor functions. | 
|---|
| 25 | * | 
|---|
| 26 | * Extractor functions extract distances from a given fragment matching with | 
|---|
| 27 | * a given set of particle types (i.e. elements, e.h. H2O). | 
|---|
| 28 | * Filter functions extract a subset of distances from a given set of distances | 
|---|
| 29 | * to be used with a specific model. | 
|---|
| 30 | * | 
|---|
| 31 | * To this end, each FunctionModel has both a filter and an extractor function. | 
|---|
| 32 | * | 
|---|
| 33 | * The functions in this namespace act as helpers or basic building blocks in | 
|---|
| 34 | * constructing such filters and extractors. | 
|---|
| 35 | * | 
|---|
| 36 | */ | 
|---|
| 37 | namespace Extractors { | 
|---|
| 38 | typedef Fragment::charges_t::const_iterator chargeiter_t; | 
|---|
| 39 | typedef std::vector<chargeiter_t> chargeiters_t; | 
|---|
| 40 |  | 
|---|
| 41 | typedef size_t count_t; | 
|---|
| 42 | typedef Fragment::atomicNumber_t element_t; | 
|---|
| 43 | typedef std::map< element_t, count_t> elementcounts_t; | 
|---|
| 44 | typedef std::map< element_t, chargeiters_t > elementtargets_t; | 
|---|
| 45 | typedef std::vector< chargeiters_t > targets_per_combination_t; | 
|---|
| 46 | //!> typedef for particle designation | 
|---|
| 47 | typedef unsigned int ParticleType_t; | 
|---|
| 48 | //!> typedef for a vector of particle designations | 
|---|
| 49 | typedef std::vector<ParticleType_t> ParticleTypes_t; | 
|---|
| 50 |  | 
|---|
| 51 | /** Namespace for some internal helper functions. | 
|---|
| 52 | * | 
|---|
| 53 | */ | 
|---|
| 54 | namespace _detail { | 
|---|
| 55 |  | 
|---|
| 56 | /** Counts all same elements in the vector and places into map of elements. | 
|---|
| 57 | * | 
|---|
| 58 | * \param elements vector of elements | 
|---|
| 59 | * \return count of same element in vector | 
|---|
| 60 | */ | 
|---|
| 61 | elementcounts_t getElementCounts( | 
|---|
| 62 | const Fragment::atomicnumbers_t elements | 
|---|
| 63 | ); | 
|---|
| 64 |  | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | /** Gather all distances from a given set of positions. | 
|---|
| 68 | * | 
|---|
| 69 | *  Here, we only return one of the two equal distances. | 
|---|
| 70 | * | 
|---|
| 71 | * \param positions all nuclei positions | 
|---|
| 72 | * \param atomicNumber all nuclei atomic numbers | 
|---|
| 73 | * \param globalid index to associated in argument_t with | 
|---|
| 74 | * \return vector of argument_ , each with a distance | 
|---|
| 75 | */ | 
|---|
| 76 | FunctionModel::arguments_t | 
|---|
| 77 | gatherAllSymmetricDistanceArguments( | 
|---|
| 78 | const Fragment::positions_t& positions, | 
|---|
| 79 | const Fragment::atomicnumbers_t& atomicnumbers, | 
|---|
| 80 | const size_t globalid); | 
|---|
| 81 |  | 
|---|
| 82 | /** Simple extractor of all unique pair distances of a given \a fragment, where | 
|---|
| 83 | * the first index is less than the second one. | 
|---|
| 84 | * | 
|---|
| 85 | * \param positions all nuclei positions | 
|---|
| 86 | * \param atomicNumber all nuclei atomic numbers | 
|---|
| 87 | * \param index index refers to the index within the global set of configurations | 
|---|
| 88 | * \return vector of of argument_t containing all found distances | 
|---|
| 89 | */ | 
|---|
| 90 | inline FunctionModel::arguments_t gatherAllSymmetricDistances( | 
|---|
| 91 | const Fragment::positions_t& positions, | 
|---|
| 92 | const Fragment::atomicnumbers_t& atomicnumbers, | 
|---|
| 93 | const size_t index | 
|---|
| 94 | ) { | 
|---|
| 95 | // get distance out of Fragment | 
|---|
| 96 | return gatherAllSymmetricDistanceArguments(positions, atomicnumbers, index); | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | /** Reorder the arguments to bring adjacent ones together. | 
|---|
| 100 | * | 
|---|
| 101 | * After filtering via particle types arguments related via same indices | 
|---|
| 102 | * must not necessarily be contained in the same bunch. This reordering | 
|---|
| 103 | * is done here, preserving the alignment given in | 
|---|
| 104 | * \sa filterArgumentsByParticleTypes() | 
|---|
| 105 | * | 
|---|
| 106 | * \param listargs list of arguments to reorder each | 
|---|
| 107 | * \param _graph contains binding model of graph | 
|---|
| 108 | * \param _types particle type vector | 
|---|
| 109 | * \return reordered args | 
|---|
| 110 | */ | 
|---|
| 111 | FunctionModel::list_of_arguments_t reorderArgumentsByParticleTypes( | 
|---|
| 112 | const FunctionModel::list_of_arguments_t &eachargs, | 
|---|
| 113 | const HomologyGraph &_graph, | 
|---|
| 114 | const ParticleTypes_t &_types, | 
|---|
| 115 | const HomologyGraph &_bindingmodel | 
|---|
| 116 | ); | 
|---|
| 117 |  | 
|---|
| 118 | /** Filter arguments according to types, allowing multiples. | 
|---|
| 119 | * | 
|---|
| 120 | * If particle types is (0,1,2) and three arguments, each with a pair of types, | 
|---|
| 121 | * are given, then the alignment will be: (0,1), (0,2), and (1,2). | 
|---|
| 122 | * | 
|---|
| 123 | * \param args arguments to reorder | 
|---|
| 124 | * \param _graph contains binding model of graph | 
|---|
| 125 | * \param _types particle type vector | 
|---|
| 126 | * \return filtered list of args | 
|---|
| 127 | */ | 
|---|
| 128 | FunctionModel::list_of_arguments_t filterArgumentsByParticleTypes( | 
|---|
| 129 | const FunctionModel::arguments_t &args, | 
|---|
| 130 | const HomologyGraph &_graph, | 
|---|
| 131 | const ParticleTypes_t &_types, | 
|---|
| 132 | const HomologyGraph &_bindingmodel | 
|---|
| 133 | ); | 
|---|
| 134 |  | 
|---|
| 135 | /** Combines two argument lists by sorting and making unique. | 
|---|
| 136 | * | 
|---|
| 137 | * @param firstargs first list of arguments | 
|---|
| 138 | * @param secondargs second list of arguments | 
|---|
| 139 | * @return concatenated lists | 
|---|
| 140 | */ | 
|---|
| 141 | FunctionModel::arguments_t combineArguments( | 
|---|
| 142 | const FunctionModel::arguments_t &firstargs, | 
|---|
| 143 | const FunctionModel::arguments_t &secondargs); | 
|---|
| 144 |  | 
|---|
| 145 | /** Combines two argument lists by concatenation. | 
|---|
| 146 | * | 
|---|
| 147 | * @param firstargs first list of arguments | 
|---|
| 148 | * @param secondargs second list of arguments | 
|---|
| 149 | * @return concatenated lists | 
|---|
| 150 | */ | 
|---|
| 151 | FunctionModel::arguments_t concatenateArguments( | 
|---|
| 152 | const FunctionModel::arguments_t &firstargs, | 
|---|
| 153 | const FunctionModel::arguments_t &secondargs); | 
|---|
| 154 |  | 
|---|
| 155 | /** Combines two argument lists by concatenation. | 
|---|
| 156 | * | 
|---|
| 157 | * @param firstlistargs first list of argument tuples | 
|---|
| 158 | * @param secondlistargs second list of argument tuples | 
|---|
| 159 | * @return concatenated lists | 
|---|
| 160 | */ | 
|---|
| 161 | FunctionModel::list_of_arguments_t concatenateListOfArguments( | 
|---|
| 162 | const FunctionModel::list_of_arguments_t &firstlistargs, | 
|---|
| 163 | const FunctionModel::list_of_arguments_t &secondlistargs); | 
|---|
| 164 |  | 
|---|
| 165 | }; /* namespace Extractors */ | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|
| 168 | #endif /* TRAININGDATA_EXTRACTORS_HPP_ */ | 
|---|