From aad616efd99ce89c9a6d7963eeb83818e2339466 Mon Sep 17 00:00:00 2001 From: Pascal Horton Date: Wed, 19 Jul 2017 14:50:38 +0200 Subject: [PATCH] Reduce time for assessing the number of analogues. --- src/app_optimizer/core/asMethodCalibrator.cpp | 57 ++++++++----------- src/app_optimizer/core/asScoreDF0.cpp | 16 +----- src/shared_base/core/asResults.cpp | 14 ++--- 3 files changed, 32 insertions(+), 55 deletions(-) diff --git a/src/app_optimizer/core/asMethodCalibrator.cpp b/src/app_optimizer/core/asMethodCalibrator.cpp index 68b6de96a..4e3247fd9 100644 --- a/src/app_optimizer/core/asMethodCalibrator.cpp +++ b/src/app_optimizer/core/asMethodCalibrator.cpp @@ -1828,31 +1828,34 @@ bool asMethodCalibrator::SubProcessAnalogsNumber(asParametersCalibration ¶ms return false; } + // Set the maximum and let play with the analogs nb on the score (faster) + params.SetAnalogsNumber(iStep, analogsNbVect[rowEnd]); + + // Process first the dates and the values + bool containsNaNs = false; + if (iStep == 0) { + if (!GetAnalogsDates(anaDates, params, iStep, containsNaNs)) + return false; + } else { + if (!GetAnalogsSubDates(anaDates, params, anaDatesPrevious, iStep, containsNaNs)) + return false; + } + if (containsNaNs) { + wxLogError(_("The dates selection contains NaNs")); + return false; + } + + asResultsDates anaDatesTmp(anaDates); + a2f dates = anaDates.GetAnalogsDates(); + // If at the end of the chain if (iStep == params.GetStepsNb() - 1) { - // Set the maximum and let play with the analogs nb on the score (faster) - params.SetAnalogsNumber(iStep, analogsNbVect[rowEnd]); - // Process first the dates and the values - bool containsNaNs = false; - if (iStep == 0) { - if (!GetAnalogsDates(anaDates, params, iStep, containsNaNs)) - return false; - } else { - if (!GetAnalogsSubDates(anaDates, params, anaDatesPrevious, iStep, containsNaNs)) - return false; - } - if (containsNaNs) { - wxLogError(_("The dates selection contains NaNs")); - return false; - } if (!GetAnalogsValues(anaValues, params, anaDates, iStep)) return false; asResultsScores anaScores; asResultsTotalScore anaScoreFinal; - asResultsDates anaDatesTmp(anaDates); - a2f dates = anaDates.GetAnalogsDates(); for (int i = 0; i <= rowEnd; i++) { params.SetAnalogsNumber(iStep, analogsNbVect[i]); @@ -1874,30 +1877,18 @@ bool asMethodCalibrator::SubProcessAnalogsNumber(asParametersCalibration ¶ms } } else { - int nextStep = iStep + 1; - for (int i = 0; i <= rowEnd; i++) { params.SetAnalogsNumber(iStep, analogsNbVect[i]); // Fixes and checks params.FixAnalogsNb(); - // Process the dates and the values - bool containsNaNs = false; - if (iStep == 0) { - if (!GetAnalogsDates(anaDates, params, iStep, containsNaNs)) - return false; - } else { - if (!GetAnalogsSubDates(anaDates, params, anaDatesPrevious, iStep, containsNaNs)) - return false; - } - if (containsNaNs) { - wxLogError(_("The dates selection contains NaNs")); - return false; - } + // Extract analogs dates from former results + a2f subDates = dates.leftCols(params.GetAnalogsNumber(iStep)); + anaDatesTmp.SetAnalogsDates(subDates); // Continue - if (!SubProcessAnalogsNumber(params, anaDates, nextStep)) + if (!SubProcessAnalogsNumber(params, anaDatesTmp, iStep + 1)) return false; } } diff --git a/src/app_optimizer/core/asScoreDF0.cpp b/src/app_optimizer/core/asScoreDF0.cpp index ed8dc6a22..4d364013d 100644 --- a/src/app_optimizer/core/asScoreDF0.cpp +++ b/src/app_optimizer/core/asScoreDF0.cpp @@ -72,8 +72,6 @@ float asScoreDF0::Assess(float ObservedVal, const a1f &ForcastVals, int nbElemen // Sort the forcast array asTools::SortArray(&x[0], &x[nbPredict - 1], Asc); - float score = 0; - // Cumulative frequency a1f F = asTools::GetCumulativeFrequency(nbPredict); @@ -85,16 +83,6 @@ float asScoreDF0::Assess(float ObservedVal, const a1f &ForcastVals, int nbElemen } } - // Display F(0)analog - bool dispF0 = false; - if (dispF0) { - if (indexLastZero >= 0) { - wxLogWarning("%f", F(indexLastZero)); - } else { - wxLogWarning("%d", 0); - } - } - // Find FxObs, fix xObs and integrate beyond limits float FxObs; if (xObs > 0.0) // If precipitation @@ -109,9 +97,7 @@ float asScoreDF0::Assess(float ObservedVal, const a1f &ForcastVals, int nbElemen return NaNf; } - score = std::abs((1.0f - F(indexLastZero)) - FxObs); - - return score; + return std::abs((1.0f - F(indexLastZero)) - FxObs); } bool asScoreDF0::ProcessScoreClimatology(const a1f &refVals, const a1f &climatologyData) diff --git a/src/shared_base/core/asResults.cpp b/src/shared_base/core/asResults.cpp index 7b44ae3cb..7e8678168 100644 --- a/src/shared_base/core/asResults.cpp +++ b/src/shared_base/core/asResults.cpp @@ -160,15 +160,15 @@ bool asResults::DefAnalogsValuesAttributes(asFileNetcdf &ncFile) const bool asResults::DefScoresAttributes(asFileNetcdf &ncFile) const { - ncFile.PutAtt("long_name", "Prediction scores", "prediction_scores"); - ncFile.PutAtt("var_desc", "Scores of the prediction resulting from the analog method", "prediction_scores"); + ncFile.PutAtt("long_name", "Prediction scores", "scores"); + ncFile.PutAtt("var_desc", "Scores of the prediction resulting from the analog method", "scores"); return true; } bool asResults::DefTotalScoreAttributes(asFileNetcdf &ncFile) const { - ncFile.PutAtt("long_name", "Final score", "prediction_score"); - ncFile.PutAtt("var_desc", "Final score of the method", "prediction_score"); + ncFile.PutAtt("long_name", "Final score", "score"); + ncFile.PutAtt("var_desc", "Final score of the method", "score"); return true; } @@ -181,8 +181,8 @@ bool asResults::DefLevelAttributes(asFileNetcdf &ncFile) const bool asResults::DefScoresMapAttributes(asFileNetcdf &ncFile) const { - ncFile.PutAtt("long_name", "Forecast score", "forecast_scores"); - ncFile.PutAtt("var_desc", "Map of the forecast scores", "forecast_scores"); - ncFile.PutAtt("units", "no unit", "forecast_scores"); + ncFile.PutAtt("long_name", "Prediction score", "scores"); + ncFile.PutAtt("var_desc", "Map of the scores", "scores"); + ncFile.PutAtt("units", "no unit", "scores"); return true; }