{"id":37124079,"url":"https://github.com/alexander-yu/stream","last_synced_at":"2026-01-14T14:19:34.310Z","repository":{"id":57523147,"uuid":"142592898","full_name":"alexander-yu/stream","owner":"alexander-yu","description":"An online statistics library, written in Go","archived":false,"fork":false,"pushed_at":"2025-03-10T21:44:28.000Z","size":1361,"stargazers_count":32,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T22:29:35.253Z","etag":null,"topics":["data-structures","go","golang","online-algorithms","statistics","stats","streaming-algorithms"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexander-yu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-27T15:15:43.000Z","updated_at":"2025-03-10T21:40:01.000Z","dependencies_parsed_at":"2024-06-20T23:21:52.100Z","dependency_job_id":"c71812f0-5003-4b03-a96b-b6c3e191d902","html_url":"https://github.com/alexander-yu/stream","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alexander-yu/stream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexander-yu%2Fstream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexander-yu%2Fstream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexander-yu%2Fstream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexander-yu%2Fstream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexander-yu","download_url":"https://codeload.github.com/alexander-yu/stream/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexander-yu%2Fstream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28422644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","go","golang","online-algorithms","statistics","stats","streaming-algorithms"],"created_at":"2026-01-14T14:19:33.607Z","updated_at":"2026-01-14T14:19:34.297Z","avatar_url":"https://github.com/alexander-yu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stream\r\n\r\n[![GoDoc](https://godoc.org/github.com/alexander-yu/stream?status.svg)](https://godoc.org/github.com/alexander-yu/stream)\r\n[![Build Status](https://travis-ci.org/alexander-yu/stream.svg?branch=master)](https://travis-ci.org/alexander-yu/stream)\r\n[![Go Report Card](https://goreportcard.com/badge/github.com/alexander-yu/stream)](https://goreportcard.com/report/github.com/alexander-yu/stream)\r\n[![codecov](https://codecov.io/gh/alexander-yu/stream/branch/master/graph/badge.svg)](https://codecov.io/gh/alexander-yu/stream)\r\n[![GitHub license](https://img.shields.io/github/license/alexander-yu/stream.svg)](https://github.com/alexander-yu/stream/blob/master/LICENSE)\r\n\r\nStream is a Go library for online statistical algorithms. Provided statistics can be computed globally over an entire stream, or over a rolling window.\r\n\r\n## Table of Contents\r\n\r\n- [Stream](#stream)\r\n  - [Table of Contents](#table-of-contents)\r\n  - [Installation](#installation)\r\n  - [Example Usage](#example-usage)\r\n  - [Statistics](#statistics)\r\n    - [Quantile](#quantile)\r\n      - [Quantile](#quantile-1)\r\n      - [Median](#median)\r\n      - [IQR](#iqr)\r\n      - [HeapMedian](#heapmedian)\r\n    - [Min/Max](#minmax)\r\n      - [Min](#min)\r\n      - [Max](#max)\r\n    - [Moment-Based Statistics](#moment-based-statistics)\r\n      - [Mean](#mean)\r\n      - [EWMA](#ewma)\r\n      - [Moment](#moment)\r\n      - [EWMMoment](#ewmmoment)\r\n      - [Std](#std)\r\n      - [EWMStd](#ewmstd)\r\n      - [Skewness](#skewness)\r\n      - [Kurtosis](#kurtosis)\r\n      - [Core (Univariate)](#core-univariate)\r\n    - [Joint Distribution Statistics](#joint-distribution-statistics)\r\n      - [Cov](#cov)\r\n      - [EWMCov](#ewmcov)\r\n      - [Corr](#corr)\r\n      - [EWMCorr](#ewmcorr)\r\n      - [Autocorr](#autocorr)\r\n      - [Autocov](#autocov)\r\n      - [Core (Multivariate)](#core-multivariate)\r\n    - [Aggregate Statistics](#aggregate-statistics)\r\n      - [SimpleAggregateMetric](#simpleaggregatemetric)\r\n      - [SimpleJointAggregateMetric](#simplejointaggregatemetric)\r\n\r\n## Installation\r\n\r\nUse `go get`:\r\n\r\n```bash\r\ngo get github.com/alexander-yu/stream\r\n```\r\n\r\n## Example Usage\r\n\r\nIn-depth examples are provided in the [examples](https://github.com/alexander-yu/stream/tree/master/examples) directory, but a small taste is provided below:\r\n\r\n```go\r\n// tracks the autocorrelation over a\r\n// rolling window of size 15 and lag of 5\r\nautocorr, err := joint.NewAutocorr(5, 15)\r\n// handle err\r\n\r\n// all metrics in the joint package must be passed\r\n// through joint.Init in order to consume values\r\nerr = joint.Init(autocorr)\r\n// handle err\r\n\r\n// tracks the global median using a pair of heaps\r\nmedian, err := quantile.NewGlobalHeapMedian()\r\n// handle err\r\n\r\nfor i := 0., i \u003c 100; i++ {\r\n    err = autocorr.Push(i)\r\n    // handle err\r\n\r\n    err = median.Push(i)\r\n    // handle err\r\n}\r\n\r\nautocorrVal, err := autocorr.Value()\r\n// handle err\r\n\r\nmedianVal, err := median.Value()\r\n// handle err\r\n\r\nfmt.Println(\"%s: %f\", autocorr.String(), autocorrVal)\r\nfmt.Println(\"%s: %f\", median.String(), medianVal)\r\n```\r\n\r\n## Statistics\r\n\r\nFor time/space complexity details on the algorithms listed below, see [here](complexity.md).\r\n\r\n### [Quantile](https://godoc.org/github.com/alexander-yu/stream/quantile)\r\n\r\n#### Quantile\r\n\r\nQuantile keeps track of the quantiles of a stream. Quantile can calculate the global quantiles of a stream, or over a rolling window. You can also configure which implementation to use as the underlying data structure, as well as which interpolation method to use in the case that a quantile actually lies in between two elements. For now [skip lists](https://en.wikipedia.org/wiki/Skip_list) as well as [order statistic trees](https://en.wikipedia.org/wiki/Order_statistic_tree) (in particular modified forms of [AVL trees](https://en.wikipedia.org/wiki/AVL_tree) and [red black trees](https://en.wikipedia.org/wiki/Red-black_tree)) are supported.\r\n\r\n#### Median\r\n\r\nMedian keeps track of the median of a stream; this is simply a convenient wrapper over [Quantile](#Quantile), that automatically sets the quantile to be 0.5 and the interpolation method to be the midpoint method.\r\n\r\n#### IQR\r\n\r\nIQR keeps track of the [interquartile range](https://en.wikipedia.org/wiki/Interquartile_range) of a stream; this is simply a convenient wrapper over [Quantile](#Quantile), that retrieves the 1st and 3rd quartiles and sets the interpolation method to be the midpoint method.\r\n\r\n#### HeapMedian\r\n\r\nHeapMedian keeps track of the median of a stream with a pair of [heaps](https://en.wikipedia.org/wiki/Heap_(data_structure)). In particular, it uses a max-heap and a min-heap to keep track of elements below and above the median, respectively. HeapMedian can calculate the global median of a stream, or over a rolling window.\r\n\r\n### [Min/Max](https://godoc.org/github.com/alexander-yu/stream/minmax)\r\n\r\n#### Min\r\n\r\nMin keeps track of the minimum of a stream; it can track either the global minimum, or over a rolling window.\r\n\r\n#### Max\r\n\r\nMax keeps track of the maximum of a stream; it can track either the global maximum, or over a rolling window.\r\n\r\n### [Moment-Based Statistics](https://godoc.org/github.com/alexander-yu/stream/moment)\r\n\r\n#### Mean\r\n\r\nMean keeps track of the mean of a stream; it can track either the global mean, or over a rolling window.\r\n\r\n#### EWMA\r\n\r\nEWMA keeps track of the global [exponentially weighted moving average](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average).\r\n\r\n#### Moment\r\n\r\nMoment keeps track of the `k`-th sample [central moment](https://en.wikipedia.org/wiki/Central_moment); it can track either the global moment, or over a rolling window.\r\n\r\n#### EWMMoment\r\n\r\nEWMMoment keeps track of the global `k`-sample exponentially weighted moving sample [central moment](https://en.wikipedia.org/wiki/Central_moment). This uses the exponentially weighted moving average as its center of mass, and uses the same exponential weights for its power terms.\r\n\r\n#### Std\r\n\r\nStd keeps track of the sample [standard deviation](https://en.wikipedia.org/wiki/Standard_deviation) of a stream; it can track either the global standard deviation, or over a rolling window. To track the sample [variance](https://en.wikipedia.org/wiki/Variance) instead, you should use [Moment](#Moment), i.e.\r\n\r\n```go\r\nvariance := New(2, window)\r\n```\r\n\r\n#### EWMStd\r\n\r\nEWMStd keeps track of the global [exponentially weighted moving standard deviation](https://en.wikipedia.org/wiki/Moving_average#Exponentially_weighted_moving_variance_and_standard_deviation). To track the exponentially weighted moving variance instead, you should use [EWMMoment](#EWMMoment), i.e.\r\n\r\n```go\r\nvariance := NewEWMMoment(2, decay)\r\n```\r\n\r\n#### Skewness\r\n\r\nSkewness keeps track of the sample [skewness](https://en.wikipedia.org/wiki/Skewness) of a stream (in particular, the [adjusted Fisher-Pearson standardized moment coefficient](https://en.wikipedia.org/wiki/Skewness#Sample_skewness)); it can track either the global skewness, or over a rolling window.\r\n\r\n#### Kurtosis\r\n\r\nKurtosis keeps track of the sample [kurtosis](https://en.wikipedia.org/wiki/Kurtosis) of a stream (in particular, the [sample excess kurtosis](https://en.wikipedia.org/wiki/Kurtosis#Sample_kurtosis)); it can track either the global kurtosis, or over a rolling window.\r\n\r\n#### Core (Univariate)\r\n\r\nCore is the struct powering all of the statistics in the `stream/moment` subpackage; it keeps track of a pre-configured set of centralized `k`-th power sums of a stream in an efficient, numerically stable way; it can track either the global sums, or over a rolling window.\r\n\r\nTo configure which sums to track, you'll need to instantiate a `CoreConfig` struct and provide it to `NewCore`:\r\n\r\n```go\r\nconfig := \u0026moment.CoreConfig{\r\n    Sums: SumsConfig{\r\n        2: true, // tracks the sum of squared differences\r\n        3: true, // tracks the sum of cubed differences\r\n    },\r\n    Window: stream.IntPtr(0),    // tracks global sums\r\n    Decay: stream.FloatPtr(0.3), // tracks exponentially weighted sums with a decay factor of 0.3\r\n}\r\ncore, err := NewCore(config)\r\n```\r\n\r\nSee the [godoc](https://godoc.org/github.com/alexander-yu/stream/moment#Core) entry for more details on Core's methods.\r\n\r\n### [Joint Distribution Statistics](https://godoc.org/github.com/alexander-yu/stream/joint)\r\n\r\n#### Cov\r\n\r\nCov keeps track of the sample [covariance](https://en.wikipedia.org/wiki/Covariance) of a stream; it can track either the global covariance, or over a rolling window.\r\n\r\n#### EWMCov\r\n\r\nEWMCov keeps track of the global exponentially weighted sample [covariance](https://en.wikipedia.org/wiki/Covariance) of a stream. This uses the exponentially weighted moving average as its center of mass, and uses the same exponential weights for its power terms.\r\n\r\n#### Corr\r\n\r\nCorr keeps track of the sample [correlation](https://en.wikipedia.org/wiki/Correlation) of a stream (in particular, the [sample Pearson correlation coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#For_a_sample)); it can track either the global correlation, or over a rolling window.\r\n\r\n#### EWMCorr\r\n\r\nEWMCorr keeps track of the global sample exponentially weighted [correlation](https://en.wikipedia.org/wiki/Correlation) of a stream (in particular, the exponentially weighted [sample Pearson correlation coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#For_a_sample)). This uses the exponentially weighted moving average as its center of mass, and uses the same exponential weights for its power terms.\r\n\r\n#### Autocorr\r\n\r\nAutocorr keeps track of the sample [autocorrelation](https://en.wikipedia.org/wiki/Autocorrelation) of a stream (in particular, the [sample autocorrelation](https://en.wikipedia.org/wiki/Autocorrelation#Estimation)) for a given lag; it can track either the global autocorrelation, or over a rolling window.\r\n\r\n#### Autocov\r\n\r\nAutocov keeps track of the sample [autocovariance](https://en.wikipedia.org/wiki/Autocovariance) of a stream (in particular, the sample autocovariance) for a given lag; it can track either the global autocovariance, or over a rolling window.\r\n\r\n#### Core (Multivariate)\r\n\r\nCore is the struct powering all of the statistics in the `stream/joint` subpackage; it keeps track of a pre-configured set of joint centralized power sums of a stream in an efficient, numerically stable way; it can track either the global sums, or over a rolling window.\r\n\r\nTo configure which sums to track, you'll need to instantiate a `CoreConfig` struct and provide it to `NewCore`:\r\n\r\n```go\r\nconfig := \u0026joint.CoreConfig{\r\n    Sums: SumsConfig{\r\n        {1, 1}, // tracks the joint sum of differences\r\n        {2, 0}, // tracks the sum of squared differences of variable 1\r\n    },\r\n    Vars: stream.IntPtr(2),      // declares that there are 2 variables to track (optional if Sums is set)\r\n    Window: stream.IntPtr(0),    // tracks global sums\r\n    Decay: stream.FloatPtr(0.3), // tracks exponentially weighted sums with a decay factor of 0.3\r\n}\r\ncore, err := NewCore(config)\r\n```\r\n\r\nSee the [godoc](https://godoc.org/github.com/alexander-yu/stream/joint#Core) entry for more details on Core's methods.\r\n\r\n### [Aggregate Statistics](https://godoc.org/github.com/alexander-yu/stream/aggregate)\r\n\r\n#### SimpleAggregateMetric\r\n\r\nSimpleAggregateMetric is a convenience wrapper that stores multiple univariate metrics and will push a value to all metrics simultaneously; instead of returning a single scalar, it returns a map of metrics to their corresponding values.\r\n\r\n#### SimpleJointAggregateMetric\r\n\r\nSimpleJointAggregateMetric is a convenience wrapper that stores multiple multivariate metrics and will push a value to all metrics simultaneously; instead of returning a single scalar, it returns a map of metrics to their corresponding values.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexander-yu%2Fstream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexander-yu%2Fstream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexander-yu%2Fstream/lists"}