14 #include "RtypesCore.h"
19 for (
size_t i = 0; i < dict->size(); ++i) {
20 if (raw <= dict->
at(i)) {
23 else if ((dict->at(i) - raw) < (raw - dict->at(i-1)))
29 return dict->size() - 1;
36 vector<UShort_t>* order,
37 vector<Float_t>* dict,
41 std::normal_distribution<double>& distribution,
45 Int_t newLoc(vector<Int_t>* loc_vec, vector<vector<Int_t>>* loc_vec_vec);
49 Float_t approx(vector<UShort_t>* order, vector<Float_t>* dict, vector<size_t>* cnt,
Int_t n_entries, std::default_random_engine&
generator, std::normal_distribution<double>& distribution,
size_t maxNumClusters)
53 map<Float_t, pair<Float_t, Int_t>> min_max_loc_map;
54 vector<vector<Int_t>> loc_vec_vec;
55 vector<Int_t> loc_vec;
56 map<Float_t, set<Float_t>> distance_min_set_map;
58 for (
Int_t j = 0 ; j < n_entries; j++){
59 Float_t number = distribution(generator);
62 map<Float_t, pair<Float_t, Int_t>>::iterator mmlm = min_max_loc_map.find(*gen_);
64 if (mmlm != min_max_loc_map.end())
65 loc_vec_vec[mmlm->second.second].push_back(j);
69 loc_vec_vec[loc].push_back(j);
71 min_max_loc_map[*gen_] = pair<Float_t, Int_t>(*gen_, loc);
73 mmlm = min_max_loc_map.find(*gen_);
74 if (mmlm != min_max_loc_map.begin() && *gen_ <= prev(mmlm)->second.first) {
75 loc_vec_vec[prev(mmlm)->second.second].push_back(j);
76 loc_vec_vec[mmlm->second.second].clear();
77 loc_vec.push_back(mmlm->second.second);
79 min_max_loc_map.erase(mmlm);
81 }
else if (min_max_loc_map.size() >= 2) {
82 if (mmlm != min_max_loc_map.begin() && mmlm != prev(min_max_loc_map.end())) {
84 removeDiff(next(mmlm)->
second.first - prev(mmlm)->first, prev(mmlm)->first, &distance_min_set_map);
87 if (mmlm != min_max_loc_map.begin())
88 addDiff(mmlm->second.first - prev(mmlm)->first, prev(mmlm)->first, &distance_min_set_map);
90 if (mmlm != prev(min_max_loc_map.end()))
91 addDiff(next(mmlm)->
second.first - mmlm->first, mmlm->first, &distance_min_set_map);
95 if (min_max_loc_map.size() <= maxNumClusters)
98 map<Float_t, set<Float_t>>::iterator dmsm = distance_min_set_map.begin();
101 dmsm->second.erase(min);
102 if (dmsm->second.empty())
103 distance_min_set_map.erase(dmsm);
105 mmlm = min_max_loc_map.find(min);
106 if (mmlm != min_max_loc_map.begin())
107 removeDiff(mmlm->second.first - prev(mmlm)->first, prev(mmlm)->first, &distance_min_set_map);
109 if (next(mmlm) != prev(min_max_loc_map.end()))
110 removeDiff(next(next(mmlm))->
second.first - next(mmlm)->first, next(mmlm)->first, &distance_min_set_map);
112 vector<Int_t>*
s = &(loc_vec_vec[next(mmlm)->second.second]);
113 loc_vec_vec[mmlm->second.second].insert(loc_vec_vec[mmlm->second.second].end(),s->begin(), s->end());
114 mmlm->second.first = next(mmlm)->second.first;
115 min_max_loc_map.erase(next(mmlm));
116 mmlm = min_max_loc_map.find(min);
117 maxAbsErrorDoubled =
max(maxAbsErrorDoubled, mmlm->second.first - mmlm->first);
118 if (mmlm != min_max_loc_map.begin())
119 addDiff(mmlm->second.first - prev(mmlm)->first, prev(mmlm)->first, &distance_min_set_map);
121 if (mmlm != prev(min_max_loc_map.end()))
122 addDiff(next(mmlm)->
second.first - mmlm->first, mmlm->first, &distance_min_set_map);
126 order->resize(n_entries);
127 for (
const auto &mmlm : min_max_loc_map) {
130 for (
const auto &index : loc_vec_vec[mmlm.second.second]) {
131 (*order)[index] = dict->size();
134 dict->push_back(estimate);
135 cnt->push_back(loc_vec_vec[mmlm.second.second].size());
138 return maxAbsErrorDoubled / (double) 2;
141 Int_t newLoc(vector<Int_t>* loc_vec, vector<vector<Int_t>>* loc_vec_vec)
143 if (!loc_vec->empty()) {
144 Int_t loc = loc_vec->back();
149 Int_t loc = loc_vec_vec->size();
150 loc_vec_vec->push_back({});
157 map<Float_t, set<Float_t>>::iterator dmsm = distance_min_set_map->find(distance);
158 dmsm->second.erase(min);
160 if (dmsm->second.empty())
161 distance_min_set_map->erase(dmsm);
166 map<Float_t, set<Float_t>>::iterator dmsm = distance_min_set_map->find(distance);
167 if (dmsm == distance_min_set_map->end()) {
168 (*distance_min_set_map)[distance] = {min};
170 dmsm->second.insert(min);