- Notifications
You must be signed in to change notification settings - Fork0
Calculate the arithmetic mean of a single-precision floating-point strided array using an improved Kahan–Babuška algorithm.
License
stdlib-js/stats-base-smeankbn
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!
Calculate thearithmetic mean of a single-precision floating-point strided array using an improved Kahan–Babuška algorithm.
Thearithmetic mean is defined as
npm install @stdlib/stats-base-smeankbn
Alternatively,
- To load the package in a website via a
script
tag without installation and bundlers, use theES Module available on theesm
branch (seeREADME). - If you are using Deno, visit the
deno
branch (seeREADME for usage intructions). - For use in Observable, or in browser/node environments, use theUniversal Module Definition (UMD) build available on the
umd
branch (seeREADME).
Thebranches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
varsmeankbn=require('@stdlib/stats-base-smeankbn');
Computes thearithmetic mean of a single-precision floating-point strided arrayx
using an improved Kahan–Babuška algorithm.
varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([1.0,-2.0,2.0]);varN=x.length;varv=smeankbn(N,x,1);// returns ~0.3333
The function has the following parameters:
- N: number of indexed elements.
- x: input
Float32Array
. - stride: index increment for
x
.
TheN
andstride
parameters determine which elements inx
are accessed at runtime. For example, to compute thearithmetic mean of every other element inx
,
varFloat32Array=require('@stdlib/array-float32');varfloor=require('@stdlib/math-base-special-floor');varx=newFloat32Array([1.0,2.0,2.0,-7.0,-2.0,3.0,4.0,2.0]);varN=floor(x.length/2);varv=smeankbn(N,x,2);// returns 1.25
Note that indexing is relative to the first index. To introduce an offset, usetyped array
views.
varFloat32Array=require('@stdlib/array-float32');varfloor=require('@stdlib/math-base-special-floor');varx0=newFloat32Array([2.0,1.0,2.0,-2.0,-2.0,2.0,3.0,4.0]);varx1=newFloat32Array(x0.buffer,x0.BYTES_PER_ELEMENT*1);// start at 2nd elementvarN=floor(x0.length/2);varv=smeankbn(N,x1,2);// returns 1.25
Computes thearithmetic mean of a single-precision floating-point strided array using an improved Kahan–Babuška algorithm and alternative indexing semantics.
varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([1.0,-2.0,2.0]);varN=x.length;varv=smeankbn.ndarray(N,x,1,0);// returns ~0.33333
The function has the following additional parameters:
- offset: starting index for
x
.
Whiletyped array
views mandate a view offset based on the underlyingbuffer
, theoffset
parameter supports indexing semantics based on a starting index. For example, to calculate thearithmetic mean for every other value inx
starting from the second value
varFloat32Array=require('@stdlib/array-float32');varfloor=require('@stdlib/math-base-special-floor');varx=newFloat32Array([2.0,1.0,2.0,-2.0,-2.0,2.0,3.0,4.0]);varN=floor(x.length/2);varv=smeankbn.ndarray(N,x,2,1);// returns 1.25
- If
N <= 0
, both functions returnNaN
.
varrandu=require('@stdlib/random-base-randu');varround=require('@stdlib/math-base-special-round');varFloat32Array=require('@stdlib/array-float32');varsmeankbn=require('@stdlib/stats-base-smeankbn');varx;vari;x=newFloat32Array(10);for(i=0;i<x.length;i++){x[i]=round((randu()*100.0)-50.0);}console.log(x);varv=smeankbn(x.length,x,1);console.log(v);
- Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums."Zeitschrift Für Angewandte Mathematik Und Mechanik 54 (1): 39–51. doi:10.1002/zamm.19740540106.
@stdlib/stats-strided/dmeankbn
:calculate the arithmetic mean of a double-precision floating-point strided array using an improved Kahan–Babuška algorithm.@stdlib/stats-base/meankbn
:calculate the arithmetic mean of a strided array using an improved Kahan–Babuška algorithm.@stdlib/stats-base/smean
:calculate the arithmetic mean of a single-precision floating-point strided array.
This package is part ofstdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to developstdlib, see the main projectrepository.
SeeLICENSE.
Copyright © 2016-2025. The StdlibAuthors.
About
Calculate the arithmetic mean of a single-precision floating-point strided array using an improved Kahan–Babuška algorithm.