[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 |
|
---|
[228340] | 18 | #include "Fragmentation/EdgesPerFragment.hpp"
|
---|
[fbf143] | 19 | #include "Fragmentation/Summation/SetValues/Fragment.hpp"
|
---|
[8aa597] | 20 | #include "FunctionApproximation/FunctionModel.hpp"
|
---|
| 21 |
|
---|
[9c793c] | 22 | class BindingModel;
|
---|
[8aa597] | 23 | class Fragment;
|
---|
[67044a] | 24 | class HomologyGraph;
|
---|
[8aa597] | 25 |
|
---|
| 26 | /** Namespace containing all simple extractor functions.
|
---|
[1ba8a1] | 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.
|
---|
[8aa597] | 37 | *
|
---|
| 38 | */
|
---|
| 39 | namespace Extractors {
|
---|
[301dbf] | 40 | typedef Fragment::charges_t::const_iterator chargeiter_t;
|
---|
| 41 | typedef std::vector<chargeiter_t> chargeiters_t;
|
---|
| 42 |
|
---|
| 43 | typedef size_t count_t;
|
---|
[c5e75f3] | 44 | typedef Fragment::atomicNumber_t element_t;
|
---|
[301dbf] | 45 | typedef std::map< element_t, count_t> elementcounts_t;
|
---|
| 46 | typedef std::map< element_t, chargeiters_t > elementtargets_t;
|
---|
[caa00e9] | 47 | typedef std::vector< chargeiters_t > targets_per_combination_t;
|
---|
[df350c] | 48 | //!> typedef for particle designation
|
---|
[c5e75f3] | 49 | typedef unsigned int ParticleType_t;
|
---|
[df350c] | 50 | //!> typedef for a vector of particle designations
|
---|
| 51 | typedef std::vector<ParticleType_t> ParticleTypes_t;
|
---|
[301dbf] | 52 |
|
---|
[8aa597] | 53 | /** Namespace for some internal helper functions.
|
---|
| 54 | *
|
---|
| 55 | */
|
---|
| 56 | namespace _detail {
|
---|
[bc6705] | 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(
|
---|
[c5e75f3] | 64 | const Fragment::atomicnumbers_t elements
|
---|
[bc6705] | 65 | );
|
---|
| 66 |
|
---|
[8aa597] | 67 | }
|
---|
| 68 |
|
---|
[49f163] | 69 | /** Gather all distances from a given set of positions.
|
---|
| 70 | *
|
---|
| 71 | * Here, we only return one of the two equal distances.
|
---|
| 72 | *
|
---|
[691be4] | 73 | * \param positions all nuclei positions
|
---|
[c7aac9] | 74 | * \param atomicNumber all nuclei atomic numbers
|
---|
[228340] | 75 | * \param edges edges of the fragment's bond graph
|
---|
[49f163] | 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(
|
---|
[691be4] | 81 | const Fragment::positions_t& positions,
|
---|
[c7aac9] | 82 | const Fragment::atomicnumbers_t& atomicnumbers,
|
---|
[228340] | 83 | const FragmentationEdges::edges_t &edges,
|
---|
[49f163] | 84 | const size_t globalid);
|
---|
| 85 |
|
---|
[691be4] | 86 | /** Simple extractor of all unique pair distances of a given \a fragment, where
|
---|
| 87 | * the first index is less than the second one.
|
---|
[8aa597] | 88 | *
|
---|
[691be4] | 89 | * \param positions all nuclei positions
|
---|
[c7aac9] | 90 | * \param atomicNumber all nuclei atomic numbers
|
---|
[228340] | 91 | * \param edges edges of the fragment's bond graph
|
---|
[691be4] | 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,
|
---|
[c7aac9] | 97 | const Fragment::atomicnumbers_t& atomicnumbers,
|
---|
[228340] | 98 | const FragmentationEdges::edges_t &edges,
|
---|
[691be4] | 99 | const size_t index
|
---|
| 100 | ) {
|
---|
| 101 | // get distance out of Fragment
|
---|
[228340] | 102 | return gatherAllSymmetricDistanceArguments(positions, atomicnumbers, edges, index);
|
---|
[691be4] | 103 | }
|
---|
| 104 |
|
---|
[1155ba] | 105 | /** Filter the arguments to select only these required by the model.
|
---|
[df350c] | 106 | *
|
---|
[1155ba] | 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()
|
---|
[df350c] | 109 | *
|
---|
[e1fe7e] | 110 | * \param listargs list of arguments to reorder each
|
---|
[e60558] | 111 | * \param _graph contains binding model of graph
|
---|
[df350c] | 112 | * \param _types particle type vector
|
---|
| 113 | * \return reordered args
|
---|
| 114 | */
|
---|
[1155ba] | 115 | FunctionModel::list_of_arguments_t filterArgumentsByParticleTypes(
|
---|
| 116 | const FunctionModel::arguments_t &args,
|
---|
[e60558] | 117 | const HomologyGraph &_graph,
|
---|
[67044a] | 118 | const ParticleTypes_t &_types,
|
---|
[9c793c] | 119 | const BindingModel &_bindingmodel
|
---|
[df350c] | 120 | );
|
---|
[9897ee9] | 121 |
|
---|
[1155ba] | 122 | /** Filter and reorder the arguments to bring adjacent ones together.
|
---|
[51e0e3] | 123 | *
|
---|
[1155ba] | 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.
|
---|
[51e0e3] | 128 | *
|
---|
[1155ba] | 129 | * \param listargs list of arguments to filter and order appropriately
|
---|
[e60558] | 130 | * \param _graph contains binding model of graph
|
---|
[51e0e3] | 131 | * \param _types particle type vector
|
---|
[1155ba] | 132 | * \return reordered args
|
---|
[51e0e3] | 133 | */
|
---|
[1155ba] | 134 | FunctionModel::list_of_arguments_t filterArgumentsByBindingModel(
|
---|
[51e0e3] | 135 | const FunctionModel::arguments_t &args,
|
---|
[e60558] | 136 | const HomologyGraph &_graph,
|
---|
[67044a] | 137 | const ParticleTypes_t &_types,
|
---|
[9c793c] | 138 | const BindingModel &_bindingmodel
|
---|
[51e0e3] | 139 | );
|
---|
| 140 |
|
---|
[cf4905] | 141 | /** Combines two argument lists by sorting and making unique.
|
---|
[9897ee9] | 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 |
|
---|
[cf4905] | 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 |
|
---|
[e1fe7e] | 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 |
|
---|
[8aa597] | 171 | }; /* namespace Extractors */
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | #endif /* TRAININGDATA_EXTRACTORS_HPP_ */
|
---|