[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 |
|
---|
| 16 | #include "Fragmentation/SetValues/Fragment.hpp"
|
---|
| 17 | #include "FunctionApproximation/FunctionModel.hpp"
|
---|
| 18 |
|
---|
| 19 | class Fragment;
|
---|
| 20 |
|
---|
| 21 | /** Namespace containing all simple extractor functions.
|
---|
| 22 | *
|
---|
| 23 | */
|
---|
| 24 | namespace Extractors {
|
---|
[301dbf] | 25 | typedef Fragment::charges_t::const_iterator chargeiter_t;
|
---|
| 26 | typedef std::vector<chargeiter_t> chargeiters_t;
|
---|
| 27 |
|
---|
| 28 | typedef size_t count_t;
|
---|
| 29 | typedef Fragment::charge_t element_t;
|
---|
| 30 | typedef std::map< element_t, count_t> elementcounts_t;
|
---|
| 31 | typedef std::map< element_t, chargeiters_t > elementtargets_t;
|
---|
| 32 |
|
---|
[8aa597] | 33 | /** Namespace for some internal helper functions.
|
---|
| 34 | *
|
---|
| 35 | */
|
---|
| 36 | namespace _detail {
|
---|
[691be4] | 37 | /** Gather all distance arguments from the same aligned vector of charges.
|
---|
| 38 | *
|
---|
| 39 | * Basically, we filter the positions indicated by the targets but
|
---|
| 40 | * from a different vector that has the same layout.
|
---|
| 41 | *
|
---|
| 42 | * \param positions all nuclei positions
|
---|
| 43 | * \param charges all nuclei charges
|
---|
| 44 | * \param targets iterators on charges
|
---|
| 45 | * \return filtered distance arguments
|
---|
| 46 | */
|
---|
| 47 | FunctionModel::arguments_t gatherDistancesFromTargets(
|
---|
| 48 | const Fragment::positions_t& positions,
|
---|
| 49 | const Fragment::charges_t& charges,
|
---|
| 50 | const chargeiters_t &targets,
|
---|
| 51 | const size_t globalid
|
---|
| 52 | );
|
---|
| 53 |
|
---|
[301dbf] | 54 | /** Gather all positions from the same aligned vector of charges.
|
---|
| 55 | *
|
---|
| 56 | * Basically, we filter the positions indicated by the targets but
|
---|
| 57 | * from a different vector that has the same layout.
|
---|
| 58 | *
|
---|
[691be4] | 59 | * \param positions all nuclei positions
|
---|
| 60 | * \param charges all nuclei charges
|
---|
[301dbf] | 61 | * \param targets iterators on charges
|
---|
| 62 | * \return filtered positions
|
---|
| 63 | */
|
---|
[691be4] | 64 | Fragment::positions_t gatherPositionsFromTargets(
|
---|
| 65 | const Fragment::positions_t& positions,
|
---|
| 66 | const Fragment::charges_t& charges,
|
---|
| 67 | const chargeiters_t& targets
|
---|
[301dbf] | 68 | );
|
---|
[bc6705] | 69 |
|
---|
| 70 | /** Counts all same elements in the vector and places into map of elements.
|
---|
| 71 | *
|
---|
| 72 | * \param elements vector of elements
|
---|
| 73 | * \return count of same element in vector
|
---|
| 74 | */
|
---|
| 75 | elementcounts_t getElementCounts(
|
---|
| 76 | const Fragment::charges_t elements
|
---|
| 77 | );
|
---|
| 78 |
|
---|
[c211f7] | 79 | /** Gather iterators to the elements related to the desired elementcounts.
|
---|
| 80 | *
|
---|
| 81 | * \param charges charges wherein to search for the elements
|
---|
| 82 | * \param elementcounts number of desired hits per element
|
---|
| 83 | * \return iterators equal to the initial vector of elements
|
---|
| 84 | */
|
---|
| 85 | elementtargets_t convertElementcountsToTargets(
|
---|
| 86 | const Fragment::charges_t &charges,
|
---|
| 87 | const elementcounts_t &elementcounts
|
---|
| 88 | );
|
---|
[63e786] | 89 |
|
---|
| 90 | /** Convert the alignment back to as it was in the original vector.
|
---|
| 91 | *
|
---|
| 92 | * We lost the information by storing it in a map. Hence, we need this
|
---|
| 93 | * final step.
|
---|
| 94 | *
|
---|
| 95 | * \param elementtargets targets as they are in the map \a elementcounts
|
---|
| 96 | * \param elements the original order of the elements
|
---|
| 97 | * \param elementcounts the count per element for debugging checks
|
---|
| 98 | * \return vector of targets in the order as they are in \a element
|
---|
| 99 | */
|
---|
| 100 | chargeiters_t realignElementtargets(
|
---|
| 101 | const elementtargets_t &elementtargets,
|
---|
| 102 | const Fragment::charges_t elements,
|
---|
| 103 | const elementcounts_t &elementcounts
|
---|
| 104 | );
|
---|
[691be4] | 105 |
|
---|
| 106 | /** Searches for desired elements in charges in a unique manner.
|
---|
| 107 | *
|
---|
| 108 | * The idea is to have e.g. a fragment with charges 8,1,1,2 and
|
---|
| 109 | * elements as 1,8,1 (e.g. for an angle HOH) and we get the
|
---|
| 110 | * chargeiters in the desired manner on indices: 1,0,3.
|
---|
| 111 | *
|
---|
| 112 | * \param charges charges to look through
|
---|
| 113 | * \param elements vector of elements to find
|
---|
| 114 | */
|
---|
| 115 | chargeiters_t
|
---|
| 116 | gatherTargetsFromFragment(
|
---|
| 117 | const Fragment::charges_t& charges,
|
---|
| 118 | const Fragment::charges_t elements
|
---|
| 119 | );
|
---|
[8aa597] | 120 | }
|
---|
| 121 |
|
---|
[49f163] | 122 | /** Gather all distances from a given set of positions.
|
---|
| 123 | *
|
---|
[691be4] | 124 | * \param positions all nuclei positions
|
---|
| 125 | * \param charges all nuclei charges
|
---|
[49f163] | 126 | * \param globalid index to associated in argument_t with
|
---|
| 127 | * \return vector of argument_ , each with a distance
|
---|
| 128 | */
|
---|
| 129 | FunctionModel::arguments_t
|
---|
| 130 | gatherAllDistanceArguments(
|
---|
[691be4] | 131 | const Fragment::positions_t& positions,
|
---|
| 132 | const Fragment::charges_t& charges,
|
---|
[49f163] | 133 | const size_t globalid);
|
---|
| 134 |
|
---|
| 135 | /** Gather all distances from a given set of positions.
|
---|
| 136 | *
|
---|
| 137 | * Here, we only return one of the two equal distances.
|
---|
| 138 | *
|
---|
[691be4] | 139 | * \param positions all nuclei positions
|
---|
| 140 | * \param charges all nuclei charges
|
---|
[49f163] | 141 | * \param globalid index to associated in argument_t with
|
---|
| 142 | * \return vector of argument_ , each with a distance
|
---|
| 143 | */
|
---|
| 144 | FunctionModel::arguments_t
|
---|
| 145 | gatherAllSymmetricDistanceArguments(
|
---|
[691be4] | 146 | const Fragment::positions_t& positions,
|
---|
| 147 | const Fragment::charges_t& charges,
|
---|
[49f163] | 148 | const size_t globalid);
|
---|
| 149 |
|
---|
[8aa597] | 150 | /** Simple extractor of all unique pair distances of a given \a fragment.
|
---|
| 151 | *
|
---|
[691be4] | 152 | * \param positions all nuclei positions
|
---|
| 153 | * \param charges all nuclei charges
|
---|
[8aa597] | 154 | * \param index index refers to the index within the global set of configurations
|
---|
| 155 | * \return vector of of argument_t containing all found distances
|
---|
| 156 | */
|
---|
| 157 | inline FunctionModel::arguments_t gatherAllDistances(
|
---|
[691be4] | 158 | const Fragment::positions_t& positions,
|
---|
| 159 | const Fragment::charges_t& charges,
|
---|
[8aa597] | 160 | const size_t index
|
---|
| 161 | ) {
|
---|
| 162 | // get distance out of Fragment
|
---|
[691be4] | 163 | return gatherAllDistanceArguments(positions, charges, index);
|
---|
[8aa597] | 164 | }
|
---|
| 165 |
|
---|
[691be4] | 166 | /** Simple extractor of all unique pair distances of a given \a fragment, where
|
---|
| 167 | * the first index is less than the second one.
|
---|
[8aa597] | 168 | *
|
---|
[691be4] | 169 | * \param positions all nuclei positions
|
---|
| 170 | * \param charges all nuclei charges
|
---|
| 171 | * \param index index refers to the index within the global set of configurations
|
---|
| 172 | * \return vector of of argument_t containing all found distances
|
---|
| 173 | */
|
---|
| 174 | inline FunctionModel::arguments_t gatherAllSymmetricDistances(
|
---|
| 175 | const Fragment::positions_t& positions,
|
---|
| 176 | const Fragment::charges_t& charges,
|
---|
| 177 | const size_t index
|
---|
| 178 | ) {
|
---|
| 179 | // get distance out of Fragment
|
---|
| 180 | return gatherAllSymmetricDistanceArguments(positions, charges, index);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | /** Filters only those positions out of given \a fragment that match \a elements.
|
---|
| 184 | *
|
---|
| 185 | * \param positions all nuclei positions
|
---|
| 186 | * \param charges all nuclei charges
|
---|
[301dbf] | 187 | * \param elements tuple of desired elements
|
---|
| 188 | * \return vector of positions_t containing
|
---|
[8aa597] | 189 | */
|
---|
[691be4] | 190 | Fragment::positions_t gatherPositionsFromFragment(
|
---|
| 191 | const Fragment::positions_t positions,
|
---|
| 192 | const Fragment::charges_t charges,
|
---|
| 193 | const Fragment::charges_t& elements
|
---|
| 194 | );
|
---|
| 195 |
|
---|
| 196 | /** Filters only those distances out of given \a fragment that match \a elements.
|
---|
| 197 | *
|
---|
| 198 | * \param positions all nuclei positions
|
---|
| 199 | * \param charges all nuclei charges
|
---|
| 200 | * \param elements tuple of desired elements
|
---|
| 201 | * \return vector of arguments_t containing those matched with elements
|
---|
| 202 | */
|
---|
| 203 | FunctionModel::arguments_t gatherDistancesFromFragment(
|
---|
| 204 | const Fragment::positions_t positions,
|
---|
| 205 | const Fragment::charges_t charges,
|
---|
| 206 | const Fragment::charges_t& elements,
|
---|
| 207 | const size_t globalid
|
---|
[301dbf] | 208 | );
|
---|
| 209 |
|
---|
| 210 | /** Reorder arguments by increasing distance.
|
---|
| 211 | *
|
---|
| 212 | * \param args arguments to reorder
|
---|
| 213 | * \return reordered args
|
---|
| 214 | */
|
---|
| 215 | FunctionModel::arguments_t reorderArgumentsByIncreasingDistance(
|
---|
| 216 | const FunctionModel::arguments_t &args
|
---|
[8aa597] | 217 | );
|
---|
| 218 |
|
---|
| 219 | }; /* namespace Extractors */
|
---|
| 220 |
|
---|
| 221 |
|
---|
| 222 | #endif /* TRAININGDATA_EXTRACTORS_HPP_ */
|
---|