source: src/FunctionApproximation/Extractors.hpp@ cf4905

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since cf4905 was cf4905, checked in by Frederik Heber <heber@…>, 11 years ago

Added concatenateArguments to Extractors.

  • Property mode set to 100644
File size: 11.7 KB
Line 
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
21class Fragment;
22
23/** Namespace containing all simple extractor functions.
24 *
25 */
26namespace Extractors {
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;
34 typedef std::vector< chargeiters_t > targets_per_combination_t;
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;
39
40 /** Namespace for some internal helper functions.
41 *
42 */
43 namespace _detail {
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
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 *
66 * \param positions all nuclei positions
67 * \param charges all nuclei charges
68 * \param targets iterators on charges
69 * \return filtered positions
70 */
71 Fragment::positions_t gatherPositionsFromTargets(
72 const Fragment::positions_t& positions,
73 const Fragment::charges_t& charges,
74 const chargeiters_t& targets
75 );
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
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 );
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 );
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 );
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 &currenttargets)> &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 );
182 }
183
184 /** Gather all distances from a given set of positions.
185 *
186 * \param positions all nuclei positions
187 * \param charges all nuclei charges
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(
193 const Fragment::positions_t& positions,
194 const Fragment::charges_t& charges,
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 *
201 * \param positions all nuclei positions
202 * \param charges all nuclei charges
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(
208 const Fragment::positions_t& positions,
209 const Fragment::charges_t& charges,
210 const size_t globalid);
211
212 /** Simple extractor of all unique pair distances of a given \a fragment.
213 *
214 * \param positions all nuclei positions
215 * \param charges all nuclei charges
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(
220 const Fragment::positions_t& positions,
221 const Fragment::charges_t& charges,
222 const size_t index
223 ) {
224 // get distance out of Fragment
225 return gatherAllDistanceArguments(positions, charges, index);
226 }
227
228 /** Simple extractor of all unique pair distances of a given \a fragment, where
229 * the first index is less than the second one.
230 *
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
249 * \param elements tuple of desired elements
250 * \return vector of positions_t containing
251 */
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
263 * \param globalid refers to the index within the global set of configurations
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
271 );
272
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
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
301 );
302
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 );
316
317 /** Combines two argument lists by sorting and making unique.
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
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
337}; /* namespace Extractors */
338
339
340#endif /* TRAININGDATA_EXTRACTORS_HPP_ */
Note: See TracBrowser for help on using the repository browser.