| 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/EdgesPerFragment.hpp"
 | 
|---|
| 19 | #include "Fragmentation/Summation/SetValues/Fragment.hpp"
 | 
|---|
| 20 | #include "FunctionApproximation/FunctionModel.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | class BindingModel;
 | 
|---|
| 23 | class Fragment;
 | 
|---|
| 24 | class HomologyGraph;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | /** Namespace containing all simple extractor functions.
 | 
|---|
| 27 |  *
 | 
|---|
| 28 |  * Extractor functions extract distances from a given fragment matching with
 | 
|---|
| 29 |  * a given set of particle types (i.e. elements, e.h. H2O).
 | 
|---|
| 30 |  * Filter functions extract a subset of distances from a given set of distances
 | 
|---|
| 31 |  * to be used with a specific model.
 | 
|---|
| 32 |  *
 | 
|---|
| 33 |  * To this end, each FunctionModel has both a filter and an extractor function.
 | 
|---|
| 34 |  *
 | 
|---|
| 35 |  * The functions in this namespace act as helpers or basic building blocks in
 | 
|---|
| 36 |  * constructing such filters and extractors.
 | 
|---|
| 37 |  *
 | 
|---|
| 38 |  */
 | 
|---|
| 39 | namespace Extractors {
 | 
|---|
| 40 |   typedef Fragment::charges_t::const_iterator chargeiter_t;
 | 
|---|
| 41 |   typedef std::vector<chargeiter_t> chargeiters_t;
 | 
|---|
| 42 | 
 | 
|---|
| 43 |   typedef size_t count_t;
 | 
|---|
| 44 |   typedef Fragment::atomicNumber_t element_t;
 | 
|---|
| 45 |   typedef std::map< element_t, count_t> elementcounts_t;
 | 
|---|
| 46 |   typedef std::map< element_t, chargeiters_t > elementtargets_t;
 | 
|---|
| 47 |   typedef std::vector< chargeiters_t > targets_per_combination_t;
 | 
|---|
| 48 |   //!> typedef for particle designation
 | 
|---|
| 49 |   typedef unsigned int ParticleType_t;
 | 
|---|
| 50 |   //!> typedef for a vector of particle designations
 | 
|---|
| 51 |   typedef std::vector<ParticleType_t> ParticleTypes_t;
 | 
|---|
| 52 | 
 | 
|---|
| 53 |   /** Namespace for some internal helper functions.
 | 
|---|
| 54 |    *
 | 
|---|
| 55 |    */
 | 
|---|
| 56 |   namespace _detail {
 | 
|---|
| 57 | 
 | 
|---|
| 58 |     /** Counts all same elements in the vector and places into map of elements.
 | 
|---|
| 59 |      *
 | 
|---|
| 60 |      * \param elements vector of elements
 | 
|---|
| 61 |      * \return count of same element in vector
 | 
|---|
| 62 |      */
 | 
|---|
| 63 |     elementcounts_t getElementCounts(
 | 
|---|
| 64 |         const Fragment::atomicnumbers_t elements
 | 
|---|
| 65 |         );
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   }
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   /** Gather all distances from a given set of positions.
 | 
|---|
| 70 |    *
 | 
|---|
| 71 |    *  Here, we only return one of the two equal distances.
 | 
|---|
| 72 |    *
 | 
|---|
| 73 |    * \param positions all nuclei positions
 | 
|---|
| 74 |    * \param atomicNumber all nuclei atomic numbers
 | 
|---|
| 75 |    * \param edges edges of the fragment's bond graph
 | 
|---|
| 76 |    * \param globalid index to associated in argument_t with
 | 
|---|
| 77 |    * \return vector of argument_ , each with a distance
 | 
|---|
| 78 |    */
 | 
|---|
| 79 |   FunctionModel::arguments_t
 | 
|---|
| 80 |   gatherAllSymmetricDistanceArguments(
 | 
|---|
| 81 |       const Fragment::positions_t& positions,
 | 
|---|
| 82 |       const Fragment::atomicnumbers_t& atomicnumbers,
 | 
|---|
| 83 |       const FragmentationEdges::edges_t &edges,
 | 
|---|
| 84 |       const size_t globalid);
 | 
|---|
| 85 | 
 | 
|---|
| 86 |   /** Simple extractor of all unique pair distances of a given \a fragment, where
 | 
|---|
| 87 |    * the first index is less than the second one.
 | 
|---|
| 88 |    *
 | 
|---|
| 89 |    * \param positions all nuclei positions
 | 
|---|
| 90 |    * \param atomicNumber all nuclei atomic numbers
 | 
|---|
| 91 |    * \param edges edges of the fragment's bond graph
 | 
|---|
| 92 |    * \param index index refers to the index within the global set of configurations
 | 
|---|
| 93 |    * \return vector of of argument_t containing all found distances
 | 
|---|
| 94 |    */
 | 
|---|
| 95 |   inline FunctionModel::arguments_t gatherAllSymmetricDistances(
 | 
|---|
| 96 |       const Fragment::positions_t& positions,
 | 
|---|
| 97 |       const Fragment::atomicnumbers_t& atomicnumbers,
 | 
|---|
| 98 |       const FragmentationEdges::edges_t &edges,
 | 
|---|
| 99 |       const size_t index
 | 
|---|
| 100 |       ) {
 | 
|---|
| 101 |     // get distance out of Fragment
 | 
|---|
| 102 |     return gatherAllSymmetricDistanceArguments(positions, atomicnumbers, edges, index);
 | 
|---|
| 103 |   }
 | 
|---|
| 104 | 
 | 
|---|
| 105 |   /** Filter the arguments to select only these required by the model.
 | 
|---|
| 106 |    *
 | 
|---|
| 107 |    * \warning this is meant as a faster way of getting the arguments for simple
 | 
|---|
| 108 |    * pair potentials. In any other case, one should use filterArgumentsByBindingModel()
 | 
|---|
| 109 |    *
 | 
|---|
| 110 |    * \param listargs list of arguments to reorder each
 | 
|---|
| 111 |    * \param _graph contains binding model of graph
 | 
|---|
| 112 |    * \param _types particle type vector
 | 
|---|
| 113 |    * \return reordered args
 | 
|---|
| 114 |    */
 | 
|---|
| 115 |   FunctionModel::list_of_arguments_t filterArgumentsByParticleTypes(
 | 
|---|
| 116 |       const FunctionModel::arguments_t &args,
 | 
|---|
| 117 |       const HomologyGraph &_graph,
 | 
|---|
| 118 |       const ParticleTypes_t &_types,
 | 
|---|
| 119 |       const BindingModel &_bindingmodel
 | 
|---|
| 120 |       );
 | 
|---|
| 121 | 
 | 
|---|
| 122 |   /** Filter and reorder the arguments to bring adjacent ones together.
 | 
|---|
| 123 |    *
 | 
|---|
| 124 |    * We need to find all matching subgraphs (given by \a _bindingmodel) in the
 | 
|---|
| 125 |    * given homology graph (given by \a _graph) of the fragment molecule.
 | 
|---|
| 126 |    * This means filtering down to the desired particle types and then find
 | 
|---|
| 127 |    * all possible matching subgraphs in each of argument lists, \a eachargs.
 | 
|---|
| 128 |    *
 | 
|---|
| 129 |    * \param listargs list of arguments to filter and order appropriately
 | 
|---|
| 130 |    * \param _graph contains binding model of graph
 | 
|---|
| 131 |    * \param _types particle type vector
 | 
|---|
| 132 |    * \return reordered args
 | 
|---|
| 133 |    */
 | 
|---|
| 134 |   FunctionModel::list_of_arguments_t filterArgumentsByBindingModel(
 | 
|---|
| 135 |       const FunctionModel::arguments_t &args,
 | 
|---|
| 136 |       const HomologyGraph &_graph,
 | 
|---|
| 137 |       const ParticleTypes_t &_types,
 | 
|---|
| 138 |       const BindingModel &_bindingmodel
 | 
|---|
| 139 |       );
 | 
|---|
| 140 | 
 | 
|---|
| 141 |   /** Combines two argument lists by sorting and making unique.
 | 
|---|
| 142 |    *
 | 
|---|
| 143 |    * @param firstargs first list of arguments
 | 
|---|
| 144 |    * @param secondargs second list of arguments
 | 
|---|
| 145 |    * @return concatenated lists
 | 
|---|
| 146 |    */
 | 
|---|
| 147 |   FunctionModel::arguments_t combineArguments(
 | 
|---|
| 148 |       const FunctionModel::arguments_t &firstargs,
 | 
|---|
| 149 |       const FunctionModel::arguments_t &secondargs);
 | 
|---|
| 150 | 
 | 
|---|
| 151 |   /** Combines two argument lists by concatenation.
 | 
|---|
| 152 |    *
 | 
|---|
| 153 |    * @param firstargs first list of arguments
 | 
|---|
| 154 |    * @param secondargs second list of arguments
 | 
|---|
| 155 |    * @return concatenated lists
 | 
|---|
| 156 |    */
 | 
|---|
| 157 |   FunctionModel::arguments_t concatenateArguments(
 | 
|---|
| 158 |       const FunctionModel::arguments_t &firstargs,
 | 
|---|
| 159 |       const FunctionModel::arguments_t &secondargs);
 | 
|---|
| 160 | 
 | 
|---|
| 161 |   /** Combines two argument lists by concatenation.
 | 
|---|
| 162 |    *
 | 
|---|
| 163 |    * @param firstlistargs first list of argument tuples
 | 
|---|
| 164 |    * @param secondlistargs second list of argument tuples
 | 
|---|
| 165 |    * @return concatenated lists
 | 
|---|
| 166 |    */
 | 
|---|
| 167 |   FunctionModel::list_of_arguments_t concatenateListOfArguments(
 | 
|---|
| 168 |       const FunctionModel::list_of_arguments_t &firstlistargs,
 | 
|---|
| 169 |       const FunctionModel::list_of_arguments_t &secondlistargs);
 | 
|---|
| 170 | 
 | 
|---|
| 171 | }; /* namespace Extractors */
 | 
|---|
| 172 | 
 | 
|---|
| 173 | 
 | 
|---|
| 174 | #endif /* TRAININGDATA_EXTRACTORS_HPP_ */
 | 
|---|