Skip to content
Permalink
Browse files

optimize varianceFromCellValues()

  • Loading branch information
root676 authored and nyalldawson committed Jul 2, 2020
1 parent cf6e634 commit 294ad083ed75c45f1c27370243ddc196c3910e56
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/analysis/processing/qgsrasteranalysisutils.cpp
@@ -348,7 +348,13 @@ double QgsRasterAnalysisUtils::stddevFromCellValues( std::vector<double> cellVal

double QgsRasterAnalysisUtils::varianceFromCellValues( std::vector<double> cellValues, int stackSize )
{
double variance = std::pow( stddevFromCellValues( cellValues, stackSize ), 2.0 );
double mean = meanFromCellValues( cellValues, stackSize );
double accum = 0.0;
for ( int i = 0; i < stackSize; i++ )
{
accum += std::pow( ( cellValues.at( i ) - mean ), 2.0 );
}
double variance = accum / static_cast<double>( stackSize );
return variance;
}

0 comments on commit 294ad08

Please sign in to comment.
You can’t perform that action at this time.