51 os << pairs[i].first() <<
' ' << pairs[i].second() <<
nl;
74 Map<label>(static_cast<
Map<label>>(d)),
75 binWidth_(d.binWidth())
89 label sumOfEntries = 0;
93 sumOfEntries += iter.val();
98 <<
"Accumulated distribution values total has become negative: "
99 <<
"sumOfEntries = " << sumOfEntries
100 <<
". This is most likely to be because too many samples "
101 <<
"have been added to the bins and the label has 'rolled "
102 <<
"round'. Try distribution::approxTotalEntries which "
103 <<
"returns a scalar." <<
endl;
117 scalar sumOfEntries = 0;
121 sumOfEntries += scalar(iter.val());
130 scalar runningSum = 0;
132 scalar totEnt = approxTotalEntries();
134 List<label> keys = toc();
143 *scalar((*
this)[
key])
160 scalar runningSum = 0.0;
166 if (normDist.size() == 1)
168 median = normDist[0].first();
173 && normDist[0].second()*binWidth_ > 0.5
176 scalar xk = normDist[1].first();
177 scalar xkm1 = normDist[0].first();
179 (normDist[0].second() + normDist[1].second())*binWidth_;
180 scalar Skm1 = normDist[0].second()*binWidth_;
182 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
186 label lastNonZeroIndex = 0;
190 if (runningSum + (normDist[nD].second()*binWidth_) > 0.5)
192 scalar xk = normDist[nD].first();
193 scalar xkm1 = normDist[lastNonZeroIndex].first();
194 scalar Sk = runningSum + (normDist[nD].second()*binWidth_);
195 scalar Skm1 = runningSum;
197 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
201 else if (normDist[nD].second() > 0.0)
203 runningSum += normDist[nD].second()*binWidth_;
205 lastNonZeroIndex = nD;
217 iterator iter(this->
begin());
219 label
n = label(valueToAdd/binWidth_) - label(
neg(valueToAdd/binWidth_));
223 if (iter == this->
end())
235 <<
"Accumulated distribution value has become negative: "
236 <<
"bin = " << (0.5 + scalar(
n)) * binWidth_
237 <<
", value = " << (*
this)[
n]
238 <<
". This is most likely to be because too many samples "
239 <<
"have been added to a bin and the label has 'rolled round'"
247 add(scalar(valueToAdd));
257 for (label
k = keys[1];
k < keys.last();
k++)
268 scalar totEnt = approxTotalEntries();
272 List<label> keys = sortedToc();
273 List<Pair<scalar>> normDist(size());
279 normDist[
k].first() = (0.5 + scalar(
key))*binWidth_;
281 normDist[
k].second() = scalar((*
this)[
key])/totEnt/binWidth_;
295 return normalisedShifted(mean());
310 oldDist[u].first() -= shiftValue;
313 scalar lowestOldBin = oldDist[0].first()/binWidth_ - 0.5;
315 label lowestNewKey = label
317 lowestOldBin + 0.5*
sign(lowestOldBin)
320 scalar interpolationStartDirection =
321 sign(scalar(lowestNewKey) - lowestOldBin);
323 label newKey = lowestNewKey;
328 <<
nl << lowestOldBin
329 <<
nl << lowestNewKey
330 <<
nl << interpolationStartDirection
333 scalar checkNormalisation = 0;
337 checkNormalisation += oldDist[oD].second()*binWidth_;
340 Info<<
"Initial normalisation = " << checkNormalisation <<
endl;
345 newDist[u].first() = (0.5 + scalar(newKey)) * binWidth_;
347 if (interpolationStartDirection < 0)
351 newDist[u].second() =
352 (0.5 + scalar(newKey))*oldDist[u].second()
353 - oldDist[u].second()
354 *(oldDist[u].first() - binWidth_)/ binWidth_;
358 newDist[u].second() =
359 (0.5 + scalar(newKey))
360 *(oldDist[u].second() - oldDist[u-1].second())
363 oldDist[u-1].second()*oldDist[u].first()
364 - oldDist[u].second()*oldDist[u-1].first()
371 if (u == oldDist.size() - 1)
373 newDist[u].second() =
374 (0.5 + scalar(newKey))*-oldDist[u].second()
375 + oldDist[u].second()*(oldDist[u].first() + binWidth_)
380 newDist[u].second() =
381 (0.5 + scalar(newKey))
382 *(oldDist[u+1].second() - oldDist[u].second())
385 oldDist[u].second()*oldDist[u+1].first()
386 - oldDist[u+1].second()*oldDist[u].first()
397 scalar checkNormalisation = 0;
401 checkNormalisation += newDist[nD].second()*binWidth_;
404 Info<<
"Shifted normalisation = " << checkNormalisation <<
endl;
415 List<label> keys = sortedToc();
416 List<Pair<scalar>> rawDist(size());
422 rawDist[
k].first() = (0.5 + scalar(
key))*binWidth_;
424 rawDist[
k].second() = scalar((*
this)[
key]);
451 <<
static_cast<const Map<label>&
>(d);