[358ddb] | 1 | /*
|
---|
| 2 | * OrthogonalFullSummator.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: 08.09.2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef ORTHOGONALFULLSUMMATOR_HPP_
|
---|
| 9 | #define ORTHOGONALFULLSUMMATOR_HPP_
|
---|
| 10 |
|
---|
| 11 | // include config.h
|
---|
| 12 | #ifdef HAVE_CONFIG_H
|
---|
| 13 | #include <config.h>
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
| 16 | #include <boost/fusion/sequence.hpp>
|
---|
| 17 |
|
---|
| 18 | #include "Fragmentation/Summation/OrthogonalSummation.hpp"
|
---|
| 19 | #include "Fragmentation/Summation/SetValue.hpp"
|
---|
| 20 | #include "Jobs/MPQCDataMap.hpp"
|
---|
| 21 |
|
---|
| 22 | /** OrthogonalFullSummator is a general class for making us of OrthogonalSummation.
|
---|
| 23 | *
|
---|
| 24 | *
|
---|
| 25 | * This class is very similar to OrthogonalSummation only that we specifically include
|
---|
| 26 | * the full set (with a value!) as well. Also there is a function to obtain the
|
---|
| 27 | * contribution. This is intended to check a full calculation against the truncated
|
---|
| 28 | * sum.
|
---|
| 29 | */
|
---|
| 30 | template <typename MapType, typename MapKey>
|
---|
| 31 | struct OrthogonalFullSummator {
|
---|
| 32 | /** We retrieve the type of the MPQCData member variable from the
|
---|
| 33 | * boost::fusion::map and stored it in this typedef. Note that for
|
---|
| 34 | * internal types (e.g. MapValue::const_iterator we need to place
|
---|
| 35 | * \b typename before).
|
---|
| 36 | */
|
---|
| 37 | typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
|
---|
| 38 |
|
---|
| 39 | /** Constructor for class OrthogonalFullSummator.
|
---|
| 40 | *
|
---|
| 41 | * \param _subsetmap map with hierarchy of IndexSet's
|
---|
| 42 | * \param _data MPQCData converted to MPQCDataMap_t type
|
---|
| 43 | * \param _jobids job ids to sum data in correct order
|
---|
| 44 | * \param _container container of IndexSet's such that each set has correct order
|
---|
| 45 | * to job id and hence to _data.
|
---|
| 46 | * \param _MatrixNrLookup lookup from job id to ordering in above vectors
|
---|
| 47 | */
|
---|
| 48 | OrthogonalFullSummator(
|
---|
| 49 | SubsetMap::ptr &_subsetmap,
|
---|
| 50 | const std::vector<MapType> &_data,
|
---|
| 51 | const std::vector<JobId_t> &_jobids,
|
---|
| 52 | const IndexSetContainer::Container_t &_container,
|
---|
| 53 | std::map< JobId_t, size_t > &_MatrixNrLookup) : /* cannot make this const due to operator[] */
|
---|
| 54 | indices(getSubsets(_container)),
|
---|
| 55 | values(createValues(_data, _jobids, _container, _MatrixNrLookup)),
|
---|
| 56 | OS(indices, values, _subsetmap)
|
---|
| 57 | {
|
---|
| 58 | ASSERT( _data.size() == _container.size(),
|
---|
| 59 | "OrthogonalFullSummator() - data and indices don't have same size.");
|
---|
| 60 | ASSERT( _data.size() == _jobids.size(),
|
---|
| 61 | "OrthogonalFullSummator() - data and ids don't have same size.");
|
---|
| 62 | ASSERT( _jobids.size() == _MatrixNrLookup.size(),
|
---|
| 63 | "OrthogonalFullSummator() - ids and MatrixNrLookup don't have same size.");
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /** Summation operator.
|
---|
| 67 | *
|
---|
| 68 | * Initialises instantiated OrthogonalSummation of the respective type via
|
---|
| 69 | * \a OrthogonalFullSummator::data, uses OrthogonalSummation::operator() to sum and returns
|
---|
| 70 | * the result.
|
---|
| 71 | *
|
---|
| 72 | * \param level up to which level to sum up
|
---|
| 73 | * \return result of OrthogonalSummation for given type from MPQCDataMap_t.
|
---|
| 74 | */
|
---|
| 75 | MapValue operator()(const size_t level)
|
---|
| 76 | {
|
---|
| 77 | // evaluate
|
---|
| 78 | const MapValue result = OS(level);
|
---|
| 79 | return result;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /** Getter for the remaining contribution of the full set.
|
---|
| 83 | *
|
---|
| 84 | * @return contribution of allindices
|
---|
| 85 | */
|
---|
| 86 | MapValue getFullContribution() const {
|
---|
| 87 | typename SetValueMap<MapValue>::const_iterator iter = --OS.getSetValues().end();
|
---|
| 88 | return iter->second->getContribution();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | private:
|
---|
| 92 | /** Tiny helper to create the indices from a given IndexSetContainer.
|
---|
| 93 | *
|
---|
| 94 | * @param container container with IndexSet
|
---|
| 95 | * @return all subsets contained in \a container
|
---|
| 96 | */
|
---|
| 97 | typename OrthogonalSummation<MapValue>::InputSets_t getSubsets(
|
---|
| 98 | const IndexSetContainer::Container_t &container)
|
---|
| 99 | {
|
---|
| 100 | typename OrthogonalSummation<MapValue>::InputSets_t indices(
|
---|
| 101 | container.begin(),
|
---|
| 102 | container.end());
|
---|
| 103 | return indices;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /** Tiny helper to create the values for the summation in the correct order.
|
---|
| 107 | *
|
---|
| 108 | * @param data
|
---|
| 109 | * @param jobids
|
---|
| 110 | * @param container
|
---|
| 111 | * @param MatrixNrLookup
|
---|
| 112 | * @return
|
---|
| 113 | */
|
---|
| 114 | typename OrthogonalSummation<MapValue>::InputValues_t createValues(
|
---|
| 115 | const std::vector<MapType> &data,
|
---|
| 116 | const std::vector<JobId_t> &jobids,
|
---|
| 117 | const IndexSetContainer::Container_t &container,
|
---|
| 118 | std::map< JobId_t, size_t > &MatrixNrLookup)
|
---|
| 119 | {
|
---|
| 120 | typename OrthogonalSummation<MapValue>::InputValues_t values(container.size());
|
---|
| 121 | typename std::vector<MapType>::const_iterator dataiter = data.begin();
|
---|
| 122 | std::vector<size_t>::const_iterator iditer = jobids.begin();
|
---|
| 123 | for (; dataiter != data.end(); ++dataiter, ++iditer) {
|
---|
| 124 | const MapType &Data = *dataiter;
|
---|
| 125 | const MapValue &value = boost::fusion::at_key<MapKey>(Data);
|
---|
| 126 | values[ MatrixNrLookup[*iditer] ] = value;
|
---|
| 127 | }
|
---|
| 128 | return values;
|
---|
| 129 | }
|
---|
| 130 | private:
|
---|
| 131 | //!> created indices for OS such that we may hand over refs
|
---|
| 132 | typename OrthogonalSummation<MapValue>::InputSets_t indices;
|
---|
| 133 | //!> created values for OS such that we may hand over refs
|
---|
| 134 | typename OrthogonalSummation<MapValue>::InputValues_t values;
|
---|
| 135 | //!> Summation instance to use in operator()(level)
|
---|
| 136 | OrthogonalSummation<MapValue> OS;
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | #endif /* ORTHOGONALFULLSUMMATOR_HPP_ */
|
---|