#6567 Remove use of GNU GSL

This commit is contained in:
Gaute Lindkvist 2020-09-23 15:48:19 +02:00
parent 2741b24e27
commit 9afac51bca
15 changed files with 32 additions and 231 deletions

3
.gitmodules vendored
View File

@ -1,9 +1,6 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg
[submodule "ThirdParty/gsl"]
path = ThirdParty/gsl
url = https://github.com/ampl/gsl/
[submodule "ThirdParty/qwt"]
path = ThirdParty/qwt
url = https://github.com/CeetronSolutions/qwt.git

View File

@ -25,10 +25,6 @@
#include "cafAssert.h"
#ifdef USE_GSL
#include "gsl/statistics/gsl_statistics_double.h"
#endif
#include <QString>
//--------------------------------------------------------------------------------------------------
@ -68,32 +64,6 @@ double RiaStatisticsTools::pearsonCorrelation( const std::vector<double>& xValue
RigStatisticsMath::calculateBasicStatistics( yValues, nullptr, nullptr, nullptr, &rangeY, nullptr, nullptr );
if ( rangeX < eps || rangeY < eps ) return 0.0;
#ifdef USE_GSL
return pearsonCorrelationGSL( xValues, yValues );
#else
return pearsonCorrelationOwn( xValues, yValues );
#endif
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RiaStatisticsTools::pearsonCorrelationGSL( const std::vector<double>& xValues, const std::vector<double>& yValues )
{
#ifdef USE_GSL
return gsl_stats_correlation( xValues.data(), 1, yValues.data(), 1, xValues.size() );
#else
CAF_ASSERT( false );
return std::numeric_limits<double>::infinity();
#endif
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RiaStatisticsTools::pearsonCorrelationOwn( const std::vector<double>& xValues, const std::vector<double>& yValues )
{
const double eps = 1.0e-8;
if ( xValues.size() != yValues.size() ) return 0.0;
if ( xValues.empty() ) return 0.0;
@ -124,22 +94,3 @@ double RiaStatisticsTools::pearsonCorrelationOwn( const std::vector<double>& xVa
return sumNumerator / ( std::sqrt( sumxDiffSquared ) * std::sqrt( sumyDiffSquared ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RiaStatisticsTools::spearmanCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues )
{
const double eps = 1.0e-8;
double rangeX = 0.0, rangeY = 0.0;
RigStatisticsMath::calculateBasicStatistics( xValues, nullptr, nullptr, nullptr, &rangeX, nullptr, nullptr );
RigStatisticsMath::calculateBasicStatistics( yValues, nullptr, nullptr, nullptr, &rangeY, nullptr, nullptr );
if ( rangeX < eps || rangeY < eps ) return 0.0;
#ifdef USE_GSL
std::vector<double> work( 2 * xValues.size() );
return gsl_stats_spearman( xValues.data(), 1, yValues.data(), 1, xValues.size(), work.data() );
#else
return 0.0;
#endif
}

View File

@ -52,7 +52,4 @@ public:
}
static double pearsonCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues );
static double pearsonCorrelationGSL( const std::vector<double>& xValues, const std::vector<double>& yValues );
static double pearsonCorrelationOwn( const std::vector<double>& xValues, const std::vector<double>& yValues );
static double spearmanCorrelation( const std::vector<double>& xValues, const std::vector<double>& yValues );
};

View File

@ -152,8 +152,6 @@ RimCorrelationMatrixPlot::RimCorrelationMatrixPlot()
{
CAF_PDM_InitObject( "Correlation Plot", ":/CorrelationMatrixPlot16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_correlationFactor, "CorrelationFactor", "Correlation Factor", "", "", "" );
m_correlationFactor.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
CAF_PDM_InitField( &m_showAbsoluteValues, "CorrelationAbsValues", false, "Show Absolute Values", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_sortByValues, "CorrelationSorting", "Sort Matrix by Values", "", "", "" );
CAF_PDM_InitField( &m_sortByAbsoluteValues, "CorrelationAbsSorting", true, "Sort by Absolute Values", "", "", "" );
@ -192,14 +190,6 @@ RimCorrelationMatrixPlot::~RimCorrelationMatrixPlot()
cleanupBeforeClose();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCorrelationMatrixPlot::CorrelationFactor RimCorrelationMatrixPlot::correlationFactor() const
{
return m_correlationFactor();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -264,10 +254,10 @@ void RimCorrelationMatrixPlot::fieldChangedByUi( const caf::PdmFieldHandle* chan
const QVariant& newValue )
{
RimAbstractCorrelationPlot::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_correlationFactor || changedField == &m_showAbsoluteValues ||
changedField == &m_sortByValues || changedField == &m_sortByAbsoluteValues ||
changedField == &m_showOnlyTopNCorrelations || changedField == &m_topNFilterCount ||
changedField == &m_excludeParametersWithoutVariation || changedField == &m_selectedParametersList )
if ( changedField == &m_showAbsoluteValues || changedField == &m_sortByValues ||
changedField == &m_sortByAbsoluteValues || changedField == &m_showOnlyTopNCorrelations ||
changedField == &m_topNFilterCount || changedField == &m_excludeParametersWithoutVariation ||
changedField == &m_selectedParametersList )
{
if ( changedField == &m_excludeParametersWithoutVariation )
{
@ -284,8 +274,7 @@ void RimCorrelationMatrixPlot::fieldChangedByUi( const caf::PdmFieldHandle* chan
//--------------------------------------------------------------------------------------------------
void RimCorrelationMatrixPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
caf::PdmUiGroup* correlationGroup = uiOrdering.addNewGroup( "Correlation Factor Settings" );
correlationGroup->add( &m_correlationFactor );
caf::PdmUiGroup* correlationGroup = uiOrdering.addNewGroup( "Correlation Settings" );
correlationGroup->add( &m_excludeParametersWithoutVariation );
correlationGroup->add( &m_selectedParametersList );
correlationGroup->add( &m_showAbsoluteValues );
@ -553,14 +542,7 @@ void RimCorrelationMatrixPlot::createMatrix()
if ( parameterValues.empty() ) continue;
if ( m_correlationFactor == CorrelationFactor::PEARSON )
{
correlation = RiaStatisticsTools::pearsonCorrelation( parameterValues, caseValuesAtTimestep );
}
else
{
correlation = RiaStatisticsTools::spearmanCorrelation( parameterValues, caseValuesAtTimestep );
}
correlation = RiaStatisticsTools::pearsonCorrelation( parameterValues, caseValuesAtTimestep );
bool validResult = RiaCurveDataTools::isValidValue( correlation, false );
if ( validResult )
@ -655,9 +637,7 @@ void RimCorrelationMatrixPlot::updatePlotTitle()
{
if ( m_useAutoPlotTitle )
{
m_description = QString( "%1 Matrix for Parameters vs Result Vectors at %2" )
.arg( m_correlationFactor().uiText() )
.arg( timeStepString() );
m_description = QString( "Correlation Matrix for Parameters vs Result Vectors at %2" ).arg( timeStepString() );
}
if ( m_plotWidget )

View File

@ -39,9 +39,6 @@ public:
caf::Signal<std::pair<QString, RiaSummaryCurveDefinition>> matrixCellSelected;
public:
using CorrelationFactor = RimCorrelationPlot::CorrelationFactor;
using CorrelationFactorEnum = RimCorrelationPlot::CorrelationFactorEnum;
enum class Sorting
{
NO_SORTING,
@ -55,7 +52,6 @@ public:
RimCorrelationMatrixPlot();
~RimCorrelationMatrixPlot() override;
CorrelationFactor correlationFactor() const;
bool showAbsoluteValues() const;
bool sortByAbsoluteValues() const;
RimRegularLegendConfig* legendConfig();
@ -85,14 +81,13 @@ private:
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex ) override;
private:
caf::PdmField<CorrelationFactorEnum> m_correlationFactor;
caf::PdmField<bool> m_showAbsoluteValues;
caf::PdmField<SortingEnum> m_sortByValues;
caf::PdmField<bool> m_sortByAbsoluteValues;
caf::PdmField<bool> m_excludeParametersWithoutVariation;
caf::PdmField<bool> m_showOnlyTopNCorrelations;
caf::PdmField<int> m_topNFilterCount;
caf::PdmField<std::vector<QString>> m_selectedParametersList;
caf::PdmField<bool> m_showAbsoluteValues;
caf::PdmField<SortingEnum> m_sortByValues;
caf::PdmField<bool> m_sortByAbsoluteValues;
caf::PdmField<bool> m_excludeParametersWithoutVariation;
caf::PdmField<bool> m_showOnlyTopNCorrelations;
caf::PdmField<int> m_topNFilterCount;
caf::PdmField<std::vector<QString>> m_selectedParametersList;
caf::PdmChildField<RimRegularLegendConfig*> m_legendConfig;

View File

@ -47,19 +47,6 @@
#include <map>
#include <set>
namespace caf
{
template <>
void caf::AppEnum<RimCorrelationPlot::CorrelationFactor>::setUp()
{
addItem( RimCorrelationPlot::CorrelationFactor::PEARSON, "PEARSON", "Pearson Correlation Coefficient" );
#ifdef USE_GSL
addItem( RimCorrelationPlot::CorrelationFactor::SPEARMAN, "SPEARMAN", "Spearman's Rank Correlation Coefficient" );
#endif
setDefault( RimCorrelationPlot::CorrelationFactor::PEARSON );
}
} // namespace caf
CAF_PDM_SOURCE_INIT( RimCorrelationPlot, "CorrelationPlot" );
//--------------------------------------------------------------------------------------------------
@ -71,8 +58,6 @@ RimCorrelationPlot::RimCorrelationPlot()
{
CAF_PDM_InitObject( "Correlation Tornado Plot", ":/CorrelationTornadoPlot16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_correlationFactor, "CorrelationFactor", "Correlation Factor", "", "", "" );
m_correlationFactor.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
CAF_PDM_InitField( &m_showAbsoluteValues, "CorrelationAbsValues", false, "Show Absolute Values", "", "", "" );
CAF_PDM_InitField( &m_sortByAbsoluteValues, "CorrelationAbsSorting", true, "Sort by Absolute Values", "", "", "" );
CAF_PDM_InitField( &m_excludeParametersWithoutVariation,
@ -111,10 +96,9 @@ void RimCorrelationPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedFie
const QVariant& newValue )
{
RimAbstractCorrelationPlot::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_correlationFactor || changedField == &m_showAbsoluteValues ||
changedField == &m_sortByAbsoluteValues || changedField == &m_excludeParametersWithoutVariation ||
changedField == &m_selectedParametersList || changedField == &m_showOnlyTopNCorrelations ||
changedField == &m_topNFilterCount )
if ( changedField == &m_showAbsoluteValues || changedField == &m_sortByAbsoluteValues ||
changedField == &m_excludeParametersWithoutVariation || changedField == &m_selectedParametersList ||
changedField == &m_showOnlyTopNCorrelations || changedField == &m_topNFilterCount )
{
if ( changedField == &m_excludeParametersWithoutVariation )
{
@ -130,8 +114,7 @@ void RimCorrelationPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedFie
//--------------------------------------------------------------------------------------------------
void RimCorrelationPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
caf::PdmUiGroup* correlationGroup = uiOrdering.addNewGroup( "Correlation Factor Settings" );
correlationGroup->add( &m_correlationFactor );
caf::PdmUiGroup* correlationGroup = uiOrdering.addNewGroup( "Correlation Settings" );
correlationGroup->add( &m_excludeParametersWithoutVariation );
correlationGroup->add( &m_selectedParametersList );
@ -264,10 +247,7 @@ void RimCorrelationPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chart
auto address = *addresses().begin();
std::vector<std::pair<EnsembleParameter, double>> correlations =
ensemble->parameterCorrelations( address,
selectedTimestep,
m_correlationFactor == CorrelationFactor::SPEARMAN,
m_selectedParametersList() );
ensemble->parameterCorrelations( address, selectedTimestep, m_selectedParametersList() );
QString timestepString = m_timeStep().toString( RiaPreferences::current()->dateTimeFormat() );
@ -290,11 +270,8 @@ void RimCorrelationPlot::updatePlotTitle()
if ( m_useAutoPlotTitle && !ensembles().empty() )
{
auto ensemble = *ensembles().begin();
m_description = QString( "%1 for %2, %3 at %4" )
.arg( m_correlationFactor().uiText() )
.arg( ensemble->name() )
.arg( m_selectedVarsUiField )
.arg( timeStepString() );
m_description =
QString( "Correlations for %2, %3 at %4" ).arg( ensemble->name() ).arg( m_selectedVarsUiField ).arg( timeStepString() );
}
m_plotWidget->setPlotTitle( m_description );
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && !isSubPlot() );
@ -321,22 +298,6 @@ void RimCorrelationPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle,
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCorrelationPlot::CorrelationFactor RimCorrelationPlot::correlationFactor() const
{
return m_correlationFactor();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationPlot::setCorrelationFactor( CorrelationFactor factor )
{
m_correlationFactor = factor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -40,21 +40,10 @@ class RimCorrelationPlot : public RimAbstractCorrelationPlot
public:
caf::Signal<std::pair<QString, RiaSummaryCurveDefinition>> tornadoItemSelected;
public:
enum class CorrelationFactor
{
PEARSON,
SPEARMAN
};
using CorrelationFactorEnum = caf::AppEnum<CorrelationFactor>;
public:
RimCorrelationPlot();
~RimCorrelationPlot() override;
CorrelationFactor correlationFactor() const;
void setCorrelationFactor( CorrelationFactor factor );
bool showAbsoluteValues() const;
void setShowAbsoluteValues( bool showAbsoluteValues );
@ -84,11 +73,10 @@ private:
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex ) override;
private:
caf::PdmField<CorrelationFactorEnum> m_correlationFactor;
caf::PdmField<bool> m_showAbsoluteValues;
caf::PdmField<bool> m_sortByAbsoluteValues;
caf::PdmField<bool> m_excludeParametersWithoutVariation;
caf::PdmField<bool> m_showOnlyTopNCorrelations;
caf::PdmField<int> m_topNFilterCount;
caf::PdmField<std::vector<QString>> m_selectedParametersList;
caf::PdmField<bool> m_showAbsoluteValues;
caf::PdmField<bool> m_sortByAbsoluteValues;
caf::PdmField<bool> m_excludeParametersWithoutVariation;
caf::PdmField<bool> m_showOnlyTopNCorrelations;
caf::PdmField<int> m_topNFilterCount;
caf::PdmField<std::vector<QString>> m_selectedParametersList;
};

View File

@ -320,7 +320,6 @@ void RimCorrelationReportPlot::onLoadDataAndUpdate()
m_parameterResultCrossPlot->setAxisTitleFontSize( m_axisTitleFontSize() );
m_parameterResultCrossPlot->setAxisValueFontSize( m_axisValueFontSize() );
m_correlationPlot->setCorrelationFactor( m_correlationMatrixPlot->correlationFactor() );
m_correlationPlot->setShowAbsoluteValues( m_correlationMatrixPlot->showAbsoluteValues() );
m_correlationPlot->setSortByAbsoluteValues( m_correlationMatrixPlot->sortByAbsoluteValues() );

View File

@ -38,8 +38,6 @@ class RiuMultiPlotPage;
class RimCorrelationReportPlot : public QObject, public RimPlotWindow
{
CAF_PDM_HEADER_INIT;
using CorrelationFactor = RimCorrelationPlot::CorrelationFactor;
using CorrelationFactorEnum = RimCorrelationPlot::CorrelationFactorEnum;
public:
RimCorrelationReportPlot();

View File

@ -519,7 +519,6 @@ time_t timeDiff( time_t lhs, time_t rhs )
std::vector<std::pair<EnsembleParameter, double>>
RimSummaryCaseCollection::parameterCorrelations( const RifEclipseSummaryAddress& address,
time_t timeStep,
bool spearman,
const std::vector<QString>& selectedParameters ) const
{
auto parameters = variationSortedEnsembleParameters( true );
@ -582,16 +581,8 @@ std::vector<std::pair<EnsembleParameter, double>>
for ( auto parameterValuesPair : parameterValues )
{
double correlation = 0.0;
if ( spearman )
{
double spearman = RiaStatisticsTools::spearmanCorrelation( parameterValuesPair.second, caseValuesAtTimestep );
if ( spearman != std::numeric_limits<double>::infinity() ) correlation = spearman;
}
else
{
double pearson = RiaStatisticsTools::pearsonCorrelation( parameterValuesPair.second, caseValuesAtTimestep );
if ( pearson != std::numeric_limits<double>::infinity() ) correlation = pearson;
}
double pearson = RiaStatisticsTools::pearsonCorrelation( parameterValuesPair.second, caseValuesAtTimestep );
if ( pearson != std::numeric_limits<double>::infinity() ) correlation = pearson;
correlationResults.push_back( std::make_pair( parameterValuesPair.first, correlation ) );
}
return correlationResults;
@ -602,7 +593,6 @@ std::vector<std::pair<EnsembleParameter, double>>
//--------------------------------------------------------------------------------------------------
std::vector<std::pair<EnsembleParameter, double>>
RimSummaryCaseCollection::parameterCorrelationsAllTimeSteps( const RifEclipseSummaryAddress& address,
bool spearman,
const std::vector<QString>& selectedParameters ) const
{
const size_t maxTimeStepCount = 10;
@ -617,7 +607,7 @@ std::vector<std::pair<EnsembleParameter, double>>
for ( size_t i = stride; i < timeStepsVector.size(); i += stride )
{
std::vector<std::pair<EnsembleParameter, double>> correlationsForTimeStep =
parameterCorrelations( address, timeStepsVector[i], spearman, selectedParameters );
parameterCorrelations( address, timeStepsVector[i], selectedParameters );
correlationsForChosenTimeSteps.push_back( correlationsForTimeStep );
}

View File

@ -122,11 +122,9 @@ public:
std::vector<std::pair<EnsembleParameter, double>>
parameterCorrelations( const RifEclipseSummaryAddress& address,
time_t selectedTimeStep,
bool spearman = false,
const std::vector<QString>& selectedParameters = {} ) const;
std::vector<std::pair<EnsembleParameter, double>>
parameterCorrelationsAllTimeSteps( const RifEclipseSummaryAddress& address,
bool spearman = false,
const std::vector<QString>& selectedParameters = {} ) const;
std::vector<EnsembleParameter> alphabeticEnsembleParameters() const;

View File

@ -83,27 +83,3 @@ TEST( RiaStatisticsTools, NegativeCorrelation )
double correlation = RiaStatisticsTools::pearsonCorrelation( a, b );
EXPECT_NEAR( correlation, -1.0, 1.0e-2 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
#ifdef USE_GSL
TEST( RiaStatisticsTools, ComparisonGSLAndOwn )
{
const int N = 1000;
std::vector<double> a, b;
a.reserve( N );
b.reserve( N );
for ( int i = 0; i < N; ++i )
{
a.push_back( (double)i );
}
for ( int i = 0; i < N; ++i )
{
b.push_back( (double)std::rand() );
}
double correlationGSL = RiaStatisticsTools::pearsonCorrelationGSL( a, b );
double correlationOwn = RiaStatisticsTools::pearsonCorrelationOwn( a, b );
EXPECT_NEAR( correlationGSL, correlationOwn, 1.0e-3 );
}
#endif

View File

@ -266,9 +266,7 @@ void RiuSummaryQwtPlot::contextMenuEvent( QContextMenuEvent* event )
menuBuilder.subMenuStart( "Cross Plots",
*caf::IconProvider( ":/CorrelationCrossPlot16x16.png" ).icon() );
std::vector<std::pair<EnsembleParameter, double>> ensembleParameters =
ensemble->parameterCorrelations( clickedEnsembleCurveSet->summaryAddress(),
timeStep,
false );
ensemble->parameterCorrelations( clickedEnsembleCurveSet->summaryAddress(), timeStep );
std::sort( ensembleParameters.begin(),
ensembleParameters.end(),
[]( const std::pair<EnsembleParameter, double>& lhs,

View File

@ -162,10 +162,7 @@ set(CMAKE_CXX_COMPILER_LAUNCHER ${TEMP_CMAKE_CXX_COMPILER_LAUNCHER})
# Go through required git submodules #
######################################
list(APPEND THIRD_PARTY_SUBMODULES qwt)
option(GSL_ENABLE "Enable the GNU Scientific Library for Statistics" OFF)
if(GSL_ENABLE)
list(APPEND THIRD_PARTY_SUBMODULES gsl)
endif(GSL_ENABLE)
###############################################
# Init GIT submodules if they haven't already #
###############################################
@ -361,29 +358,6 @@ set_property(TARGET
PROPERTY FOLDER "Thirdparty"
)
################################################################################
# GNU GSL
################################################################################
if(GSL_ENABLE)
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/ThirdParty/gsl/CMakeLists.txt")
message(FATAL_ERROR "The GSL submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
option(GSL_DISABLE_TESTS "Disable the GSL tests" ON)
set(GSL_INSTALL OFF)
add_subdirectory(ThirdParty/gsl)
add_definitions(-DUSE_GSL)
list(APPEND THIRD_PARTY_LIBRARIES gsl)
# set this property manually for all GSL projects, as they are put into a separate folder
set_property(TARGET
gsl
gslcblas
copy-headers
PROPERTY FOLDER "Thirdparty/GSL"
)
endif()
################################################################################
# Vizualization Framework
################################################################################

1
ThirdParty/gsl vendored

@ -1 +0,0 @@
Subproject commit f4564b1ffed5495041432fa8aa1550c0edf1d6ac