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