mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Unit test for interpolation
p4#: 21496
This commit is contained in:
parent
6ef5205343
commit
71187d5bbc
@ -175,10 +175,8 @@ TEST(RigStatisticsMath, InterpolatedPercentiles)
|
|||||||
pValPos.push_back(90);
|
pValPos.push_back(90);
|
||||||
std::vector<double> pVals = RigStatisticsMath::calculateInterpolatedPercentiles(values, pValPos);
|
std::vector<double> pVals = RigStatisticsMath::calculateInterpolatedPercentiles(values, pValPos);
|
||||||
|
|
||||||
/*
|
EXPECT_DOUBLE_EQ( -72278.340409937548, pVals[0]);
|
||||||
EXPECT_DOUBLE_EQ( -76092.8157632591000, pVals[0]);
|
EXPECT_DOUBLE_EQ( -2265.6006907818719, pVals[1]);
|
||||||
EXPECT_DOUBLE_EQ( 2788.2723335651900 , pVals[1]);
|
EXPECT_DOUBLE_EQ( 6391.9799990972897, pVals[2]);
|
||||||
EXPECT_DOUBLE_EQ( 6391.979999097290 , pVals[2]);
|
EXPECT_DOUBLE_EQ( 93073.49128098879, pVals[3]);
|
||||||
EXPECT_DOUBLE_EQ( 96161.7546348456000 , pVals[3]);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -142,22 +142,22 @@ std::vector<double> RigStatisticsMath::calculateInterpolatedPercentiles(const st
|
|||||||
{
|
{
|
||||||
double pVal = HUGE_VAL;
|
double pVal = HUGE_VAL;
|
||||||
|
|
||||||
double doubleIndex = sortedValues.size() * fabs(pValPositions[i]) / 100.0;
|
double doubleIndex = (sortedValues.size() - 1) * fabs(pValPositions[i]) / 100.0;
|
||||||
|
|
||||||
size_t lowerValueIndex = static_cast<size_t>(floor(doubleIndex));
|
size_t lowerValueIndex = static_cast<size_t>(floor(doubleIndex));
|
||||||
size_t upperValueIndex = lowerValueIndex + 1;
|
size_t upperValueIndex = lowerValueIndex + 1;
|
||||||
|
|
||||||
if (lowerValueIndex >= sortedValues.size() ) lowerValueIndex = sortedValues.size() - 1;
|
double upperValueWeight = doubleIndex - lowerValueIndex;
|
||||||
if (upperValueIndex >= sortedValues.size() ) upperValueIndex = sortedValues.size() - 1;
|
assert(upperValueWeight < 1.0);
|
||||||
|
|
||||||
double upperValueWeight = 1.0;
|
if (upperValueIndex < sortedValues.size())
|
||||||
if (lowerValueIndex != upperValueIndex)
|
|
||||||
{
|
{
|
||||||
upperValueWeight = doubleIndex - lowerValueIndex;
|
pVal = (1.0 - upperValueWeight) * sortedValues[lowerValueIndex] + upperValueWeight * sortedValues[upperValueIndex];
|
||||||
assert(upperValueWeight < 1.0);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pVal = sortedValues[lowerValueIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
pVal = (1.0 - upperValueWeight) * sortedValues[lowerValueIndex] + upperValueWeight * sortedValues[upperValueIndex];
|
|
||||||
percentiles[i] = pVal;
|
percentiles[i] = pVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user