Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Calculate the arithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and returning an extended precision result.

License

NotificationsYou must be signed in to change notification settings

stdlib-js/stats-base-dsmeanpw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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!

dsmeanpw

NPM versionBuild StatusCoverage Status

Calculate thearithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and returning an extended precision result.

Thearithmetic mean is defined as

$$\mu = \frac{1}{n} \sum_{i=0}^{n-1} x_i$$

Installation

npm install @stdlib/stats-base-dsmeanpw

Alternatively,

  • To load the package in a website via ascript tag without installation and bundlers, use theES Module available on theesm branch (seeREADME).
  • If you are using Deno, visit thedeno branch (seeREADME for usage intructions).
  • For use in Observable, or in browser/node environments, use theUniversal Module Definition (UMD) build available on theumd 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.

Usage

vardsmeanpw=require('@stdlib/stats-base-dsmeanpw');

dsmeanpw( N, x, strideX )

Computes thearithmetic mean of a single-precision floating-point strided arrayx using pairwise summation with extended accumulation and returning an extended precision result.

varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([1.0,-2.0,2.0]);varv=dsmeanpw(x.length,x,1);// returns ~0.3333

The function has the following parameters:

  • N: number of indexed elements.
  • x: inputFloat32Array.
  • strideX: stride length forx.

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');varx=newFloat32Array([1.0,2.0,2.0,-7.0,-2.0,3.0,4.0,2.0]);varv=dsmeanpw(4,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');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 elementvarv=dsmeanpw(4,x1,2);// returns 1.25

dsmeanpw.ndarray( N, x, strideX, offsetX )

Computes thearithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result.

varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([1.0,-2.0,2.0]);varv=dsmeanpw.ndarray(x.length,x,1,0);// returns ~0.33333

The function has the following additional parameters:

  • offsetX: starting index forx.

Whiletyped array views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate thearithmetic mean for every other element inx starting from the second element

varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([2.0,1.0,2.0,-2.0,-2.0,2.0,3.0,4.0]);varv=dsmeanpw.ndarray(4,x,2,1);// returns 1.25

Notes

  • IfN <= 0, both functions returnNaN.
  • Accumulated intermediate values are stored as double-precision floating-point numbers.
  • In general, pairwise summation is more numerically stable than ordinary recursive summation (i.e., "simple" summation), with slightly worse performance. While not the most numerically stable summation technique (e.g., compensated summation techniques such as the Kahan–Babuška-Neumaier algorithm are generally more numerically stable), pairwise summation strikes a reasonable balance between numerical stability and performance. If either numerical stability or performance is more desirable for your use case, consider alternative summation techniques.

Examples

vardiscreteUniform=require('@stdlib/random-array-discrete-uniform');vardsmeanpw=require('@stdlib/stats-base-dsmeanpw');varx=discreteUniform(10,-50,50,{'dtype':'float32'});console.log(x);varv=dsmeanpw(x.length,x,1);console.log(v);

C APIs

Usage

#include"stdlib/stats/base/dsmeanpw.h"

stdlib_strided_dsmeanpw( N, *X, strideX )

Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and returning an extended precision result.

constfloatx[]= {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f };doublev=stdlib_strided_dsmeanpw(4,x,2 );// returns 4.0

The function accepts the following arguments:

  • N:[in] CBLAS_INT number of indexed elements.
  • X:[in] float* input array.
  • strideX:[in] CBLAS_INT stride length forX.
doublestdlib_strided_dsmeanpw(constCBLAS_INTN,constfloat*X,constCBLAS_INTstrideX );

stdlib_strided_dsmeanpw_ndarray( N, *X, strideX, offsetX )

Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result.

constfloatx[]= {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f };doublev=stdlib_strided_dsmeanpw_ndarray(4,x,2,0 );// returns 4.0

The function accepts the following arguments:

  • N:[in] CBLAS_INT number of indexed elements.
  • X:[in] float* input array.
  • strideX:[in] CBLAS_INT stride length forX.
  • offsetX:[in] CBLAS_INT starting index forX.
doublestdlib_strided_dsmeanpw_ndarray(constCBLAS_INTN,constfloat*X,constCBLAS_INTstrideX,constCBLAS_INToffsetX );

Examples

#include"stdlib/stats/base/dsmeanpw.h"#include<stdio.h>intmain(void ) {// Create a strided array:constfloatx[]= {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f };// Specify the number of elements:constintN=4;// Specify the stride length:constintstrideX=2;// Compute the arithmetic mean:doublev=stdlib_strided_dsmeanpw(N,x,strideX );// Print the result:printf("mean: %lf\n",v );}

References

  • Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation."SIAM Journal on Scientific Computing 14 (4): 783–99. doi:10.1137/0914050.

See Also

  • @stdlib/stats-strided/dmeanpw:calculate the arithmetic mean of a double-precision floating-point strided array using pairwise summation.
  • @stdlib/stats-base/dsmean:calculate the arithmetic mean of a single-precision floating-point strided array using extended accumulation and returning an extended precision result.
  • @stdlib/stats-base/meanpw:calculate the arithmetic mean of a strided array using pairwise summation.
  • @stdlib/stats-base/smeanpw:calculate the arithmetic mean of a single-precision floating-point strided array using pairwise summation.

Notice

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.

Community

Chat


License

SeeLICENSE.

Copyright

Copyright © 2016-2025. The StdlibAuthors.


[8]ページ先頭

©2009-2025 Movatter.jp