Skip to content

Commit

Permalink
Reduce time for assessing the number of analogues.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalhorton committed Jul 19, 2017
1 parent 2c32002 commit aad616e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 55 deletions.
57 changes: 24 additions & 33 deletions src/app_optimizer/core/asMethodCalibrator.cpp
Expand Up @@ -1828,31 +1828,34 @@ bool asMethodCalibrator::SubProcessAnalogsNumber(asParametersCalibration &params
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]);
Expand All @@ -1874,30 +1877,18 @@ bool asMethodCalibrator::SubProcessAnalogsNumber(asParametersCalibration &params
}

} 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;
}
}
Expand Down
16 changes: 1 addition & 15 deletions src/app_optimizer/core/asScoreDF0.cpp
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/shared_base/core/asResults.cpp
Expand Up @@ -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;
}

Expand All @@ -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;
}

0 comments on commit aad616e

Please sign in to comment.