37 listStarts_(
pTraits<Type>::nComponents, 0)
46 listStarts_(
pTraits<Type>::nComponents, 0)
54 binWidth_(d.binWidth()),
55 listStarts_(d.listStarts())
62 List<List<scalar>>(move(d)),
63 binWidth_(d.binWidth()),
64 listStarts_(move(d.listStarts()))
82 scalar sumOfWeights = 0.0;
84 forAll(cmptDistribution, i)
86 sumOfWeights += cmptDistribution[i];
100 keys[
k] += listStarts_[cmpt];
116 if (cmptDistribution.
empty())
120 cmptDistribution.
setSize(2, 0.0);
122 listStarts_[cmpt] =
n;
127 label listIndex = -1;
129 label& listStart = listStarts_[cmpt];
131 label testIndex =
n - listStart;
142 forAll(cmptDistribution, i)
144 newCmptDistribution[i + sOld] = cmptDistribution[i];
147 cmptDistribution = newCmptDistribution;
152 listIndex = index(cmpt,
n);
154 else if (testIndex > cmptDistribution.
size() - 1)
158 cmptDistribution.
setSize(2*cmptDistribution.
size(), 0.0);
162 listIndex = index(cmpt,
n);
166 listIndex =
n - listStart;
185 forAll(cmptDistribution, i)
187 if (cmptDistribution[i] > 0.0)
189 if (limits.
first() == -1)
208 Type meanValue(
Zero);
210 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
214 scalar totalCmptWeight = totalWeight(cmpt);
237 Type medianValue(
Zero);
241 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
247 if (normDist.
size() == 1)
254 && normDist[0].second()*
component(binWidth_, cmpt) > 0.5
265 scalar Sk = (normDist[0].second())*
component(binWidth_, cmpt);
267 setComponent(medianValue, cmpt) = 0.5*(xk - xkm1)/(Sk) + xkm1;
271 label previousNonZeroIndex = 0;
273 scalar cumulative = 0.0;
289 normDist[previousNonZeroIndex].
first()
294 + (normDist[nD].second()*
component(binWidth_, cmpt));
296 scalar Skm1 = cumulative;
299 (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
303 else if (
mag(normDist[nD].
second()) > vSmall)
306 normDist[nD].second()*
component(binWidth_, cmpt);
308 previousNonZeroIndex = nD;
323 const Type& valueToAdd,
327 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
335 label listIndex = index(cmpt,
n);
337 cmptDistribution[listIndex] +=
component(weight, cmpt);
348 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
352 if (cmptDistribution.
empty())
357 scalar totalCmptWeight = totalWeight(cmpt);
376 normDist[i].
first() =
377 (0.5 + scalar(key))*
component(binWidth_, cmpt);
379 normDist[i].second() =
386 return normDistribution;
396 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
400 if (cmptDistribution.
empty())
422 rawDist[i].
first() = (0.5 + scalar(key))*
component(binWidth_, cmpt);
424 rawDist[i].second() = cmptDistribution[
k];
428 return rawDistribution;
439 normalisedDistribution;
441 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
444 normalisedDistribution[cmpt];
447 cumulativeNormalisedDistribution[cmpt];
453 cumNormalisedCmpt[i].
first() =
454 normalisedCmpt[i].
first()
457 cumNormalisedCmpt[i].second() =
458 normalisedCmpt[i].second()*
component(binWidth_, cmpt) +
sum;
460 sum = cumNormalisedCmpt[i].second();
464 return cumulativeNormalisedDistribution;
476 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
486 cumRawCmpt[i].
first() =
490 cumRawCmpt[i].second() = rawCmpt[i].second() +
sum;
492 sum = cumRawCmpt[i].second();
496 return cumulativeRawDistribution;
503 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
505 (*this)[cmpt].clear();
507 listStarts_[cmpt] = 0;
519 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
528 os <<
"# key normalised raw" <<
endl;
532 os << normPairs[i].
first()
533 <<
' ' << normPairs[i].second()
534 <<
' ' << rawPairs[i].second()
543 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
554 os <<
"# key normalised raw" <<
endl;
558 os << normPairs[i].
first()
559 <<
' ' << normPairs[i].second()
560 <<
' ' << rawPairs[i].second()
579 <<
"Attempted assignment to self"
585 binWidth_ = rhs.binWidth();
587 listStarts_ = rhs.listStarts();
601 <<
"Attempted assignment to self"
607 binWidth_ = rhs.binWidth();
609 listStarts_ = move(rhs.listStarts());
627 is.check(
"Istream& operator>>(Istream&, Distribution<Type>&)");
637 const Distribution<Type>& d
640 os << static_cast<const List<List<scalar>>& >(d)
645 os.check(
"Ostream& operator<<(Ostream&, " "const Distribution&)");
656 const Distribution<Type>& d1,
657 const Distribution<Type>& d2
661 Distribution<Type> d(
max(d1.
binWidth(), d2.binWidth()));
663 List<List<List<Pair<scalar>>>> rawDists(2);
665 rawDists[0] = d1.
raw();
666 rawDists[1] = d2.raw();
670 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
672 List<scalar>& cmptDistribution = d[cmpt];
674 const List<Pair<scalar>>& cmptRaw = rawDists[rDI][cmpt];
678 scalar valueToAdd = cmptRaw[rI].first();
679 scalar cmptWeight = cmptRaw[rI].second();
693 label listIndex = d.index(cmpt,
n);
695 cmptDistribution[listIndex] += cmptWeight;
700 return Distribution<Type>(d);
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
Accumulating histogram of component values. Specified bin resolution, automatic generation of bins.
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
List< label > keys(direction cmpt) const
void add(const Type &valueToAdd, const Type &weight=pTraits< Type >::one)
Add a value to the distribution, optionally specifying a weight.
~Distribution()
Destructor.
void write(const fileName &filePrefix) const
Write the distribution to file: key normalised raw.
Distribution()
Construct null.
scalar totalWeight(direction cmpt) const
Sum the total weight added to the component in the.
void clear()
Resets the Distribution by clearing the stored lists.
Pair< label > validLimits(direction cmpt) const
Returns the indices of the first and last non-zero entries.
const Type & binWidth() const
Return the bin width.
List< List< Pair< scalar > > > cumulativeRaw() const
Return the cumulative total bin weights and integration.
List< List< Pair< scalar > > > raw() const
Return the distribution of the total bin weights.
label index(direction cmpt, label n)
Return the appropriate List index for the given bin index.
List< List< Pair< scalar > > > normalised() const
Return the normalised distribution (probability density)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
An ordered pair of two objects of type <T> with first() and second() elements.
const Type & second() const
Return second.
const Type & first() const
Return first.
T & first()
Return the first element of the list.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
A class for handling file names.
A class representing the concept of 1 (scalar(1)) used to avoid unnecessary manipulations for objects...
Traits class for primitives.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
label & setComponent(label &l, const direction)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
errorManip< error > abort(error &err)
labelList second(const UList< labelPair > &p)
dimensionSet normalised(const dimensionSet &)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar neg(const dimensionedScalar &ds)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.