{"id":44657058,"url":"https://github.com/dallaylaen/stats-logscale-js","last_synced_at":"2026-02-14T22:19:40.310Z","repository":{"id":145514747,"uuid":"468886668","full_name":"dallaylaen/stats-logscale-js","owner":"dallaylaen","description":"Memory efficient, fast approximate statistical analysis tool","archived":false,"fork":false,"pushed_at":"2024-03-11T20:51:36.000Z","size":861,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-28T23:51:40.479Z","etag":null,"topics":["approximate","math","statistics","univariate"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dallaylaen.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"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":"2022-03-11T20:10:51.000Z","updated_at":"2023-07-08T04:34:14.000Z","dependencies_parsed_at":"2024-03-10T23:27:21.767Z","dependency_job_id":"7ff95797-9124-45c1-879e-7fd8bf58a1d9","html_url":"https://github.com/dallaylaen/stats-logscale-js","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/dallaylaen/stats-logscale-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fstats-logscale-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fstats-logscale-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fstats-logscale-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fstats-logscale-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dallaylaen","download_url":"https://codeload.github.com/dallaylaen/stats-logscale-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dallaylaen%2Fstats-logscale-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29458453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T21:29:27.764Z","status":"ssl_error","status_checked_at":"2026-02-14T21:28:11.111Z","response_time":53,"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":["approximate","math","statistics","univariate"],"created_at":"2026-02-14T22:19:38.644Z","updated_at":"2026-02-14T22:19:40.300Z","avatar_url":"https://github.com/dallaylaen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stats-logscale\n\nA memory-efficient approximate statistical analysis tool\nusing logarithmic binning.\n\n![Example: repeated setTimeout(0) execution times](example/images/settimeout-duration-distribution.png)\n_Example: repeated setTimeout(0) execution times_\n\n## Description\n\n* data is split into bins (aka buckets),\nlinear close to zero and logarithmic for large numbers (hence the name),\nthus maintaining desired absolute and relative precision;\n\n* can calculate mean, variance, median, moments, percentiles,\ncumulative distribution function (i.e. probability that a value is less than x),\nand expected values of arbitrary functions over the sample;\n\n* can generate histograms for plotting the data;\n\n* all calculated values are cached. Cache is reset upon adding new data;\n\n* (almost) every function has a \"neat\" counterpart which rounds the result\nto the shortest possible number within the precision bounds.\nE.g. `foo.mean() // 1.0100047`, but `foo.neat.mean() // 1.01`;\n\n* is (de)serializable;\n\n* can split out partial data or combine multiple samples into one.\n\n## Usage\n\nCreating the sample container:\n\n```javascript\nconst { Univariate } = require( 'stats-logscale' );\nconst stat = new Univariate();\n```\n\n**Specifying absolute and relative precision.**\nThe defaults are 10\u003csup\u003e-9\u003c/sup\u003e and 1.001, respectivele.\nLess precision = less memory usage\nand faster data querying (but not insertion).\n```javascript\nconst stat = new Univariate({base: 1.01, precision: 0.001});\n```\n\nUse _flat_ switch to avoid using logarithmic binning at all:\n```javascript\n// this assumes the data is just integer numbers\nconst stat = new Univariate({precision: 1, flat: true});\n```\n\n**Adding data points**, wither one by one,\nor as _(value, frequency)_ pairs.\nStrings are OK (e.g. after parsing user input)\nbut non-numeric values will cause an exception:\n```javascript\nstat.add (3.14);\nstat.add (\"Foo\"); // Nope!\nstat.add (\"3.14 3.15 3.16\".split(\" \"));\nstat.addWeighted([[0.5, 1], [1.5, 3], [2.5, 5]]);\n```\n\n**Querying data:**\n```javascript\nstat.count();           // number of data points\nstat.mean();            // average\nstat.stdev();           // standard deviation\nstat.median();          // half of data is lower than this value\nstat.percentile(90);    // 90% of data below this point\nstat.quantile(0.9);     // ditto\nstat.cdf(0.5);          // Cumulative distribution function, which means\n                        // the probability that a data point is less than 0.5\nstat.moment(power);     // central moment of an integer power\nstat.momentAbs(power);  // \u003c |x-\u003cx\u003e| ** power \u003e, power may be fractional\nstat.E( x =\u003e x\\*x );    // expected value of an arbitrary function\n```\n\nEach querying primitive has a _\"neat\"_ counterpart\nthat rounds its output to the shortest possible\ndecimal number in the respective bin:\n\n```javascript\nstat.neat.mean();\nstat.neat.stdev();\nstat.neat.median();\n```\n\n**Extract partial samples:**\n\n```javascript\nstat.clone( { min: 0.5, max: 0.7 } );\nstat.clone( { ltrim: 1, rtrim: 1 });\n    // cut off outer 1% of data\nstat.clone( { ltrim: 1, rtrim: 1, winsorize: true }});\n    // ditto but truncate outliers instead of discarding\n```\n\nSerialize, deserialize, and combine data from multiple sources\n\n```javascript\nconst str = JSON.stringify(stat);\n// send over the network here\nconst copy = new Univariate (JSON.parse(str));\n\nmain.addWeighted( partialStat.getBins() );\nmain.addWeighted( JSON.parse(str).bins ); // ditto\n```\n\nCreate histograms and plot data:\n\n```javascript\nstat.histogram({scale: 768, count:1024});\n    // this produces 1024 bars of the form\n    // [ bar_height, lower_boundary, upper_boundary ]\n    // The intervals are consecutive.\n    // The bar heights are limited to 768.\n\nstat.histogram({scale: 70, count:20})\n    .map( x =\u003e stat.shorten(x[1], x[2]) + '\\t' + '+'.repeat(x[0]) )\n    .join('\\n')\n    // \"Draw\" a vertical histogram for text console\n    // You'll use PNG in production instead, right? Right?\n```\n\nSee the [playground](https://dallaylaen.github.io/stats-logscale-js/).\n\nSee also [full documentation](https://dallaylaen.github.io/stats-logscale-js/man/Univariate.html).\n\n## Performance\n\nData inserts are optimized for speed,\nand querying is cached where possible.\nThe script [example/speed.js](example/speed.js) \ncan be used to benchmark the module on your system.\n\nMemory usage for a dense sample spanning 6 orders of magnitude\nwas around 1.6MB in Chromium,\n~230KB for the data itself + ~1.2MB for the cache.  \n\n## Bugs\n\nPlease report bugs and request features via the \n[github bugtracker](https://github.com/dallaylaen/stats-logscale-js/issues).\n\n## Copyright and license\n\nCopyright (c) 2022-2023 Konstantin Uvarin\n\nThis software is free software available under MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdallaylaen%2Fstats-logscale-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdallaylaen%2Fstats-logscale-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdallaylaen%2Fstats-logscale-js/lists"}