49 Map<label>(static_cast<
Map<label> >(d)),
50 binWidth_(d.binWidth())
64 label sumOfEntries = 0;
68 sumOfEntries += iter();
72 WarningIn(
"label distribution::totalEntries()")
73 <<
"Accumulated distribution values total has become negative: "
74 <<
"sumOfEntries = " << sumOfEntries
75 <<
". This is most likely to be because too many samples "
76 <<
"have been added to the bins and the label has 'rolled "
77 <<
"round'. Try distribution::approxTotalEntries which "
78 <<
"returns a scalar." <<
endl;
92 scalar sumOfEntries = 0;
96 sumOfEntries += scalar(iter());
105 scalar runningSum = 0;
118 *scalar((*
this)[key])
135 scalar runningSum = 0.0;
141 if (normDist.
size() == 1)
143 median = normDist[0].first();
148 && normDist[0].second()*binWidth_ > 0.5
151 scalar xk = normDist[1].first();
152 scalar xkm1 = normDist[0].first();
154 (normDist[0].second() + normDist[1].second())*binWidth_;
155 scalar Skm1 = normDist[0].second()*binWidth_;
157 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
161 label lastNonZeroIndex = 0;
165 if (runningSum + (normDist[nD].second()*binWidth_) > 0.5)
167 scalar xk = normDist[nD].first();
168 scalar xkm1 = normDist[lastNonZeroIndex].first();
169 scalar Sk = runningSum + (normDist[nD].second()*binWidth_);
170 scalar Skm1 = runningSum;
172 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
176 else if (normDist[nD].second() > 0.0)
178 runningSum += normDist[nD].second()*binWidth_;
180 lastNonZeroIndex = nD;
194 label n = label(valueToAdd/binWidth_) - label(
neg(valueToAdd/binWidth_));
198 if (iter == this->
end())
209 FatalErrorIn(
"distribution::add(const scalar valueToAdd)")
210 <<
"Accumulated distribution value has become negative: "
211 <<
"bin = " << (0.5 + scalar(n)) * binWidth_
212 <<
", value = " << (*
this)[n]
213 <<
". This is most likely to be because too many samples "
214 <<
"have been added to a bin and the label has 'rolled round'"
222 add(scalar(valueToAdd));
236 for (label
k = keys[0];
k < keys[keys.
size()-1];
k++)
240 if (iter == this->
end())
265 normDist[
k].first() = (0.5 + scalar(key))*binWidth_;
267 normDist[
k].second() = scalar((*
this)[key])/totEnt/binWidth_;
288 oldDist[u].first() -= shiftValue;
291 scalar lowestOldBin = oldDist[0].first()/binWidth_ - 0.5;
293 label lowestNewKey = label
295 lowestOldBin + 0.5*
sign(lowestOldBin)
298 scalar interpolationStartDirection =
299 sign(scalar(lowestNewKey) - lowestOldBin);
301 label newKey = lowestNewKey;
320 newDist[u].first() = (0.5 + scalar(newKey)) * binWidth_;
322 if (interpolationStartDirection < 0)
326 newDist[u].second() =
327 (0.5 + scalar(newKey))*oldDist[u].second()
328 - oldDist[u].second()
329 *(oldDist[u].first() - binWidth_)/ binWidth_;
333 newDist[u].second() =
334 (0.5 + scalar(newKey))
335 *(oldDist[u].second() - oldDist[u-1].second())
338 oldDist[u-1].second()*oldDist[u].first()
339 - oldDist[u].second()*oldDist[u-1].first()
346 if (u == oldDist.
size() - 1)
348 newDist[u].second() =
349 (0.5 + scalar(newKey))*-oldDist[u].second()
350 + oldDist[u].second()*(oldDist[u].first() + binWidth_)
355 newDist[u].second() =
356 (0.5 + scalar(newKey))
357 *(oldDist[u+1].second() - oldDist[u].second())
360 oldDist[u].second()*oldDist[u+1].first()
361 - oldDist[u+1].second()*oldDist[u].first()
397 rawDist[
k].first() = (0.5 + scalar(key))*binWidth_;
399 rawDist[
k].second() = scalar((*
this)[key]);
413 FatalErrorIn(
"distribution::operator=(const distribution&)")
414 <<
"Attempted assignment to self"
434 "Ostream& operator<<(Ostream&, "
435 "const distribution&)"