mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make P10/P90 calculation style more explicit
This commit is contained in:
committed by
GitHub
parent
0bfa6ae2d1
commit
1e83254e9e
@@ -343,8 +343,8 @@ void RigStatisticsDataCache::computeHistogramStatisticsIfNeeded()
|
||||
|
||||
m_statisticsCalculator->addDataToHistogramCalculator( histCalc );
|
||||
|
||||
m_statsAllTimesteps.m_p10 = histCalc.calculatePercentil( 0.1 );
|
||||
m_statsAllTimesteps.m_p90 = histCalc.calculatePercentil( 0.9 );
|
||||
m_statsAllTimesteps.m_p10 = histCalc.calculatePercentil( 0.1, RigStatisticsMath::PercentileStyle::SWITCHED );
|
||||
m_statsAllTimesteps.m_p90 = histCalc.calculatePercentil( 0.9, RigStatisticsMath::PercentileStyle::SWITCHED );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,8 +364,8 @@ void RigStatisticsDataCache::computeHistogramStatisticsIfNeeded( size_t timeStep
|
||||
|
||||
m_statisticsCalculator->addDataToHistogramCalculator( timeStepIndex, histCalc );
|
||||
|
||||
m_statsPrTs[timeStepIndex].m_p10 = histCalc.calculatePercentil( 0.1 );
|
||||
m_statsPrTs[timeStepIndex].m_p90 = histCalc.calculatePercentil( 0.9 );
|
||||
m_statsPrTs[timeStepIndex].m_p10 = histCalc.calculatePercentil( 0.1, RigStatisticsMath::PercentileStyle::SWITCHED );
|
||||
m_statsPrTs[timeStepIndex].m_p90 = histCalc.calculatePercentil( 0.9, RigStatisticsMath::PercentileStyle::SWITCHED );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,8 @@ void RigStatisticsMath::calculateStatisticsCurves( const std::vector<double>& va
|
||||
double* p10,
|
||||
double* p50,
|
||||
double* p90,
|
||||
double* mean )
|
||||
double* mean,
|
||||
PercentileStyle percentileStyle )
|
||||
{
|
||||
CVF_ASSERT( p10 && p50 && p90 && mean );
|
||||
|
||||
@@ -145,9 +146,20 @@ void RigStatisticsMath::calculateStatisticsCurves( const std::vector<double>& va
|
||||
}
|
||||
}
|
||||
|
||||
*p10 = pValues[P10];
|
||||
*p50 = pValues[P50];
|
||||
*p90 = pValues[P90];
|
||||
*p50 = pValues[P50];
|
||||
|
||||
if ( percentileStyle == PercentileStyle::REGULAR )
|
||||
{
|
||||
*p10 = pValues[P10];
|
||||
*p90 = pValues[P90];
|
||||
}
|
||||
else
|
||||
{
|
||||
CVF_ASSERT( percentileStyle == PercentileStyle::SWITCHED );
|
||||
*p10 = pValues[P90];
|
||||
*p90 = pValues[P10];
|
||||
}
|
||||
|
||||
*mean = valueSum / valueCount;
|
||||
}
|
||||
|
||||
@@ -158,7 +170,8 @@ void RigStatisticsMath::calculateStatisticsCurves( const std::vector<double>& va
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
std::vector<double> RigStatisticsMath::calculateNearestRankPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions )
|
||||
const std::vector<double>& pValPositions,
|
||||
RigStatisticsMath::PercentileStyle percentileStyle )
|
||||
{
|
||||
std::vector<double> sortedValues;
|
||||
sortedValues.reserve( inputValues.size() );
|
||||
@@ -180,7 +193,10 @@ std::vector<double> RigStatisticsMath::calculateNearestRankPercentiles( const st
|
||||
{
|
||||
double pVal = HUGE_VAL;
|
||||
|
||||
size_t pValIndex = static_cast<size_t>( sortedValues.size() * cvf::Math::abs( pValPositions[i] ) / 100 );
|
||||
double pValPosition = cvf::Math::abs( pValPositions[i] ) / 100;
|
||||
if ( percentileStyle == RigStatisticsMath::PercentileStyle::SWITCHED ) pValPosition = 1.0 - pValPosition;
|
||||
|
||||
size_t pValIndex = static_cast<size_t>( sortedValues.size() * pValPosition );
|
||||
|
||||
if ( pValIndex >= sortedValues.size() ) pValIndex = sortedValues.size() - 1;
|
||||
|
||||
@@ -198,7 +214,8 @@ std::vector<double> RigStatisticsMath::calculateNearestRankPercentiles( const st
|
||||
/// the inputValues does not contain any valid values
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<double> RigStatisticsMath::calculateInterpolatedPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions )
|
||||
const std::vector<double>& pValPositions,
|
||||
RigStatisticsMath::PercentileStyle percentileStyle )
|
||||
{
|
||||
std::vector<double> sortedValues;
|
||||
sortedValues.reserve( inputValues.size() );
|
||||
@@ -220,7 +237,10 @@ std::vector<double> RigStatisticsMath::calculateInterpolatedPercentiles( const s
|
||||
{
|
||||
double pVal = HUGE_VAL;
|
||||
|
||||
double doubleIndex = ( sortedValues.size() - 1 ) * cvf::Math::abs( pValPositions[i] ) / 100.0;
|
||||
double pValPosition = cvf::Math::abs( pValPositions[i] ) / 100.0;
|
||||
if ( percentileStyle == RigStatisticsMath::PercentileStyle::SWITCHED ) pValPosition = 1.0 - pValPosition;
|
||||
|
||||
double doubleIndex = ( sortedValues.size() - 1 ) * pValPosition;
|
||||
|
||||
size_t lowerValueIndex = static_cast<size_t>( floor( doubleIndex ) );
|
||||
size_t upperValueIndex = lowerValueIndex + 1;
|
||||
@@ -315,12 +335,16 @@ void RigHistogramCalculator::addData( const std::vector<float>& data )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RigHistogramCalculator::calculatePercentil( double pVal )
|
||||
double RigHistogramCalculator::calculatePercentil( double pVal, RigStatisticsMath::PercentileStyle percentileStyle )
|
||||
{
|
||||
assert( m_histogram );
|
||||
assert( m_histogram->size() );
|
||||
auto pValClamped = cvf::Math::clamp( pVal, 0.0, 1.0 );
|
||||
assert( 0.0 <= pValClamped && pValClamped <= 1.0 );
|
||||
if ( percentileStyle == RigStatisticsMath::PercentileStyle::SWITCHED )
|
||||
{
|
||||
pValClamped = 1.0 - pValClamped;
|
||||
}
|
||||
|
||||
double pValObservationCount = pValClamped * m_observationCount;
|
||||
if ( pValObservationCount == 0.0 ) return m_min;
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
class RigStatisticsMath
|
||||
{
|
||||
public:
|
||||
enum class PercentileStyle
|
||||
{
|
||||
REGULAR,
|
||||
SWITCHED
|
||||
};
|
||||
|
||||
static void calculateBasicStatistics( const std::vector<double>& values,
|
||||
double* min,
|
||||
double* max,
|
||||
@@ -34,13 +40,21 @@ public:
|
||||
double* range,
|
||||
double* mean,
|
||||
double* dev );
|
||||
static void
|
||||
calculateStatisticsCurves( const std::vector<double>& values, double* p10, double* p50, double* p90, double* mean );
|
||||
|
||||
static void calculateStatisticsCurves( const std::vector<double>& values,
|
||||
double* p10,
|
||||
double* p50,
|
||||
double* p90,
|
||||
double* mean,
|
||||
PercentileStyle percentileStyle );
|
||||
|
||||
static std::vector<double> calculateNearestRankPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions );
|
||||
const std::vector<double>& pValPositions,
|
||||
PercentileStyle percentileStyle );
|
||||
|
||||
static std::vector<double> calculateInterpolatedPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions );
|
||||
const std::vector<double>& pValPositions,
|
||||
PercentileStyle percentileStyle );
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@@ -61,7 +75,7 @@ public:
|
||||
/// the percentile is the domain value at which pVal of the observations are below it.
|
||||
/// Will only consider observed values between min and max, as all other values are discarded from the histogram
|
||||
|
||||
double calculatePercentil( double pVal );
|
||||
double calculatePercentil( double pVal, RigStatisticsMath::PercentileStyle percentileStyle );
|
||||
|
||||
private:
|
||||
size_t m_maxIndex;
|
||||
|
||||
Reference in New Issue
Block a user