48 os << pairs[i].first() <<
' ' << pairs[i].second() <<
nl;
72 binWidth_(d.binWidth())
86 label sumOfEntries = 0;
90 sumOfEntries += iter();
95 <<
"Accumulated distribution values total has become negative: "
96 <<
"sumOfEntries = " << sumOfEntries
97 <<
". This is most likely to be because too many samples "
98 <<
"have been added to the bins and the label has 'rolled "
99 <<
"round'. Try distribution::approxTotalEntries which "
100 <<
"returns a scalar." <<
endl;
114 scalar sumOfEntries = 0;
118 sumOfEntries += scalar(iter());
127 scalar runningSum = 0;
129 scalar totEnt = approxTotalEntries();
140 *scalar((*
this)[key])
157 scalar runningSum = 0.0;
163 if (normDist.
size() == 1)
165 median = normDist[0].first();
170 && normDist[0].second()*binWidth_ > 0.5
173 scalar xk = normDist[1].first();
174 scalar xkm1 = normDist[0].first();
176 (normDist[0].second() + normDist[1].second())*binWidth_;
177 scalar Skm1 = normDist[0].second()*binWidth_;
179 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
183 label lastNonZeroIndex = 0;
187 if (runningSum + (normDist[nD].second()*binWidth_) > 0.5)
189 scalar xk = normDist[nD].first();
190 scalar xkm1 = normDist[lastNonZeroIndex].first();
191 scalar Sk = runningSum + (normDist[nD].second()*binWidth_);
192 scalar Skm1 = runningSum;
194 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
198 else if (normDist[nD].second() > 0.0)
200 runningSum += normDist[nD].second()*binWidth_;
202 lastNonZeroIndex = nD;
220 if (iter == this->end())
232 <<
"Accumulated distribution value has become negative: "
233 <<
"bin = " << (0.5 + scalar(
n)) * binWidth_
234 <<
", value = " << (*
this)[
n]
235 <<
". This is most likely to be because too many samples "
236 <<
"have been added to a bin and the label has 'rolled round'"
244 add(scalar(valueToAdd));
258 for (
label k = keys[0];
k < keys.last();
k++)
262 if (iter == this->end())
273 scalar totEnt = approxTotalEntries();
287 normDist[
k].first() = (0.5 + scalar(key))*binWidth_;
289 normDist[
k].second() = scalar((*
this)[key])/totEnt/binWidth_;
294 Info<<
"totEnt: " << totEnt <<
endl;
303 return normalisedShifted(mean());
318 oldDist[u].first() -= shiftValue;
321 scalar lowestOldBin = oldDist[0].first()/binWidth_ - 0.5;
325 lowestOldBin + 0.5*
sign(lowestOldBin)
328 scalar interpolationStartDirection =
329 sign(scalar(lowestNewKey) - lowestOldBin);
331 label newKey = lowestNewKey;
336 <<
nl << lowestOldBin
337 <<
nl << lowestNewKey
338 <<
nl << interpolationStartDirection
341 scalar checkNormalisation = 0;
345 checkNormalisation += oldDist[oD].second()*binWidth_;
348 Info<<
"Initial normalisation = " << checkNormalisation <<
endl;
353 newDist[u].first() = (0.5 + scalar(newKey)) * binWidth_;
355 if (interpolationStartDirection < 0)
359 newDist[u].second() =
360 (0.5 + scalar(newKey))*oldDist[u].second()
361 - oldDist[u].second()
362 *(oldDist[u].first() - binWidth_)/ binWidth_;
366 newDist[u].second() =
367 (0.5 + scalar(newKey))
368 *(oldDist[u].second() - oldDist[u-1].second())
371 oldDist[u-1].second()*oldDist[u].first()
372 - oldDist[u].second()*oldDist[u-1].first()
379 if (u == oldDist.
size() - 1)
381 newDist[u].second() =
382 (0.5 + scalar(newKey))*-oldDist[u].second()
383 + oldDist[u].second()*(oldDist[u].first() + binWidth_)
388 newDist[u].second() =
389 (0.5 + scalar(newKey))
390 *(oldDist[u+1].second() - oldDist[u].second())
393 oldDist[u].second()*oldDist[u+1].first()
394 - oldDist[u+1].second()*oldDist[u].first()
405 scalar checkNormalisation = 0;
409 checkNormalisation += newDist[nD].second()*binWidth_;
412 Info<<
"Shifted normalisation = " << checkNormalisation <<
endl;
433 rawDist[
k].first() = (0.5 + scalar(key))*binWidth_;
435 rawDist[
k].second() = scalar((*
this)[key]);
450 <<
"Attempted assignment to self"
470 "Ostream& operator<<(Ostream&, "
471 "const distribution&)"