Skip to content

Conversation

@robertogallea
Copy link

Since variance (or standard deviation) can be computed incrementally, it could be very useful to add it to the available Pulse aggregates.

The formula for its incremental computation is the following:

s_n^2 = (n-2)/(n-1)s_{n-1}^2 + (1/n)(X_n - X'_{n-1})^2

where

  • s_n^2 is the updated variance
  • *s_{n-1} is the previous variance
  • n is the number of samples
  • X_n is the upcoming sample
  • X'_{n-1} is the previous mean value

The only issue preventing me from submitting a complete PR is the fact that the computation requires the mean at the previous step, which altough could be available in the aggregates table, is not directly accessible during the upsert, so a choice has to be done for the strategy used to fetch it from the database.

Some viable solution could be:

  • When variance is requested, also the mean aggregate is automatically registered and its results are (re)used during variance computation;
  • Add an extra column in the aggregates table where to store the mean value only for this specific aggregate;
  • other proposals?

…usage

It adds an example test with the usage of the `var()` aggregate function
Update DatabaseStorageTest.php with an example of variance aggregate …
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants