| [8aa597] | 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 | 
 | 
|---|
| [caa00e9] | 16 | #include <boost/function.hpp>
 | 
|---|
 | 17 | 
 | 
|---|
| [fbf143] | 18 | #include "Fragmentation/Summation/SetValues/Fragment.hpp"
 | 
|---|
| [8aa597] | 19 | #include "FunctionApproximation/FunctionModel.hpp"
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | class Fragment;
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | /** Namespace containing all simple extractor functions.
 | 
|---|
 | 24 |  *
 | 
|---|
 | 25 |  */
 | 
|---|
 | 26 | namespace Extractors {
 | 
|---|
| [301dbf] | 27 |   typedef Fragment::charges_t::const_iterator chargeiter_t;
 | 
|---|
 | 28 |   typedef std::vector<chargeiter_t> chargeiters_t;
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 |   typedef size_t count_t;
 | 
|---|
 | 31 |   typedef Fragment::charge_t element_t;
 | 
|---|
 | 32 |   typedef std::map< element_t, count_t> elementcounts_t;
 | 
|---|
 | 33 |   typedef std::map< element_t, chargeiters_t > elementtargets_t;
 | 
|---|
| [caa00e9] | 34 |   typedef std::vector< chargeiters_t > targets_per_combination_t;
 | 
|---|
| [df350c] | 35 |   //!> typedef for particle designation
 | 
|---|
 | 36 |   typedef int ParticleType_t;
 | 
|---|
 | 37 |   //!> typedef for a vector of particle designations
 | 
|---|
 | 38 |   typedef std::vector<ParticleType_t> ParticleTypes_t;
 | 
|---|
| [301dbf] | 39 | 
 | 
|---|
| [8aa597] | 40 |   /** Namespace for some internal helper functions.
 | 
|---|
 | 41 |    *
 | 
|---|
 | 42 |    */
 | 
|---|
 | 43 |   namespace _detail {
 | 
|---|
| [691be4] | 44 |     /** Gather all distance arguments from the same aligned vector of charges.
 | 
|---|
 | 45 |      *
 | 
|---|
 | 46 |      * Basically, we filter the positions indicated by the targets but
 | 
|---|
 | 47 |      * from a different vector that has the same layout.
 | 
|---|
 | 48 |      *
 | 
|---|
 | 49 |      * \param positions all nuclei positions
 | 
|---|
 | 50 |      * \param charges all nuclei charges
 | 
|---|
 | 51 |      * \param targets iterators on charges
 | 
|---|
 | 52 |      * \return filtered distance arguments
 | 
|---|
 | 53 |      */
 | 
|---|
 | 54 |     FunctionModel::arguments_t gatherDistancesFromTargets(
 | 
|---|
 | 55 |         const Fragment::positions_t& positions,
 | 
|---|
 | 56 |         const Fragment::charges_t& charges,
 | 
|---|
 | 57 |         const chargeiters_t &targets,
 | 
|---|
 | 58 |         const size_t globalid
 | 
|---|
 | 59 |         );
 | 
|---|
 | 60 | 
 | 
|---|
| [301dbf] | 61 |     /** Gather all positions from the same aligned vector of charges.
 | 
|---|
 | 62 |      *
 | 
|---|
 | 63 |      * Basically, we filter the positions indicated by the targets but
 | 
|---|
 | 64 |      * from a different vector that has the same layout.
 | 
|---|
 | 65 |      *
 | 
|---|
| [691be4] | 66 |      * \param positions all nuclei positions
 | 
|---|
 | 67 |      * \param charges all nuclei charges
 | 
|---|
| [301dbf] | 68 |      * \param targets iterators on charges
 | 
|---|
 | 69 |      * \return filtered positions
 | 
|---|
 | 70 |      */
 | 
|---|
| [691be4] | 71 |     Fragment::positions_t gatherPositionsFromTargets(
 | 
|---|
 | 72 |         const Fragment::positions_t& positions,
 | 
|---|
 | 73 |         const Fragment::charges_t& charges,
 | 
|---|
 | 74 |         const chargeiters_t& targets
 | 
|---|
| [301dbf] | 75 |         );
 | 
|---|
| [bc6705] | 76 | 
 | 
|---|
 | 77 |     /** Counts all same elements in the vector and places into map of elements.
 | 
|---|
 | 78 |      *
 | 
|---|
 | 79 |      * \param elements vector of elements
 | 
|---|
 | 80 |      * \return count of same element in vector
 | 
|---|
 | 81 |      */
 | 
|---|
 | 82 |     elementcounts_t getElementCounts(
 | 
|---|
 | 83 |         const Fragment::charges_t elements
 | 
|---|
 | 84 |         );
 | 
|---|
 | 85 | 
 | 
|---|
| [c211f7] | 86 |     /** Gather iterators to the elements related to the desired elementcounts.
 | 
|---|
 | 87 |      *
 | 
|---|
 | 88 |      * \param charges charges wherein to search for the elements
 | 
|---|
 | 89 |      * \param elementcounts number of desired hits per element
 | 
|---|
 | 90 |      * \return iterators equal to the initial vector of elements
 | 
|---|
 | 91 |      */
 | 
|---|
 | 92 |     elementtargets_t convertElementcountsToTargets(
 | 
|---|
 | 93 |         const Fragment::charges_t &charges,
 | 
|---|
 | 94 |         const elementcounts_t &elementcounts
 | 
|---|
 | 95 |         );
 | 
|---|
| [63e786] | 96 | 
 | 
|---|
 | 97 |     /** Convert the alignment back to as it was in the original vector.
 | 
|---|
 | 98 |      *
 | 
|---|
 | 99 |      * We lost the information by storing it in a map. Hence, we need this
 | 
|---|
 | 100 |      * final step.
 | 
|---|
 | 101 |      *
 | 
|---|
 | 102 |      * \param elementtargets targets as they are in the map \a elementcounts
 | 
|---|
 | 103 |      * \param elements the original order of the elements
 | 
|---|
 | 104 |      * \param elementcounts the count per element for debugging checks
 | 
|---|
 | 105 |      * \return vector of targets in the order as they are in \a element
 | 
|---|
 | 106 |      */
 | 
|---|
 | 107 |     chargeiters_t realignElementtargets(
 | 
|---|
 | 108 |         const elementtargets_t &elementtargets,
 | 
|---|
 | 109 |         const Fragment::charges_t elements,
 | 
|---|
 | 110 |         const elementcounts_t &elementcounts
 | 
|---|
 | 111 |         );
 | 
|---|
| [691be4] | 112 | 
 | 
|---|
 | 113 |     /** Searches for desired elements in charges in a unique manner.
 | 
|---|
 | 114 |      *
 | 
|---|
 | 115 |      * The idea is to have e.g. a fragment with charges 8,1,1,2 and
 | 
|---|
 | 116 |      * elements as 1,8,1 (e.g. for an angle HOH) and we get the
 | 
|---|
 | 117 |      * chargeiters in the desired manner on indices: 1,0,3.
 | 
|---|
 | 118 |      *
 | 
|---|
 | 119 |      * \param charges charges to look through
 | 
|---|
 | 120 |      * \param elements vector of elements to find
 | 
|---|
 | 121 |      */
 | 
|---|
 | 122 |     chargeiters_t
 | 
|---|
 | 123 |     gatherTargetsFromFragment(
 | 
|---|
 | 124 |         const Fragment::charges_t& charges,
 | 
|---|
 | 125 |         const Fragment::charges_t elements
 | 
|---|
 | 126 |         );
 | 
|---|
| [caa00e9] | 127 | 
 | 
|---|
 | 128 |     /** Brings all charges together in a map.
 | 
|---|
 | 129 |      *
 | 
|---|
 | 130 |      * @param charges charges as possible keys and their iterators as values in the map
 | 
|---|
 | 131 |      * @param elements list of charges to pick as keys
 | 
|---|
 | 132 |      * @return map of key and a vector of charge iterators
 | 
|---|
 | 133 |      */
 | 
|---|
 | 134 |     elementtargets_t convertChargesToTargetMap(
 | 
|---|
 | 135 |         const Fragment::charges_t& charges,
 | 
|---|
 | 136 |         Fragment::charges_t elements
 | 
|---|
 | 137 |         );
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 |     /** Brings combinatorially together desired list of \a charges and \a targets.
 | 
|---|
 | 140 |      *
 | 
|---|
 | 141 |      * @param charges list of desired charges
 | 
|---|
 | 142 |      * @param elementtargets map of available targets per element
 | 
|---|
 | 143 |      * @return vector of chargeiters with all unique combinations
 | 
|---|
 | 144 |      */
 | 
|---|
 | 145 |     targets_per_combination_t
 | 
|---|
 | 146 |     CombineChargesAndTargets(
 | 
|---|
 | 147 |         const Fragment::charges_t& charges,
 | 
|---|
 | 148 |         const elementtargets_t& elementtargets
 | 
|---|
 | 149 |         );
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 |     /** Recursive function to pick the next target.
 | 
|---|
 | 152 |      *
 | 
|---|
 | 153 |      * This is used by \sa CombineChargesAndTargets()
 | 
|---|
 | 154 |      *
 | 
|---|
 | 155 |      * @param charges set of charges, reduced by one per recursion
 | 
|---|
 | 156 |      * @param elementtargets targets, map of targets to pick from
 | 
|---|
 | 157 |      * @param currenttargets current set of targets, "global" through recursion
 | 
|---|
 | 158 |      * @param addFunction bound function to add a set when complete
 | 
|---|
 | 159 |      */
 | 
|---|
 | 160 |     void pickLastElementAsTarget(
 | 
|---|
 | 161 |         Fragment::charges_t elements,
 | 
|---|
 | 162 |         elementtargets_t elementtargets,
 | 
|---|
 | 163 |         chargeiters_t& currenttargets,
 | 
|---|
 | 164 |         boost::function<void (const chargeiters_t ¤ttargets)> &addFunction
 | 
|---|
 | 165 |         );
 | 
|---|
 | 166 | 
 | 
|---|
 | 167 |     /** Converts a list of chargeiters to a list of respective arguments.
 | 
|---|
 | 168 |      *
 | 
|---|
 | 169 |      * @param positions positions from fragment
 | 
|---|
 | 170 |      * @param charges charges associated to each element in \a positions
 | 
|---|
 | 171 |      * @param combinations vector of chargeiters
 | 
|---|
 | 172 |      * \param globalid refers to the index within the global set of configurations
 | 
|---|
 | 173 |      * @return list of arguments
 | 
|---|
 | 174 |      */
 | 
|---|
 | 175 |     FunctionModel::arguments_t
 | 
|---|
 | 176 |     convertTargetsToArguments(
 | 
|---|
 | 177 |         const Fragment::positions_t& positions,
 | 
|---|
 | 178 |         const Fragment::charges_t& charges,
 | 
|---|
 | 179 |         const targets_per_combination_t combinations,
 | 
|---|
 | 180 |         const size_t globalid
 | 
|---|
 | 181 |         );
 | 
|---|
| [8aa597] | 182 |   }
 | 
|---|
 | 183 | 
 | 
|---|
| [49f163] | 184 |   /** Gather all distances from a given set of positions.
 | 
|---|
 | 185 |    *
 | 
|---|
| [691be4] | 186 |    * \param positions all nuclei positions
 | 
|---|
 | 187 |    * \param charges all nuclei charges
 | 
|---|
| [49f163] | 188 |    * \param globalid index to associated in argument_t with
 | 
|---|
 | 189 |    * \return vector of argument_ , each with a distance
 | 
|---|
 | 190 |    */
 | 
|---|
 | 191 |   FunctionModel::arguments_t
 | 
|---|
 | 192 |   gatherAllDistanceArguments(
 | 
|---|
| [691be4] | 193 |       const Fragment::positions_t& positions,
 | 
|---|
 | 194 |       const Fragment::charges_t& charges,
 | 
|---|
| [49f163] | 195 |       const size_t globalid);
 | 
|---|
 | 196 | 
 | 
|---|
 | 197 |   /** Gather all distances from a given set of positions.
 | 
|---|
 | 198 |    *
 | 
|---|
 | 199 |    *  Here, we only return one of the two equal distances.
 | 
|---|
 | 200 |    *
 | 
|---|
| [691be4] | 201 |    * \param positions all nuclei positions
 | 
|---|
 | 202 |    * \param charges all nuclei charges
 | 
|---|
| [49f163] | 203 |    * \param globalid index to associated in argument_t with
 | 
|---|
 | 204 |    * \return vector of argument_ , each with a distance
 | 
|---|
 | 205 |    */
 | 
|---|
 | 206 |   FunctionModel::arguments_t
 | 
|---|
 | 207 |   gatherAllSymmetricDistanceArguments(
 | 
|---|
| [691be4] | 208 |       const Fragment::positions_t& positions,
 | 
|---|
 | 209 |       const Fragment::charges_t& charges,
 | 
|---|
| [49f163] | 210 |       const size_t globalid);
 | 
|---|
 | 211 | 
 | 
|---|
| [8aa597] | 212 |   /** Simple extractor of all unique pair distances of a given \a fragment.
 | 
|---|
 | 213 |    *
 | 
|---|
| [691be4] | 214 |    * \param positions all nuclei positions
 | 
|---|
 | 215 |    * \param charges all nuclei charges
 | 
|---|
| [8aa597] | 216 |    * \param index index refers to the index within the global set of configurations
 | 
|---|
 | 217 |    * \return vector of of argument_t containing all found distances
 | 
|---|
 | 218 |    */
 | 
|---|
 | 219 |   inline FunctionModel::arguments_t gatherAllDistances(
 | 
|---|
| [691be4] | 220 |       const Fragment::positions_t& positions,
 | 
|---|
 | 221 |       const Fragment::charges_t& charges,
 | 
|---|
| [8aa597] | 222 |       const size_t index
 | 
|---|
 | 223 |       ) {
 | 
|---|
 | 224 |     // get distance out of Fragment
 | 
|---|
| [691be4] | 225 |     return gatherAllDistanceArguments(positions, charges, index);
 | 
|---|
| [8aa597] | 226 |   }
 | 
|---|
 | 227 | 
 | 
|---|
| [691be4] | 228 |   /** Simple extractor of all unique pair distances of a given \a fragment, where
 | 
|---|
 | 229 |    * the first index is less than the second one.
 | 
|---|
| [8aa597] | 230 |    *
 | 
|---|
| [691be4] | 231 |    * \param positions all nuclei positions
 | 
|---|
 | 232 |    * \param charges all nuclei charges
 | 
|---|
 | 233 |    * \param index index refers to the index within the global set of configurations
 | 
|---|
 | 234 |    * \return vector of of argument_t containing all found distances
 | 
|---|
 | 235 |    */
 | 
|---|
 | 236 |   inline FunctionModel::arguments_t gatherAllSymmetricDistances(
 | 
|---|
 | 237 |       const Fragment::positions_t& positions,
 | 
|---|
 | 238 |       const Fragment::charges_t& charges,
 | 
|---|
 | 239 |       const size_t index
 | 
|---|
 | 240 |       ) {
 | 
|---|
 | 241 |     // get distance out of Fragment
 | 
|---|
 | 242 |     return gatherAllSymmetricDistanceArguments(positions, charges, index);
 | 
|---|
 | 243 |   }
 | 
|---|
 | 244 | 
 | 
|---|
 | 245 |   /** Filters only those positions out of given \a fragment that match \a elements.
 | 
|---|
 | 246 |    *
 | 
|---|
 | 247 |    * \param positions all nuclei positions
 | 
|---|
 | 248 |    * \param charges all nuclei charges
 | 
|---|
| [301dbf] | 249 |    * \param elements tuple of desired elements
 | 
|---|
 | 250 |    * \return vector of positions_t containing
 | 
|---|
| [8aa597] | 251 |    */
 | 
|---|
| [691be4] | 252 |   Fragment::positions_t gatherPositionsFromFragment(
 | 
|---|
 | 253 |       const Fragment::positions_t positions,
 | 
|---|
 | 254 |       const Fragment::charges_t charges,
 | 
|---|
 | 255 |       const Fragment::charges_t& elements
 | 
|---|
 | 256 |       );
 | 
|---|
 | 257 | 
 | 
|---|
 | 258 |   /** Filters only those distances out of given \a fragment that match \a elements.
 | 
|---|
 | 259 |    *
 | 
|---|
 | 260 |    * \param positions all nuclei positions
 | 
|---|
 | 261 |    * \param charges all nuclei charges
 | 
|---|
 | 262 |    * \param elements tuple of desired elements
 | 
|---|
| [caa00e9] | 263 |    * \param globalid refers to the index within the global set of configurations
 | 
|---|
| [691be4] | 264 |    * \return vector of arguments_t containing those matched with elements
 | 
|---|
 | 265 |    */
 | 
|---|
 | 266 |   FunctionModel::arguments_t gatherDistancesFromFragment(
 | 
|---|
 | 267 |       const Fragment::positions_t positions,
 | 
|---|
 | 268 |       const Fragment::charges_t charges,
 | 
|---|
 | 269 |       const Fragment::charges_t& elements,
 | 
|---|
 | 270 |       const size_t globalid
 | 
|---|
| [301dbf] | 271 |       );
 | 
|---|
 | 272 | 
 | 
|---|
| [caa00e9] | 273 |   /** Gather all combinations of charges as distance arguments from the fragment.
 | 
|---|
 | 274 |    *
 | 
|---|
 | 275 |    * E.g. we have a water fragment, i.e. (8,1,1) and we we want elements (8,1),
 | 
|---|
 | 276 |    * then two arguments are returned, first to second and first to third.
 | 
|---|
 | 277 |    *
 | 
|---|
 | 278 |    * With \sa gatherDistancesFromFragment() only the first distance would be
 | 
|---|
 | 279 |    * returned.
 | 
|---|
 | 280 |    *
 | 
|---|
 | 281 |    * @param positions positions in fragment
 | 
|---|
 | 282 |    * @param charges charges in fragment
 | 
|---|
 | 283 |    * @param elements list of desired elements
 | 
|---|
 | 284 |    * @param globalid some global id to discern training data tuples
 | 
|---|
 | 285 |    * @return list of arguments with distances
 | 
|---|
 | 286 |    */
 | 
|---|
 | 287 |   FunctionModel::arguments_t gatherAllDistancesFromFragment(
 | 
|---|
 | 288 |       const Fragment::positions_t& positions,
 | 
|---|
 | 289 |       const Fragment::charges_t& charges,
 | 
|---|
 | 290 |       const Fragment::charges_t elements,
 | 
|---|
 | 291 |       const size_t globalid
 | 
|---|
 | 292 |       );
 | 
|---|
 | 293 | 
 | 
|---|
| [301dbf] | 294 |   /** Reorder arguments by increasing distance.
 | 
|---|
 | 295 |    *
 | 
|---|
 | 296 |    * \param args arguments to reorder
 | 
|---|
 | 297 |    * \return reordered args
 | 
|---|
 | 298 |    */
 | 
|---|
 | 299 |   FunctionModel::arguments_t reorderArgumentsByIncreasingDistance(
 | 
|---|
 | 300 |       const FunctionModel::arguments_t &args
 | 
|---|
| [8aa597] | 301 |       );
 | 
|---|
 | 302 | 
 | 
|---|
| [df350c] | 303 |   /** Reorder arguments according to types.
 | 
|---|
 | 304 |    *
 | 
|---|
 | 305 |    * If particle types is (0,1,2) and three argumens, each with a pair of types,
 | 
|---|
 | 306 |    * are given, then the alignment will be: (0,1), (0,2), and (1,2).
 | 
|---|
 | 307 |    *
 | 
|---|
 | 308 |    * \param args arguments to reorder
 | 
|---|
 | 309 |    * \param _types particle type vector
 | 
|---|
 | 310 |    * \return reordered args
 | 
|---|
 | 311 |    */
 | 
|---|
 | 312 |   FunctionModel::arguments_t reorderArgumentsByParticleTypes(
 | 
|---|
 | 313 |       const FunctionModel::arguments_t &args,
 | 
|---|
 | 314 |       const ParticleTypes_t &_types
 | 
|---|
 | 315 |       );
 | 
|---|
| [9897ee9] | 316 | 
 | 
|---|
| [cf4905] | 317 |   /** Combines two argument lists by sorting and making unique.
 | 
|---|
| [9897ee9] | 318 |    *
 | 
|---|
 | 319 |    * @param firstargs first list of arguments
 | 
|---|
 | 320 |    * @param secondargs second list of arguments
 | 
|---|
 | 321 |    * @return concatenated lists
 | 
|---|
 | 322 |    */
 | 
|---|
 | 323 |   FunctionModel::arguments_t combineArguments(
 | 
|---|
 | 324 |       const FunctionModel::arguments_t &firstargs,
 | 
|---|
 | 325 |       const FunctionModel::arguments_t &secondargs);
 | 
|---|
 | 326 | 
 | 
|---|
| [cf4905] | 327 |   /** Combines two argument lists by concatenation.
 | 
|---|
 | 328 |    *
 | 
|---|
 | 329 |    * @param firstargs first list of arguments
 | 
|---|
 | 330 |    * @param secondargs second list of arguments
 | 
|---|
 | 331 |    * @return concatenated lists
 | 
|---|
 | 332 |    */
 | 
|---|
 | 333 |   FunctionModel::arguments_t concatenateArguments(
 | 
|---|
 | 334 |       const FunctionModel::arguments_t &firstargs,
 | 
|---|
 | 335 |       const FunctionModel::arguments_t &secondargs);
 | 
|---|
 | 336 | 
 | 
|---|
| [8aa597] | 337 | }; /* namespace Extractors */
 | 
|---|
 | 338 | 
 | 
|---|
 | 339 | 
 | 
|---|
 | 340 | #endif /* TRAININGDATA_EXTRACTORS_HPP_ */
 | 
|---|