OnlineStatistics.cpp
//==============================================================================
// Recalculates internal state, taking the provided unitless sample into account
//==============================================================================
Recalculates internal state, taking the provided unitless sample into account
Recalculates internal state taking the provided unitless sample into account
void OnlineStatistics::update(double sample)
{
    ++sample_count;
    double last_mean = mean;
    mean += (sample - mean) / sample_count;
    varianceSource += (sample - mean) * (sample - last_mean);
    if (sample_count == 1)
    {
        maximum = sample;
        minimum = sample;
    }
    else
    {
        if (sample > maximum)
        {
            maximum = sample;
        }
        if (sample < minimum)
        {
            minimum = sample;
        }
    }
}
void OnlineStatistics :: update ( double sample ) { ++ sample_count ; double last_mean = mean ; mean += ( sample - mean ) / sample_count ; varianceSource += ( sample - mean ) * ( sample - last_mean ) ; if ( sample_count == 1 ) { maximum = sample ; minimum = sample ; } else { if ( sample > maximum ) { maximum = sample ; } if ( sample < minimum ) { minimum = sample ; } } }
Recalculates internal state, taking the provided unitless sample into account
Recalculates internal state taking the provided unitless sample into account
// We've been given a new sample so increment the sample counter // Update statistics // We need to retain the old mean for the variance calculation below // Update the mean // Update the variance // If this sample is the only sample we've ever received then it must be // both the smallest and largest sample ever received // Is this sample larger than any sample yet received? // Is this sample smaller than any sample yet received?