Commit 4387fd1e authored by Yohann Bearzi's avatar Yohann Bearzi Committed by Kitware Robot

Merge topic 'resample2htg-quantile'

f9fbaa82 fixed quantile measurement in resample2htg
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: David E. DeMarle's avatarDavid E. DeMarle <dave.demarle@kitware.com>
Merge-request: !3916
parents cbc2d1ac f9fbaa82
Pipeline #160625 failed with stage
in 0 seconds
......@@ -236,6 +236,8 @@
name="Geometric Mean" />
<Proxy group="array_measurement"
name="Harmonic Mean" />
<Proxy group="array_measurement"
name="Quantile" />
<Proxy group="array_measurement"
name="Standard Deviation" />
<Proxy group="array_measurement"
......@@ -261,6 +263,8 @@
name="Geometric Mean" />
<Proxy group="array_measurement"
name="Harmonic Mean" />
<Proxy group="array_measurement"
name="Quantile" />
<Proxy group="array_measurement"
name="Standard Deviation" />
<Proxy group="array_measurement"
......
......@@ -46,8 +46,7 @@ void vtkQuantileAccumulator::Add(vtkAbstractAccumulator* accumulator)
std::size_t i = 0;
ListType out;
while (i < quantileAccumulator->SortedList->size() &&
(*quantileAccumulator->SortedList)[i].Weight <
(*this->SortedList)[this->PercentileIdx].Weight)
(*quantileAccumulator->SortedList)[i].Value < (*this->SortedList)[this->PercentileIdx].Value)
{
this->PercentileWeight += (*quantileAccumulator->SortedList)[i++].Weight;
}
......@@ -56,32 +55,21 @@ void vtkQuantileAccumulator::Add(vtkAbstractAccumulator* accumulator)
quantileAccumulator->SortedList->cbegin(), quantileAccumulator->SortedList->cend(),
std::back_inserter(out));
this->SortedList = std::make_shared<ListType>(out);
this->TotalWeight = quantileAccumulator->TotalWeight;
this->PercentileIdx = quantileAccumulator->PercentileIdx;
if (i)
this->TotalWeight += quantileAccumulator->TotalWeight;
// Move the percentile in the left direction.
while (this->PercentileIdx != 0 &&
this->Percentile - 100.0 * this->PercentileWeight / this->TotalWeight <= 0)
{
// Move the percentile in the left direction accordingly.
while (this->PercentileIdx != 0 &&
this->Percentile -
100.0 * (this->PercentileWeight - (*this->SortedList)[this->PercentileIdx - 1].Weight) /
this->TotalWeight >=
0)
{
--this->PercentileIdx;
this->PercentileWeight -= (*this->SortedList)[this->PercentileIdx].Weight;
}
this->PercentileWeight -= (*this->SortedList)[this->PercentileIdx].Weight;
--this->PercentileIdx;
}
else
// Move the percentile in the right direction.
while (this->PercentileIdx != this->SortedList->size() - 1 &&
this->Percentile - 100.0 * this->PercentileWeight / this->TotalWeight > 0)
{
while (this->PercentileIdx < this->SortedList->size() &&
this->Percentile -
100.0 * (this->PercentileWeight + (*this->SortedList)[this->PercentileIdx + 1].Weight) /
this->TotalWeight <=
0)
{
++this->PercentileIdx;
this->PercentileWeight += (*this->SortedList)[this->PercentileIdx].Weight;
}
++this->PercentileIdx;
this->PercentileWeight += (*this->SortedList)[this->PercentileIdx].Weight;
}
}
else
......@@ -100,36 +88,33 @@ void vtkQuantileAccumulator::Add(vtkAbstractAccumulator* accumulator)
//----------------------------------------------------------------------------
void vtkQuantileAccumulator::Add(double value, double weight)
{
if (this->SortedList->size() && (*this->SortedList)[this->PercentileIdx].Value >= value)
{
this->PercentileWeight += weight;
++this->PercentileIdx;
}
else if (!this->SortedList->size())
{
this->PercentileWeight = weight;
}
this->TotalWeight += weight;
auto it = std::lower_bound(
this->SortedList->begin(), this->SortedList->end(), ListElement(value, weight));
this->SortedList->insert(it, ListElement(value, weight));
if ((*this->SortedList)[this->PercentileIdx].Value >= value)
{
this->PercentileWeight += weight;
// Move the percentile in the left direction accordingly.
while (this->PercentileIdx != 0 &&
this->Percentile -
100.0 * (this->PercentileWeight - (*this->SortedList)[this->PercentileIdx - 1].Weight) /
this->TotalWeight >=
0)
{
--this->PercentileIdx;
this->PercentileWeight -= (*this->SortedList)[this->PercentileIdx].Weight;
}
// Move the percentile in the left direction.
while (this->PercentileIdx != 0 &&
this->Percentile - 100.0 * this->PercentileWeight / this->TotalWeight <= 0)
{
this->PercentileWeight -= (*this->SortedList)[this->PercentileIdx].Weight;
--this->PercentileIdx;
}
else
// Move the percentile in the right direction.
while (this->PercentileIdx != this->SortedList->size() - 1 &&
this->Percentile - 100.0 * this->PercentileWeight / this->TotalWeight > 0)
{
while (this->PercentileIdx < this->SortedList->size() &&
this->Percentile -
100.0 * (this->PercentileWeight + (*this->SortedList)[this->PercentileIdx + 1].Weight) /
this->TotalWeight <=
0)
{
++this->PercentileIdx;
this->PercentileWeight += (*this->SortedList)[this->PercentileIdx].Weight;
}
++this->PercentileIdx;
this->PercentileWeight += (*this->SortedList)[this->PercentileIdx].Weight;
}
this->Modified();
}
......@@ -147,10 +132,13 @@ void vtkQuantileAccumulator::Initialize()
void vtkQuantileAccumulator::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "PercentileIdx " << this->PercentileIdx << std::endl;
os << indent << "PercentileWeight " << this->PercentileWeight << std::endl;
os << indent << "TotalWeight " << this->TotalWeight << std::endl;
os << indent << "Sorted list:" << std::endl;
for (std::size_t i = 0; i < this->SortedList->size(); ++i)
{
os << indent << "Index " << i << ": (Value: " << (*this->SortedList)[i].Value
os << indent << indent << "Index " << i << ": (Value: " << (*this->SortedList)[i].Value
<< ", Weight: " << (*this->SortedList)[i].Weight << ")" << std::endl;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment