mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4683 clang-format on all files in ApplicationCode
This commit is contained in:
@@ -2,17 +2,17 @@
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -21,18 +21,17 @@
|
||||
|
||||
#include <cmath> // Needed for HUGE_VAL on Linux
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsCalculator::meanCellScalarValue(double& meanValue)
|
||||
void RigStatisticsCalculator::meanCellScalarValue( double& meanValue )
|
||||
{
|
||||
double valueSum = 0.0;
|
||||
double valueSum = 0.0;
|
||||
size_t sampleCount = 0;
|
||||
|
||||
this->valueSumAndSampleCount(valueSum, sampleCount);
|
||||
this->valueSumAndSampleCount( valueSum, sampleCount );
|
||||
|
||||
if (sampleCount == 0)
|
||||
if ( sampleCount == 0 )
|
||||
{
|
||||
meanValue = HUGE_VAL;
|
||||
}
|
||||
@@ -43,16 +42,16 @@ void RigStatisticsCalculator::meanCellScalarValue(double& meanValue)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsCalculator::meanCellScalarValue(size_t timeStepIndex, double& meanValue)
|
||||
void RigStatisticsCalculator::meanCellScalarValue( size_t timeStepIndex, double& meanValue )
|
||||
{
|
||||
double valueSum = 0.0;
|
||||
double valueSum = 0.0;
|
||||
size_t sampleCount = 0;
|
||||
|
||||
this->valueSumAndSampleCount(timeStepIndex, valueSum, sampleCount);
|
||||
this->valueSumAndSampleCount( timeStepIndex, valueSum, sampleCount );
|
||||
|
||||
if (sampleCount == 0)
|
||||
if ( sampleCount == 0 )
|
||||
{
|
||||
meanValue = HUGE_VAL;
|
||||
}
|
||||
@@ -60,80 +59,77 @@ void RigStatisticsCalculator::meanCellScalarValue(size_t timeStepIndex, double&
|
||||
{
|
||||
meanValue = valueSum / sampleCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsCalculator::valueSumAndSampleCount(double& valueSum, size_t& sampleCount)
|
||||
void RigStatisticsCalculator::valueSumAndSampleCount( double& valueSum, size_t& sampleCount )
|
||||
{
|
||||
size_t tsCount = this->timeStepCount();
|
||||
for (size_t tIdx = 0; tIdx < tsCount; tIdx++)
|
||||
for ( size_t tIdx = 0; tIdx < tsCount; tIdx++ )
|
||||
{
|
||||
this->valueSumAndSampleCount(tIdx, valueSum, sampleCount);
|
||||
this->valueSumAndSampleCount( tIdx, valueSum, sampleCount );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsCalculator::addDataToHistogramCalculator(RigHistogramCalculator& histogramCalculator)
|
||||
void RigStatisticsCalculator::addDataToHistogramCalculator( RigHistogramCalculator& histogramCalculator )
|
||||
{
|
||||
size_t tsCount = this->timeStepCount();
|
||||
for (size_t tIdx = 0; tIdx < tsCount; tIdx++)
|
||||
for ( size_t tIdx = 0; tIdx < tsCount; tIdx++ )
|
||||
{
|
||||
this->addDataToHistogramCalculator(tIdx, histogramCalculator);
|
||||
this->addDataToHistogramCalculator( tIdx, histogramCalculator );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsCalculator::mobileVolumeWeightedMean(size_t timeStepIndex, double& mean)
|
||||
{}
|
||||
void RigStatisticsCalculator::mobileVolumeWeightedMean( size_t timeStepIndex, double& mean ) {}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsCalculator::mobileVolumeWeightedMean(double& mean)
|
||||
void RigStatisticsCalculator::mobileVolumeWeightedMean( double& mean )
|
||||
{
|
||||
double sum = 0.0;
|
||||
double sum = 0.0;
|
||||
size_t tsCount = this->timeStepCount();
|
||||
for (size_t tIdx = 0; tIdx < tsCount; tIdx++)
|
||||
for ( size_t tIdx = 0; tIdx < tsCount; tIdx++ )
|
||||
{
|
||||
double meanForTimeStep;
|
||||
this->mobileVolumeWeightedMean(tIdx, meanForTimeStep);
|
||||
this->mobileVolumeWeightedMean( tIdx, meanForTimeStep );
|
||||
sum += meanForTimeStep;
|
||||
}
|
||||
if (tsCount != 0)
|
||||
if ( tsCount != 0 )
|
||||
{
|
||||
mean = sum / tsCount;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsCalculator::posNegClosestToZero(const std::vector<double>& values, double& pos, double& neg)
|
||||
void RigStatisticsCalculator::posNegClosestToZero( const std::vector<double>& values, double& pos, double& neg )
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < values.size(); i++)
|
||||
for ( i = 0; i < values.size(); i++ )
|
||||
{
|
||||
if (values[i] == HUGE_VAL)
|
||||
if ( values[i] == HUGE_VAL )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (values[i] < pos && values[i] > 0)
|
||||
if ( values[i] < pos && values[i] > 0 )
|
||||
{
|
||||
pos = values[i];
|
||||
}
|
||||
|
||||
if (values[i] > neg && values[i] < 0)
|
||||
if ( values[i] > neg && values[i] < 0 )
|
||||
{
|
||||
neg = values[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,24 +2,23 @@
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "cvfCollection.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
@@ -28,29 +27,29 @@
|
||||
class RigHistogramCalculator;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RigStatisticsCalculator : public cvf::Object
|
||||
{
|
||||
public:
|
||||
virtual void minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max) = 0;
|
||||
virtual void posNegClosestToZero(size_t timeStepIndex, double& pos, double& neg) = 0;
|
||||
|
||||
void meanCellScalarValue(double& meanValue);
|
||||
void meanCellScalarValue(size_t timeStepIndex, double& meanValue);
|
||||
virtual void minMaxCellScalarValues( size_t timeStepIndex, double& min, double& max ) = 0;
|
||||
virtual void posNegClosestToZero( size_t timeStepIndex, double& pos, double& neg ) = 0;
|
||||
|
||||
void valueSumAndSampleCount(double& valueSum, size_t& sampleCount);
|
||||
virtual void valueSumAndSampleCount(size_t timeStepIndex, double& valueSum, size_t& sampleCount) = 0;
|
||||
void meanCellScalarValue( double& meanValue );
|
||||
void meanCellScalarValue( size_t timeStepIndex, double& meanValue );
|
||||
|
||||
void addDataToHistogramCalculator(RigHistogramCalculator& histogramCalculator);
|
||||
virtual void addDataToHistogramCalculator(size_t timeStepIndex, RigHistogramCalculator& histogramCalculator) = 0;
|
||||
void valueSumAndSampleCount( double& valueSum, size_t& sampleCount );
|
||||
virtual void valueSumAndSampleCount( size_t timeStepIndex, double& valueSum, size_t& sampleCount ) = 0;
|
||||
|
||||
virtual void uniqueValues(size_t timeStepIndex, std::set<int>& values) = 0;
|
||||
void addDataToHistogramCalculator( RigHistogramCalculator& histogramCalculator );
|
||||
virtual void addDataToHistogramCalculator( size_t timeStepIndex, RigHistogramCalculator& histogramCalculator ) = 0;
|
||||
|
||||
virtual size_t timeStepCount() = 0;
|
||||
virtual void uniqueValues( size_t timeStepIndex, std::set<int>& values ) = 0;
|
||||
|
||||
void mobileVolumeWeightedMean(double& mean);
|
||||
virtual void mobileVolumeWeightedMean(size_t timeStepIndex, double& mean);
|
||||
virtual size_t timeStepCount() = 0;
|
||||
|
||||
static void posNegClosestToZero(const std::vector<double>& values, double& pos, double& neg);
|
||||
void mobileVolumeWeightedMean( double& mean );
|
||||
virtual void mobileVolumeWeightedMean( size_t timeStepIndex, double& mean );
|
||||
|
||||
static void posNegClosestToZero( const std::vector<double>& values, double& pos, double& neg );
|
||||
};
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -24,20 +24,19 @@
|
||||
|
||||
#include <cmath> // Needed for HUGE_VAL on Linux
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigStatisticsDataCache::RigStatisticsDataCache(RigStatisticsCalculator* statisticsCalculator)
|
||||
: m_statisticsCalculator(statisticsCalculator)
|
||||
RigStatisticsDataCache::RigStatisticsDataCache( RigStatisticsCalculator* statisticsCalculator )
|
||||
: m_statisticsCalculator( statisticsCalculator )
|
||||
{
|
||||
CVF_ASSERT(m_statisticsCalculator.notNull());
|
||||
CVF_ASSERT( m_statisticsCalculator.notNull() );
|
||||
|
||||
clearAllStatistics();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::clearAllStatistics()
|
||||
{
|
||||
@@ -46,26 +45,26 @@ void RigStatisticsDataCache::clearAllStatistics()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::minMaxCellScalarValues(double& min, double& max)
|
||||
void RigStatisticsDataCache::minMaxCellScalarValues( double& min, double& max )
|
||||
{
|
||||
if (!m_statsAllTimesteps.m_isMaxMinCalculated)
|
||||
if ( !m_statsAllTimesteps.m_isMaxMinCalculated )
|
||||
{
|
||||
min = HUGE_VAL;
|
||||
max = -HUGE_VAL;
|
||||
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < m_statisticsCalculator->timeStepCount(); i++)
|
||||
for ( i = 0; i < m_statisticsCalculator->timeStepCount(); i++ )
|
||||
{
|
||||
double tsmin, tsmax;
|
||||
this->minMaxCellScalarValues(i, tsmin, tsmax);
|
||||
if (tsmin < min) min = tsmin;
|
||||
if (tsmax > max) max = tsmax;
|
||||
this->minMaxCellScalarValues( i, tsmin, tsmax );
|
||||
if ( tsmin < min ) min = tsmin;
|
||||
if ( tsmax > max ) max = tsmax;
|
||||
}
|
||||
|
||||
m_statsAllTimesteps.m_minValue = min;
|
||||
m_statsAllTimesteps.m_maxValue = max;
|
||||
m_statsAllTimesteps.m_minValue = min;
|
||||
m_statsAllTimesteps.m_maxValue = max;
|
||||
m_statsAllTimesteps.m_isMaxMinCalculated = true;
|
||||
}
|
||||
|
||||
@@ -74,21 +73,21 @@ void RigStatisticsDataCache::minMaxCellScalarValues(double& min, double& max)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max)
|
||||
void RigStatisticsDataCache::minMaxCellScalarValues( size_t timeStepIndex, double& min, double& max )
|
||||
{
|
||||
if (timeStepIndex >= m_statsPrTs.size())
|
||||
if ( timeStepIndex >= m_statsPrTs.size() )
|
||||
{
|
||||
m_statsPrTs.resize(timeStepIndex + 1);
|
||||
m_statsPrTs.resize( timeStepIndex + 1 );
|
||||
}
|
||||
|
||||
if (!m_statsPrTs[timeStepIndex].m_isMaxMinCalculated)
|
||||
if ( !m_statsPrTs[timeStepIndex].m_isMaxMinCalculated )
|
||||
{
|
||||
double tsMin = HUGE_VAL;
|
||||
double tsMax = -HUGE_VAL;
|
||||
|
||||
m_statisticsCalculator->minMaxCellScalarValues(timeStepIndex, tsMin, tsMax);
|
||||
m_statisticsCalculator->minMaxCellScalarValues( timeStepIndex, tsMin, tsMax );
|
||||
|
||||
m_statsPrTs[timeStepIndex].m_minValue = tsMin;
|
||||
m_statsPrTs[timeStepIndex].m_maxValue = tsMax;
|
||||
@@ -101,26 +100,26 @@ void RigStatisticsDataCache::minMaxCellScalarValues(size_t timeStepIndex, double
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::posNegClosestToZero(double& pos, double& neg)
|
||||
void RigStatisticsDataCache::posNegClosestToZero( double& pos, double& neg )
|
||||
{
|
||||
if (!m_statsAllTimesteps.m_isClosestToZeroCalculated)
|
||||
if ( !m_statsAllTimesteps.m_isClosestToZeroCalculated )
|
||||
{
|
||||
pos = HUGE_VAL;
|
||||
neg = -HUGE_VAL;
|
||||
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < m_statisticsCalculator->timeStepCount(); i++)
|
||||
for ( i = 0; i < m_statisticsCalculator->timeStepCount(); i++ )
|
||||
{
|
||||
double tsNeg, tsPos;
|
||||
this->posNegClosestToZero(i, tsPos, tsNeg);
|
||||
if (tsNeg > neg && tsNeg < 0) neg = tsNeg;
|
||||
if (tsPos < pos && tsPos > 0) pos = tsPos;
|
||||
this->posNegClosestToZero( i, tsPos, tsNeg );
|
||||
if ( tsNeg > neg && tsNeg < 0 ) neg = tsNeg;
|
||||
if ( tsPos < pos && tsPos > 0 ) pos = tsPos;
|
||||
}
|
||||
|
||||
m_statsAllTimesteps.m_posClosestToZero = pos;
|
||||
m_statsAllTimesteps.m_negClosestToZero = neg;
|
||||
m_statsAllTimesteps.m_posClosestToZero = pos;
|
||||
m_statsAllTimesteps.m_negClosestToZero = neg;
|
||||
m_statsAllTimesteps.m_isClosestToZeroCalculated = true;
|
||||
}
|
||||
|
||||
@@ -129,22 +128,21 @@ void RigStatisticsDataCache::posNegClosestToZero(double& pos, double& neg)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::posNegClosestToZero(size_t timeStepIndex, double& posNearZero, double& negNearZero)
|
||||
void RigStatisticsDataCache::posNegClosestToZero( size_t timeStepIndex, double& posNearZero, double& negNearZero )
|
||||
{
|
||||
if (timeStepIndex >= m_statsPrTs.size())
|
||||
if ( timeStepIndex >= m_statsPrTs.size() )
|
||||
{
|
||||
m_statsPrTs.resize(timeStepIndex + 1);
|
||||
m_statsPrTs.resize( timeStepIndex + 1 );
|
||||
}
|
||||
|
||||
if (!m_statsPrTs[timeStepIndex].m_isClosestToZeroCalculated)
|
||||
if ( !m_statsPrTs[timeStepIndex].m_isClosestToZeroCalculated )
|
||||
{
|
||||
|
||||
double pos = HUGE_VAL;
|
||||
double neg = -HUGE_VAL;
|
||||
|
||||
m_statisticsCalculator->posNegClosestToZero(timeStepIndex, pos, neg);
|
||||
|
||||
m_statisticsCalculator->posNegClosestToZero( timeStepIndex, pos, neg );
|
||||
|
||||
m_statsPrTs[timeStepIndex].m_posClosestToZero = pos;
|
||||
m_statsPrTs[timeStepIndex].m_negClosestToZero = neg;
|
||||
@@ -156,13 +154,13 @@ void RigStatisticsDataCache::posNegClosestToZero(size_t timeStepIndex, double& p
|
||||
negNearZero = m_statsPrTs[timeStepIndex].m_negClosestToZero;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::meanCellScalarValues(double& meanValue)
|
||||
void RigStatisticsDataCache::meanCellScalarValues( double& meanValue )
|
||||
{
|
||||
if (!m_statsAllTimesteps.m_isMeanCalculated)
|
||||
if ( !m_statsAllTimesteps.m_isMeanCalculated )
|
||||
{
|
||||
m_statisticsCalculator->meanCellScalarValue(m_statsAllTimesteps.m_meanValue);
|
||||
m_statisticsCalculator->meanCellScalarValue( m_statsAllTimesteps.m_meanValue );
|
||||
|
||||
m_statsAllTimesteps.m_isMeanCalculated = true;
|
||||
}
|
||||
@@ -171,42 +169,41 @@ void RigStatisticsDataCache::meanCellScalarValues(double& meanValue)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::meanCellScalarValues(size_t timeStepIndex, double& meanValue)
|
||||
void RigStatisticsDataCache::meanCellScalarValues( size_t timeStepIndex, double& meanValue )
|
||||
{
|
||||
if (timeStepIndex >= m_statsPrTs.size())
|
||||
if ( timeStepIndex >= m_statsPrTs.size() )
|
||||
{
|
||||
m_statsPrTs.resize(timeStepIndex + 1);
|
||||
m_statsPrTs.resize( timeStepIndex + 1 );
|
||||
}
|
||||
|
||||
if (!m_statsPrTs[timeStepIndex].m_isMeanCalculated)
|
||||
if ( !m_statsPrTs[timeStepIndex].m_isMeanCalculated )
|
||||
{
|
||||
m_statisticsCalculator->meanCellScalarValue(timeStepIndex, m_statsPrTs[timeStepIndex].m_meanValue);
|
||||
m_statisticsCalculator->meanCellScalarValue( timeStepIndex, m_statsPrTs[timeStepIndex].m_meanValue );
|
||||
m_statsPrTs[timeStepIndex].m_isMeanCalculated = true;
|
||||
}
|
||||
|
||||
meanValue = m_statsPrTs[timeStepIndex].m_meanValue;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::sumCellScalarValues(double& sumValue)
|
||||
void RigStatisticsDataCache::sumCellScalarValues( double& sumValue )
|
||||
{
|
||||
if (!m_statsAllTimesteps.m_isValueSumCalculated)
|
||||
if ( !m_statsAllTimesteps.m_isValueSumCalculated )
|
||||
{
|
||||
double aggregatedSum = 0.0;
|
||||
for (size_t i = 0; i < m_statisticsCalculator->timeStepCount(); i++)
|
||||
for ( size_t i = 0; i < m_statisticsCalculator->timeStepCount(); i++ )
|
||||
{
|
||||
double valueSum = 0.0;
|
||||
this->sumCellScalarValues(i, valueSum);
|
||||
this->sumCellScalarValues( i, valueSum );
|
||||
|
||||
aggregatedSum += valueSum;
|
||||
}
|
||||
|
||||
m_statsAllTimesteps.m_valueSum = aggregatedSum;
|
||||
m_statsAllTimesteps.m_valueSum = aggregatedSum;
|
||||
m_statsAllTimesteps.m_isValueSumCalculated = true;
|
||||
}
|
||||
|
||||
@@ -214,21 +211,21 @@ void RigStatisticsDataCache::sumCellScalarValues(double& sumValue)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::sumCellScalarValues(size_t timeStepIndex, double& sumValue)
|
||||
void RigStatisticsDataCache::sumCellScalarValues( size_t timeStepIndex, double& sumValue )
|
||||
{
|
||||
if (timeStepIndex >= m_statsPrTs.size())
|
||||
if ( timeStepIndex >= m_statsPrTs.size() )
|
||||
{
|
||||
m_statsPrTs.resize(timeStepIndex + 1);
|
||||
m_statsPrTs.resize( timeStepIndex + 1 );
|
||||
}
|
||||
|
||||
if (!m_statsPrTs[timeStepIndex].m_isValueSumCalculated)
|
||||
if ( !m_statsPrTs[timeStepIndex].m_isValueSumCalculated )
|
||||
{
|
||||
double valueSum = 0.0;
|
||||
double valueSum = 0.0;
|
||||
size_t sampleCount = 0;
|
||||
m_statisticsCalculator->valueSumAndSampleCount(timeStepIndex, valueSum, sampleCount);
|
||||
m_statsPrTs[timeStepIndex].m_valueSum = valueSum;
|
||||
m_statisticsCalculator->valueSumAndSampleCount( timeStepIndex, valueSum, sampleCount );
|
||||
m_statsPrTs[timeStepIndex].m_valueSum = valueSum;
|
||||
m_statsPrTs[timeStepIndex].m_isValueSumCalculated = true;
|
||||
}
|
||||
|
||||
@@ -236,7 +233,7 @@ void RigStatisticsDataCache::sumCellScalarValues(size_t timeStepIndex, double& s
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<size_t>& RigStatisticsDataCache::cellScalarValuesHistogram()
|
||||
{
|
||||
@@ -246,17 +243,17 @@ const std::vector<size_t>& RigStatisticsDataCache::cellScalarValuesHistogram()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<size_t>& RigStatisticsDataCache::cellScalarValuesHistogram(size_t timeStepIndex)
|
||||
const std::vector<size_t>& RigStatisticsDataCache::cellScalarValuesHistogram( size_t timeStepIndex )
|
||||
{
|
||||
computeHistogramStatisticsIfNeeded(timeStepIndex);
|
||||
computeHistogramStatisticsIfNeeded( timeStepIndex );
|
||||
|
||||
return m_statsPrTs[timeStepIndex].m_histogram;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<int>& RigStatisticsDataCache::uniqueCellScalarValues()
|
||||
{
|
||||
@@ -266,41 +263,41 @@ const std::vector<int>& RigStatisticsDataCache::uniqueCellScalarValues()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<int>& RigStatisticsDataCache::uniqueCellScalarValues(size_t timeStepIndex)
|
||||
const std::vector<int>& RigStatisticsDataCache::uniqueCellScalarValues( size_t timeStepIndex )
|
||||
{
|
||||
computeUniqueValuesIfNeeded(timeStepIndex);
|
||||
computeUniqueValuesIfNeeded( timeStepIndex );
|
||||
|
||||
return m_statsPrTs[timeStepIndex].m_uniqueValues;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::mobileVolumeWeightedMean(size_t timeStepIndex, double& mean)
|
||||
void RigStatisticsDataCache::mobileVolumeWeightedMean( size_t timeStepIndex, double& mean )
|
||||
{
|
||||
if (timeStepIndex >= m_statsPrTs.size())
|
||||
if ( timeStepIndex >= m_statsPrTs.size() )
|
||||
{
|
||||
m_statsPrTs.resize(timeStepIndex + 1);
|
||||
m_statsPrTs.resize( timeStepIndex + 1 );
|
||||
}
|
||||
|
||||
if (!m_statsPrTs[timeStepIndex].m_isVolumeWeightedMeanCalculated)
|
||||
if ( !m_statsPrTs[timeStepIndex].m_isVolumeWeightedMeanCalculated )
|
||||
{
|
||||
m_statisticsCalculator->mobileVolumeWeightedMean(timeStepIndex, m_statsPrTs[timeStepIndex].m_volumeWeightedMean);
|
||||
m_statisticsCalculator->mobileVolumeWeightedMean( timeStepIndex, m_statsPrTs[timeStepIndex].m_volumeWeightedMean );
|
||||
}
|
||||
|
||||
mean = m_statsPrTs[timeStepIndex].m_volumeWeightedMean;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::mobileVolumeWeightedMean(double& mean)
|
||||
void RigStatisticsDataCache::mobileVolumeWeightedMean( double& mean )
|
||||
{
|
||||
if (!m_statsAllTimesteps.m_isVolumeWeightedMeanCalculated)
|
||||
if ( !m_statsAllTimesteps.m_isVolumeWeightedMeanCalculated )
|
||||
{
|
||||
m_statisticsCalculator->mobileVolumeWeightedMean(m_statsAllTimesteps.m_volumeWeightedMean);
|
||||
m_statisticsCalculator->mobileVolumeWeightedMean( m_statsAllTimesteps.m_volumeWeightedMean );
|
||||
|
||||
m_statsAllTimesteps.m_isVolumeWeightedMeanCalculated = true;
|
||||
}
|
||||
@@ -309,9 +306,9 @@ void RigStatisticsDataCache::mobileVolumeWeightedMean(double& mean)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::p10p90CellScalarValues(double& p10, double& p90)
|
||||
void RigStatisticsDataCache::p10p90CellScalarValues( double& p10, double& p90 )
|
||||
{
|
||||
computeHistogramStatisticsIfNeeded();
|
||||
|
||||
@@ -320,88 +317,89 @@ void RigStatisticsDataCache::p10p90CellScalarValues(double& p10, double& p90)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::p10p90CellScalarValues(size_t timeStepIndex, double& p10, double& p90)
|
||||
void RigStatisticsDataCache::p10p90CellScalarValues( size_t timeStepIndex, double& p10, double& p90 )
|
||||
{
|
||||
computeHistogramStatisticsIfNeeded(timeStepIndex);
|
||||
computeHistogramStatisticsIfNeeded( timeStepIndex );
|
||||
|
||||
p10 = m_statsPrTs[timeStepIndex].m_p10;
|
||||
p90 = m_statsPrTs[timeStepIndex].m_p90;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::computeHistogramStatisticsIfNeeded()
|
||||
{
|
||||
if (m_statsAllTimesteps.m_histogram.size() == 0)
|
||||
if ( m_statsAllTimesteps.m_histogram.size() == 0 )
|
||||
{
|
||||
double min;
|
||||
double max;
|
||||
size_t nBins = 100;
|
||||
this->minMaxCellScalarValues(min, max);
|
||||
this->minMaxCellScalarValues( min, max );
|
||||
|
||||
RigHistogramCalculator histCalc(min, max, nBins, &m_statsAllTimesteps.m_histogram);
|
||||
RigHistogramCalculator histCalc( min, max, nBins, &m_statsAllTimesteps.m_histogram );
|
||||
|
||||
m_statisticsCalculator->addDataToHistogramCalculator(histCalc);
|
||||
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 );
|
||||
m_statsAllTimesteps.m_p90 = histCalc.calculatePercentil( 0.9 );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::computeHistogramStatisticsIfNeeded(size_t timeStepIndex)
|
||||
void RigStatisticsDataCache::computeHistogramStatisticsIfNeeded( size_t timeStepIndex )
|
||||
{
|
||||
if (m_statsPrTs[timeStepIndex].m_histogram.size() == 0)
|
||||
if ( m_statsPrTs[timeStepIndex].m_histogram.size() == 0 )
|
||||
{
|
||||
double min;
|
||||
double max;
|
||||
size_t nBins = 100;
|
||||
this->minMaxCellScalarValues(timeStepIndex, min, max);
|
||||
this->minMaxCellScalarValues( timeStepIndex, min, max );
|
||||
|
||||
RigHistogramCalculator histCalc(min, max, nBins, &m_statsPrTs[timeStepIndex].m_histogram);
|
||||
RigHistogramCalculator histCalc( min, max, nBins, &m_statsPrTs[timeStepIndex].m_histogram );
|
||||
|
||||
m_statisticsCalculator->addDataToHistogramCalculator(timeStepIndex, histCalc);
|
||||
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 );
|
||||
m_statsPrTs[timeStepIndex].m_p90 = histCalc.calculatePercentil( 0.9 );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::computeUniqueValuesIfNeeded()
|
||||
{
|
||||
if (m_statsAllTimesteps.m_uniqueValues.size() == 0)
|
||||
if ( m_statsAllTimesteps.m_uniqueValues.size() == 0 )
|
||||
{
|
||||
std::set<int> setValues;
|
||||
m_statisticsCalculator->uniqueValues(0, setValues); // This is a Hack ! Only using first timestep. Ok for Static eclipse results but beware !
|
||||
m_statisticsCalculator->uniqueValues( 0, setValues ); // This is a Hack ! Only using first timestep. Ok for
|
||||
// Static eclipse results but beware !
|
||||
|
||||
for (auto val : setValues)
|
||||
for ( auto val : setValues )
|
||||
{
|
||||
m_statsAllTimesteps.m_uniqueValues.push_back(val);
|
||||
m_statsAllTimesteps.m_uniqueValues.push_back( val );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsDataCache::computeUniqueValuesIfNeeded(size_t timeStepIndex)
|
||||
void RigStatisticsDataCache::computeUniqueValuesIfNeeded( size_t timeStepIndex )
|
||||
{
|
||||
if ( m_statsPrTs[timeStepIndex].m_uniqueValues.size() == 0 )
|
||||
{
|
||||
std::set<int> setValues;
|
||||
m_statisticsCalculator->uniqueValues(timeStepIndex, setValues);
|
||||
m_statisticsCalculator->uniqueValues( timeStepIndex, setValues );
|
||||
|
||||
for ( auto val : setValues )
|
||||
{
|
||||
m_statsPrTs[timeStepIndex].m_uniqueValues.push_back(val);
|
||||
m_statsPrTs[timeStepIndex].m_uniqueValues.push_back( val );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -21,52 +21,51 @@
|
||||
|
||||
#include "RigStatisticsCalculator.h"
|
||||
|
||||
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include <vector>
|
||||
#include <cmath> // Needed for HUGE_VAL on Linux
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RigStatisticsDataCache : public cvf::Object
|
||||
{
|
||||
public:
|
||||
explicit RigStatisticsDataCache(RigStatisticsCalculator* statisticsCalculator);
|
||||
explicit RigStatisticsDataCache( RigStatisticsCalculator* statisticsCalculator );
|
||||
|
||||
void clearAllStatistics();
|
||||
void clearAllStatistics();
|
||||
|
||||
void minMaxCellScalarValues(double& min, double& max);
|
||||
void minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max);
|
||||
void minMaxCellScalarValues( double& min, double& max );
|
||||
void minMaxCellScalarValues( size_t timeStepIndex, double& min, double& max );
|
||||
|
||||
void posNegClosestToZero(double& pos, double& neg);
|
||||
void posNegClosestToZero(size_t timeStepIndex, double& pos, double& neg);
|
||||
void posNegClosestToZero( double& pos, double& neg );
|
||||
void posNegClosestToZero( size_t timeStepIndex, double& pos, double& neg );
|
||||
|
||||
void p10p90CellScalarValues(double& p10, double& p90);
|
||||
void p10p90CellScalarValues(size_t timeStepIndex, double& p10, double& p90);
|
||||
void p10p90CellScalarValues( double& p10, double& p90 );
|
||||
void p10p90CellScalarValues( size_t timeStepIndex, double& p10, double& p90 );
|
||||
|
||||
void meanCellScalarValues(double& meanValue);
|
||||
void meanCellScalarValues(size_t timeStepIndex, double& meanValue);
|
||||
void meanCellScalarValues( double& meanValue );
|
||||
void meanCellScalarValues( size_t timeStepIndex, double& meanValue );
|
||||
|
||||
void sumCellScalarValues(double& sumValue);
|
||||
void sumCellScalarValues(size_t timeStepIndex, double& sumValue);
|
||||
void sumCellScalarValues( double& sumValue );
|
||||
void sumCellScalarValues( size_t timeStepIndex, double& sumValue );
|
||||
|
||||
const std::vector<size_t>& cellScalarValuesHistogram();
|
||||
const std::vector<size_t>& cellScalarValuesHistogram(size_t timeStepIndex);
|
||||
const std::vector<size_t>& cellScalarValuesHistogram();
|
||||
const std::vector<size_t>& cellScalarValuesHistogram( size_t timeStepIndex );
|
||||
|
||||
const std::vector<int>& uniqueCellScalarValues();
|
||||
const std::vector<int>& uniqueCellScalarValues(size_t timeStepIndex);
|
||||
|
||||
void mobileVolumeWeightedMean(double& mean);
|
||||
void mobileVolumeWeightedMean(size_t timeStepIndex, double& mean);
|
||||
const std::vector<int>& uniqueCellScalarValues();
|
||||
const std::vector<int>& uniqueCellScalarValues( size_t timeStepIndex );
|
||||
|
||||
void mobileVolumeWeightedMean( double& mean );
|
||||
void mobileVolumeWeightedMean( size_t timeStepIndex, double& mean );
|
||||
|
||||
private:
|
||||
void computeHistogramStatisticsIfNeeded();
|
||||
void computeHistogramStatisticsIfNeeded(size_t timeStepIndex);
|
||||
void computeHistogramStatisticsIfNeeded();
|
||||
void computeHistogramStatisticsIfNeeded( size_t timeStepIndex );
|
||||
|
||||
void computeUniqueValuesIfNeeded();
|
||||
void computeUniqueValuesIfNeeded(size_t timeStepIndex);
|
||||
void computeUniqueValuesIfNeeded();
|
||||
void computeUniqueValuesIfNeeded( size_t timeStepIndex );
|
||||
|
||||
private:
|
||||
struct StatisticsValues
|
||||
@@ -89,34 +88,32 @@ private:
|
||||
m_isVolumeWeightedMeanCalculated = false;
|
||||
}
|
||||
|
||||
double m_minValue;
|
||||
double m_maxValue;
|
||||
bool m_isMaxMinCalculated;
|
||||
|
||||
double m_meanValue;
|
||||
bool m_isMeanCalculated;
|
||||
double m_minValue;
|
||||
double m_maxValue;
|
||||
bool m_isMaxMinCalculated;
|
||||
|
||||
double m_posClosestToZero;
|
||||
double m_negClosestToZero;
|
||||
bool m_isClosestToZeroCalculated;
|
||||
|
||||
double m_p10;
|
||||
double m_p90;
|
||||
double m_meanValue;
|
||||
bool m_isMeanCalculated;
|
||||
|
||||
double m_valueSum;
|
||||
bool m_isValueSumCalculated;
|
||||
double m_posClosestToZero;
|
||||
double m_negClosestToZero;
|
||||
bool m_isClosestToZeroCalculated;
|
||||
|
||||
double m_volumeWeightedMean;
|
||||
bool m_isVolumeWeightedMeanCalculated;
|
||||
double m_p10;
|
||||
double m_p90;
|
||||
|
||||
double m_valueSum;
|
||||
bool m_isValueSumCalculated;
|
||||
|
||||
double m_volumeWeightedMean;
|
||||
bool m_isVolumeWeightedMeanCalculated;
|
||||
|
||||
std::vector<size_t> m_histogram;
|
||||
std::vector<int> m_uniqueValues;
|
||||
};
|
||||
|
||||
StatisticsValues m_statsAllTimesteps;
|
||||
std::vector<StatisticsValues> m_statsPrTs;
|
||||
|
||||
StatisticsValues m_statsAllTimesteps;
|
||||
std::vector<StatisticsValues> m_statsPrTs;
|
||||
|
||||
cvf::ref<RigStatisticsCalculator> m_statisticsCalculator;
|
||||
cvf::ref<RigStatisticsCalculator> m_statisticsCalculator;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RigStatisticsMath.h"
|
||||
|
||||
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -26,70 +25,67 @@
|
||||
#include <math.h>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// A function to do basic statistical calculations
|
||||
/// A function to do basic statistical calculations
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
void RigStatisticsMath::calculateBasicStatistics(const std::vector<double>& values, double* min, double* max, double* sum, double* range, double* mean, double* dev)
|
||||
void RigStatisticsMath::calculateBasicStatistics(
|
||||
const std::vector<double>& values, double* min, double* max, double* sum, double* range, double* mean, double* dev )
|
||||
{
|
||||
double m_min(HUGE_VAL);
|
||||
double m_max(-HUGE_VAL);
|
||||
double m_mean(HUGE_VAL);
|
||||
double m_dev(HUGE_VAL);
|
||||
double m_min( HUGE_VAL );
|
||||
double m_max( -HUGE_VAL );
|
||||
double m_mean( HUGE_VAL );
|
||||
double m_dev( HUGE_VAL );
|
||||
|
||||
double m_sum = 0.0;
|
||||
double m_sum = 0.0;
|
||||
double sumSquared = 0.0;
|
||||
|
||||
size_t validValueCount = 0;
|
||||
|
||||
for (size_t i = 0; i < values.size(); i++)
|
||||
for ( size_t i = 0; i < values.size(); i++ )
|
||||
{
|
||||
double val = values[i];
|
||||
if (RiaStatisticsTools::isInvalidNumber<double>(val)) continue;
|
||||
if ( RiaStatisticsTools::isInvalidNumber<double>( val ) ) continue;
|
||||
|
||||
validValueCount++;
|
||||
|
||||
if (val < m_min) m_min = val;
|
||||
if (val > m_max) m_max = val;
|
||||
if ( val < m_min ) m_min = val;
|
||||
if ( val > m_max ) m_max = val;
|
||||
|
||||
m_sum += val;
|
||||
sumSquared += (val * val);
|
||||
sumSquared += ( val * val );
|
||||
}
|
||||
|
||||
if (validValueCount > 0)
|
||||
if ( validValueCount > 0 )
|
||||
{
|
||||
m_mean = m_sum / validValueCount;
|
||||
|
||||
// http://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods
|
||||
// Running standard deviation
|
||||
|
||||
double s0 = static_cast<double>(validValueCount);
|
||||
double s0 = static_cast<double>( validValueCount );
|
||||
double s1 = m_sum;
|
||||
double s2 = sumSquared;
|
||||
|
||||
m_dev = sqrt( (s0 * s2) - (s1 * s1) ) / s0;
|
||||
m_dev = sqrt( ( s0 * s2 ) - ( s1 * s1 ) ) / s0;
|
||||
}
|
||||
|
||||
if (min) *min = m_min;
|
||||
if (max) *max = m_max;
|
||||
if (sum) *sum = m_sum;
|
||||
if (range) *range = m_max - m_min;
|
||||
if ( min ) *min = m_min;
|
||||
if ( max ) *max = m_max;
|
||||
if ( sum ) *sum = m_sum;
|
||||
if ( range ) *range = m_max - m_min;
|
||||
|
||||
if (mean) *mean = m_mean;
|
||||
if (dev) *dev = m_dev;
|
||||
if ( mean ) *mean = m_mean;
|
||||
if ( dev ) *dev = m_dev;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Algorithm:
|
||||
/// https://en.wikipedia.org/wiki/Percentile#Third_variant,_'%22%60UNIQ--postMath-00000052-QINU%60%22'
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigStatisticsMath::calculateStatisticsCurves(const std::vector<double>& values,
|
||||
double* p10,
|
||||
double* p50,
|
||||
double* p90,
|
||||
double* mean)
|
||||
void RigStatisticsMath::calculateStatisticsCurves(
|
||||
const std::vector<double>& values, double* p10, double* p50, double* p90, double* mean )
|
||||
{
|
||||
CVF_ASSERT(p10 && p50 && p90 && mean);
|
||||
CVF_ASSERT( p10 && p50 && p90 && mean );
|
||||
|
||||
enum PValue
|
||||
{
|
||||
@@ -102,12 +98,12 @@ void RigStatisticsMath::calculateStatisticsCurves(const std::vector<double>& val
|
||||
double valueSum = 0;
|
||||
|
||||
{
|
||||
std::multiset<double> vSet(values.begin(), values.end());
|
||||
for (double v : vSet)
|
||||
std::multiset<double> vSet( values.begin(), values.end() );
|
||||
for ( double v : vSet )
|
||||
{
|
||||
if (RiaStatisticsTools::isValidNumber(v))
|
||||
if ( RiaStatisticsTools::isValidNumber( v ) )
|
||||
{
|
||||
sortedValues.push_back(v);
|
||||
sortedValues.push_back( v );
|
||||
valueSum += v;
|
||||
}
|
||||
}
|
||||
@@ -117,21 +113,21 @@ void RigStatisticsMath::calculateStatisticsCurves(const std::vector<double>& val
|
||||
double percentiles[] = {0.1, 0.5, 0.9};
|
||||
double pValues[] = {HUGE_VAL, HUGE_VAL, HUGE_VAL};
|
||||
|
||||
for (int i = P10; i <= P90; i++)
|
||||
for ( int i = P10; i <= P90; i++ )
|
||||
{
|
||||
// Check valid params
|
||||
if ((percentiles[i] < 1.0 / ((double)valueCount + 1)) || (percentiles[i] > (double)valueCount / ((double)valueCount + 1)))
|
||||
if ( ( percentiles[i] < 1.0 / ( (double)valueCount + 1 ) ) ||
|
||||
( percentiles[i] > (double)valueCount / ( (double)valueCount + 1 ) ) )
|
||||
continue;
|
||||
|
||||
double rank = percentiles[i] * (valueCount + 1) - 1;
|
||||
double rank = percentiles[i] * ( valueCount + 1 ) - 1;
|
||||
double rankRem;
|
||||
double rankFrac = std::modf(rank, &rankRem);
|
||||
int rankInt = static_cast<int>(rankRem);
|
||||
double rankFrac = std::modf( rank, &rankRem );
|
||||
int rankInt = static_cast<int>( rankRem );
|
||||
|
||||
|
||||
if (rankInt < valueCount - 1)
|
||||
if ( rankInt < valueCount - 1 )
|
||||
{
|
||||
pValues[i] = sortedValues[rankInt] + rankFrac * (sortedValues[rankInt + 1] - sortedValues[rankInt]);
|
||||
pValues[i] = sortedValues[rankInt] + rankFrac * ( sortedValues[rankInt + 1] - sortedValues[rankInt] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -151,33 +147,34 @@ void RigStatisticsMath::calculateStatisticsCurves(const std::vector<double>& val
|
||||
/// the inputValues does not contain any valid values
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
std::vector<double> RigStatisticsMath::calculateNearestRankPercentiles(const std::vector<double> & inputValues, const std::vector<double>& pValPositions)
|
||||
std::vector<double> RigStatisticsMath::calculateNearestRankPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions )
|
||||
{
|
||||
std::vector<double> sortedValues;
|
||||
sortedValues.reserve(inputValues.size());
|
||||
sortedValues.reserve( inputValues.size() );
|
||||
|
||||
for (size_t i = 0; i < inputValues.size(); ++i)
|
||||
for ( size_t i = 0; i < inputValues.size(); ++i )
|
||||
{
|
||||
if (RiaStatisticsTools::isValidNumber<double>(inputValues[i]))
|
||||
if ( RiaStatisticsTools::isValidNumber<double>( inputValues[i] ) )
|
||||
{
|
||||
sortedValues.push_back(inputValues[i]);
|
||||
sortedValues.push_back( inputValues[i] );
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(sortedValues.begin(), sortedValues.end());
|
||||
std::sort( sortedValues.begin(), sortedValues.end() );
|
||||
|
||||
std::vector<double> percentiles(pValPositions.size(), HUGE_VAL);
|
||||
if (sortedValues.size())
|
||||
std::vector<double> percentiles( pValPositions.size(), HUGE_VAL );
|
||||
if ( sortedValues.size() )
|
||||
{
|
||||
for (size_t i = 0; i < pValPositions.size(); ++i)
|
||||
for ( size_t i = 0; i < pValPositions.size(); ++i )
|
||||
{
|
||||
double pVal = HUGE_VAL;
|
||||
|
||||
size_t pValIndex = static_cast<size_t>(sortedValues.size() * cvf::Math::abs(pValPositions[i]) / 100);
|
||||
size_t pValIndex = static_cast<size_t>( sortedValues.size() * cvf::Math::abs( pValPositions[i] ) / 100 );
|
||||
|
||||
if (pValIndex >= sortedValues.size() ) pValIndex = sortedValues.size() - 1;
|
||||
if ( pValIndex >= sortedValues.size() ) pValIndex = sortedValues.size() - 1;
|
||||
|
||||
pVal = sortedValues[pValIndex];
|
||||
pVal = sortedValues[pValIndex];
|
||||
percentiles[i] = pVal;
|
||||
}
|
||||
}
|
||||
@@ -190,39 +187,41 @@ std::vector<double> RigStatisticsMath::calculateNearestRankPercentiles(const std
|
||||
/// This method treats HUGE_VAL as "undefined" values, and ignores these. Will return HUGE_VAL if
|
||||
/// the inputValues does not contain any valid values
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<double> RigStatisticsMath::calculateInterpolatedPercentiles(const std::vector<double> & inputValues, const std::vector<double>& pValPositions)
|
||||
std::vector<double> RigStatisticsMath::calculateInterpolatedPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions )
|
||||
{
|
||||
std::vector<double> sortedValues;
|
||||
sortedValues.reserve(inputValues.size());
|
||||
sortedValues.reserve( inputValues.size() );
|
||||
|
||||
for (size_t i = 0; i < inputValues.size(); ++i)
|
||||
for ( size_t i = 0; i < inputValues.size(); ++i )
|
||||
{
|
||||
if (RiaStatisticsTools::isValidNumber<double>(inputValues[i]))
|
||||
if ( RiaStatisticsTools::isValidNumber<double>( inputValues[i] ) )
|
||||
{
|
||||
sortedValues.push_back(inputValues[i]);
|
||||
sortedValues.push_back( inputValues[i] );
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(sortedValues.begin(), sortedValues.end());
|
||||
std::sort( sortedValues.begin(), sortedValues.end() );
|
||||
|
||||
std::vector<double> percentiles(pValPositions.size(), HUGE_VAL);
|
||||
if (sortedValues.size())
|
||||
std::vector<double> percentiles( pValPositions.size(), HUGE_VAL );
|
||||
if ( sortedValues.size() )
|
||||
{
|
||||
for (size_t i = 0; i < pValPositions.size(); ++i)
|
||||
for ( size_t i = 0; i < pValPositions.size(); ++i )
|
||||
{
|
||||
double pVal = HUGE_VAL;
|
||||
|
||||
double doubleIndex = (sortedValues.size() - 1) * cvf::Math::abs(pValPositions[i]) / 100.0;
|
||||
double doubleIndex = ( sortedValues.size() - 1 ) * cvf::Math::abs( 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;
|
||||
|
||||
double upperValueWeight = doubleIndex - lowerValueIndex;
|
||||
assert(upperValueWeight < 1.0);
|
||||
assert( upperValueWeight < 1.0 );
|
||||
|
||||
if (upperValueIndex < sortedValues.size())
|
||||
if ( upperValueIndex < sortedValues.size() )
|
||||
{
|
||||
pVal = (1.0 - upperValueWeight) * sortedValues[lowerValueIndex] + upperValueWeight * sortedValues[upperValueIndex];
|
||||
pVal = ( 1.0 - upperValueWeight ) * sortedValues[lowerValueIndex] +
|
||||
upperValueWeight * sortedValues[upperValueIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -236,101 +235,105 @@ std::vector<double> RigStatisticsMath::calculateInterpolatedPercentiles(const st
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RigHistogramCalculator::RigHistogramCalculator(double min, double max, size_t nBins, std::vector<size_t>* histogram)
|
||||
RigHistogramCalculator::RigHistogramCalculator( double min, double max, size_t nBins, std::vector<size_t>* histogram )
|
||||
{
|
||||
assert(histogram);
|
||||
assert(nBins > 0);
|
||||
assert( histogram );
|
||||
assert( nBins > 0 );
|
||||
|
||||
if (max == min) { nBins = 1; } // Avoid dividing on 0 range
|
||||
if ( max == min )
|
||||
{
|
||||
nBins = 1;
|
||||
} // Avoid dividing on 0 range
|
||||
|
||||
m_histogram = histogram;
|
||||
m_min = min;
|
||||
m_histogram = histogram;
|
||||
m_min = min;
|
||||
m_observationCount = 0;
|
||||
|
||||
// Initialize bins
|
||||
m_histogram->resize(nBins);
|
||||
for (size_t i = 0; i < m_histogram->size(); ++i) (*m_histogram)[i] = 0;
|
||||
m_histogram->resize( nBins );
|
||||
for ( size_t i = 0; i < m_histogram->size(); ++i )
|
||||
( *m_histogram )[i] = 0;
|
||||
|
||||
m_range = max - min;
|
||||
m_maxIndex = nBins-1;
|
||||
m_range = max - min;
|
||||
m_maxIndex = nBins - 1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigHistogramCalculator::addValue(double value)
|
||||
void RigHistogramCalculator::addValue( double value )
|
||||
{
|
||||
if (RiaStatisticsTools::isInvalidNumber<double>(value)) return;
|
||||
if ( RiaStatisticsTools::isInvalidNumber<double>( value ) ) return;
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
if (m_maxIndex > 0) index = (size_t)(m_maxIndex*(value - m_min)/m_range);
|
||||
if ( m_maxIndex > 0 ) index = ( size_t )( m_maxIndex * ( value - m_min ) / m_range );
|
||||
|
||||
if (index < m_histogram->size()) // Just clip to the max min range (-index will overflow to positive )
|
||||
if ( index < m_histogram->size() ) // Just clip to the max min range (-index will overflow to positive )
|
||||
{
|
||||
(*m_histogram)[index]++;
|
||||
( *m_histogram )[index]++;
|
||||
m_observationCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigHistogramCalculator::addData(const std::vector<double>& data)
|
||||
void RigHistogramCalculator::addData( const std::vector<double>& data )
|
||||
{
|
||||
assert(m_histogram);
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
assert( m_histogram );
|
||||
for ( size_t i = 0; i < data.size(); ++i )
|
||||
{
|
||||
addValue(data[i]);
|
||||
addValue( data[i] );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigHistogramCalculator::addData(const std::vector<float>& data)
|
||||
void RigHistogramCalculator::addData( const std::vector<float>& data )
|
||||
{
|
||||
assert(m_histogram);
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
assert( m_histogram );
|
||||
for ( size_t i = 0; i < data.size(); ++i )
|
||||
{
|
||||
addValue(data[i]);
|
||||
addValue( data[i] );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RigHistogramCalculator::calculatePercentil(double pVal)
|
||||
double RigHistogramCalculator::calculatePercentil( double pVal )
|
||||
{
|
||||
assert(m_histogram);
|
||||
assert(m_histogram->size());
|
||||
assert( 0.0 <= pVal && pVal <= 1.0);
|
||||
assert( m_histogram );
|
||||
assert( m_histogram->size() );
|
||||
assert( 0.0 <= pVal && pVal <= 1.0 );
|
||||
|
||||
double pValObservationCount = pVal*m_observationCount;
|
||||
if (pValObservationCount == 0.0) return m_min;
|
||||
double pValObservationCount = pVal * m_observationCount;
|
||||
if ( pValObservationCount == 0.0 ) return m_min;
|
||||
|
||||
size_t accObsCount = 0;
|
||||
double binWidth = m_range/m_histogram->size();
|
||||
for (size_t binIdx = 0; binIdx < m_histogram->size(); ++binIdx)
|
||||
double binWidth = m_range / m_histogram->size();
|
||||
for ( size_t binIdx = 0; binIdx < m_histogram->size(); ++binIdx )
|
||||
{
|
||||
size_t binObsCount = (*m_histogram)[binIdx];
|
||||
size_t binObsCount = ( *m_histogram )[binIdx];
|
||||
|
||||
accObsCount += binObsCount;
|
||||
if (accObsCount >= pValObservationCount)
|
||||
if ( accObsCount >= pValObservationCount )
|
||||
{
|
||||
double domainValueAtEndOfBin = m_min + (binIdx+1) * binWidth;
|
||||
double unusedFractionOfLastBin = (double)(accObsCount - pValObservationCount)/binObsCount;
|
||||
double domainValueAtEndOfBin = m_min + ( binIdx + 1 ) * binWidth;
|
||||
double unusedFractionOfLastBin = (double)( accObsCount - pValObservationCount ) / binObsCount;
|
||||
|
||||
double histogramBasedEstimate = domainValueAtEndOfBin - unusedFractionOfLastBin*binWidth;
|
||||
double histogramBasedEstimate = domainValueAtEndOfBin - unusedFractionOfLastBin * binWidth;
|
||||
|
||||
// See https://resinsight.org/docs/casegroupsandstatistics/#percentile-methods for details
|
||||
|
||||
return histogramBasedEstimate;
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
assert( false );
|
||||
|
||||
return HUGE_VAL;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -19,19 +19,28 @@
|
||||
|
||||
#include "RiaStatisticsTools.h"
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
class RigStatisticsMath
|
||||
{
|
||||
public:
|
||||
static void calculateBasicStatistics(const std::vector<double>& values, double* min, double* max, double* sum, double* range, double* mean, double* dev);
|
||||
static void calculateStatisticsCurves(const std::vector<double>& values, double* p10, double* p50, double* p90, double* mean);
|
||||
static void calculateBasicStatistics( const std::vector<double>& values,
|
||||
double* min,
|
||||
double* max,
|
||||
double* sum,
|
||||
double* range,
|
||||
double* mean,
|
||||
double* dev );
|
||||
static void calculateStatisticsCurves(
|
||||
const std::vector<double>& values, double* p10, double* p50, double* p90, double* mean );
|
||||
|
||||
static std::vector<double> calculateNearestRankPercentiles(const std::vector<double> & inputValues, const std::vector<double>& pValPositions);
|
||||
static std::vector<double> calculateInterpolatedPercentiles(const std::vector<double> & inputValues, const std::vector<double>& pValPositions);
|
||||
static std::vector<double> calculateNearestRankPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions );
|
||||
static std::vector<double> calculateInterpolatedPercentiles( const std::vector<double>& inputValues,
|
||||
const std::vector<double>& pValPositions );
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@@ -41,59 +50,62 @@ public:
|
||||
class RigHistogramCalculator
|
||||
{
|
||||
public:
|
||||
RigHistogramCalculator(double min, double max, size_t nBins, std::vector<size_t>* histogram);
|
||||
RigHistogramCalculator( double min, double max, size_t nBins, std::vector<size_t>* histogram );
|
||||
|
||||
void addData(const std::vector<double>& data);
|
||||
void addData(const std::vector<float>& data);
|
||||
void addData( const std::vector<double>& data );
|
||||
void addData( const std::vector<float>& data );
|
||||
|
||||
void addValue(double value);
|
||||
void addValue( double value );
|
||||
|
||||
/// Calculates the estimated percentile from the histogram.
|
||||
/// Calculates the estimated percentile from the histogram.
|
||||
/// 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 );
|
||||
|
||||
private:
|
||||
size_t m_maxIndex;
|
||||
double m_range;
|
||||
double m_min;
|
||||
size_t m_observationCount;
|
||||
size_t m_maxIndex;
|
||||
double m_range;
|
||||
double m_min;
|
||||
size_t m_observationCount;
|
||||
std::vector<size_t>* m_histogram;
|
||||
};
|
||||
|
||||
|
||||
class MinMaxAccumulator
|
||||
{
|
||||
public:
|
||||
MinMaxAccumulator(double initMin = HUGE_VAL, double initMax = -HUGE_VAL): max(initMax), min(initMin) {}
|
||||
|
||||
void addData(const std::vector<double>& values)
|
||||
MinMaxAccumulator( double initMin = HUGE_VAL, double initMax = -HUGE_VAL )
|
||||
: max( initMax )
|
||||
, min( initMin )
|
||||
{
|
||||
}
|
||||
|
||||
void addData( const std::vector<double>& values )
|
||||
{
|
||||
for ( double val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addData(const std::vector<float>& values)
|
||||
void addData( const std::vector<float>& values )
|
||||
{
|
||||
for ( float val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addValue(double value)
|
||||
void addValue( double value )
|
||||
{
|
||||
if (RiaStatisticsTools::isValidNumber<double>(value))
|
||||
if ( RiaStatisticsTools::isValidNumber<double>( value ) )
|
||||
{
|
||||
if (value < min)
|
||||
if ( value < min )
|
||||
{
|
||||
min = value;
|
||||
}
|
||||
|
||||
if (value > max)
|
||||
if ( value > max )
|
||||
{
|
||||
max = value;
|
||||
}
|
||||
@@ -104,38 +116,41 @@ public:
|
||||
double min;
|
||||
};
|
||||
|
||||
|
||||
class PosNegAccumulator
|
||||
{
|
||||
public:
|
||||
PosNegAccumulator(double initPos = HUGE_VAL, double initNeg = -HUGE_VAL): pos(initPos), neg(initNeg) {}
|
||||
|
||||
void addData(const std::vector<double>& values)
|
||||
PosNegAccumulator( double initPos = HUGE_VAL, double initNeg = -HUGE_VAL )
|
||||
: pos( initPos )
|
||||
, neg( initNeg )
|
||||
{
|
||||
for (double val : values)
|
||||
}
|
||||
|
||||
void addData( const std::vector<double>& values )
|
||||
{
|
||||
for ( double val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addData(const std::vector<float>& values)
|
||||
void addData( const std::vector<float>& values )
|
||||
{
|
||||
for ( float val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addValue(double value)
|
||||
void addValue( double value )
|
||||
{
|
||||
if (RiaStatisticsTools::isValidNumber<double>(value))
|
||||
if ( RiaStatisticsTools::isValidNumber<double>( value ) )
|
||||
{
|
||||
if (value < pos && value > 0)
|
||||
if ( value < pos && value > 0 )
|
||||
{
|
||||
pos = value;
|
||||
}
|
||||
|
||||
if (value > neg && value < 0)
|
||||
if ( value > neg && value < 0 )
|
||||
{
|
||||
neg = value;
|
||||
}
|
||||
@@ -146,31 +161,34 @@ public:
|
||||
double neg;
|
||||
};
|
||||
|
||||
|
||||
class SumCountAccumulator
|
||||
{
|
||||
public:
|
||||
SumCountAccumulator(double initSum = 0.0, size_t initCount = 0): valueSum(initSum), sampleCount(initCount) {}
|
||||
SumCountAccumulator( double initSum = 0.0, size_t initCount = 0 )
|
||||
: valueSum( initSum )
|
||||
, sampleCount( initCount )
|
||||
{
|
||||
}
|
||||
|
||||
void addData(const std::vector<double>& values)
|
||||
void addData( const std::vector<double>& values )
|
||||
{
|
||||
for ( double val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addData(const std::vector<float>& values)
|
||||
void addData( const std::vector<float>& values )
|
||||
{
|
||||
for ( float val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addValue(double value)
|
||||
void addValue( double value )
|
||||
{
|
||||
if (RiaStatisticsTools::isValidNumber<double>(value))
|
||||
if ( RiaStatisticsTools::isValidNumber<double>( value ) )
|
||||
{
|
||||
valueSum += value;
|
||||
++sampleCount;
|
||||
@@ -181,34 +199,32 @@ public:
|
||||
size_t sampleCount;
|
||||
};
|
||||
|
||||
|
||||
class UniqueValueAccumulator
|
||||
{
|
||||
public:
|
||||
UniqueValueAccumulator()
|
||||
{}
|
||||
UniqueValueAccumulator() {}
|
||||
|
||||
void addData(const std::vector<double>& values)
|
||||
void addData( const std::vector<double>& values )
|
||||
{
|
||||
for ( double val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addData(const std::vector<float>& values)
|
||||
void addData( const std::vector<float>& values )
|
||||
{
|
||||
for ( float val : values )
|
||||
{
|
||||
addValue(val);
|
||||
addValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
void addValue(double value)
|
||||
void addValue( double value )
|
||||
{
|
||||
if (RiaStatisticsTools::isValidNumber<double>(value))
|
||||
if ( RiaStatisticsTools::isValidNumber<double>( value ) )
|
||||
{
|
||||
uniqueValues.insert(static_cast<int>(value));
|
||||
uniqueValues.insert( static_cast<int>( value ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user