stdlib-js / stdlib

✨ Standard library for JavaScript and Node.js. ✨
https://stdlib.io
Apache License 2.0
4.18k stars 405 forks source link

[RFC]: add `stats/incr/mkurtosis` #14

Open kgryte opened 7 years ago

kgryte commented 7 years ago

Moving incremental kurtosis. See also @stdlib/stats/incr/kurtosis for the non-moving version.

For similar packages, see https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr.

headlessNode commented 3 months ago

@kgryte I'd like to work on this issue. I was wondering if you could provide some guidance on how to get started with it or perhaps point me to a similar implementation for reference?

kgryte commented 3 months ago

@headlessNode A couple of links:

As can be inferred from the variance implementations, the key thing to figure out are the update equations. Once a window is filled, for each new value, the oldest value must be removed.

Similar to mvariance, we should support providing an optional known mean parameter. When providing a known mean, this also affects the update equations, as one no longer needs to compute the mean at the same time as the kurtosis.

headlessNode commented 3 months ago

@kgryte I've gone through the variance and mvariance code. I understand the implementations about both the accumulator1 and accumulator2, in case of both variance and mvariance.

From what I understood, the need for accumulator2 arises due to presence of optional mean parameter. So, in case of mkurtosis, we'd have both the accumulator1 and accumulator2.

I will now go through the kurtosis code, but I wanted to confirm what you mean by the update equations when you say that the key thing to figure out are the update equations? Do you mean the part of the code where the moment, mu, and delta are being calculated?

kgryte commented 3 months ago

@headlessNode Yes, that is correct. It may be straightforward to implement, but IIRC can be a little tricky getting the update equations into a nice form amenable to a single-pass window implementation. That's the point behind the long comment in https://github.com/stdlib-js/stdlib/blob/378c108278799749f256989970815ad6b263a3e8/lib/node_modules/%40stdlib/stats/incr/mvariance/lib/main.js#L91.

headlessNode commented 3 months ago

@kgryte Does this mean that we need to, first, derive equations for implementation of moving kurtosis? If so, I'm willing to do it, but I would need a starting point and some guidance to ensure I'm on the right track.

kgryte commented 3 months ago

You may; TBH, I am not sure. I'd need to do the R&D. I suggest consulting the reference literature linked to in the incr/kurtosis package and starting from there.

headlessNode commented 3 months ago

@kgryte First of all I want apologize for my recursive inquiries. And Thank you for your patience and guidance.

I was looking through other similar issues, mainly incr/wvariance and following the literature in #46 , I stumbled across some literature which were deriving numerically stable equations for weighted variance. I also found the equations for incr/variance and some other methods.

Although I haven't found something for mkurtosis yet, that is what you meant here right? Finding more numerically stable equations for our implementation of the methods?

kgryte commented 3 months ago

Yes, it may be quite likely you'd need to derive the update equations yourself. IIRC, I remember sitting down with pen and paper when originally implementing kurtosis and skewness.