stdlib-js / stdlib

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

[RFC]: improve README examples of `stats/incr` namespace #1651

Open Planeshifter opened 4 months ago

Planeshifter commented 4 months ago

Description

This RFC proposes to improve the README examples of the stats/incr namespace package. Currently, namespace package READMEs only include minimal examples which are not particularly informative and do not showcase namespace functionality.

Historically, namespace examples were not given much effort due to the rapidly changing nature of the project; however, now that development and organization has settled, it would be good to revisit these packages and add proper examples to better communicate to users how to use namespace contents.

For those wanting to contribute to this issue, you can use the following steps:

Related Issues

None.

Questions

No.

Other

No.

Checklist

irfan-iiitr commented 4 months ago

Can I work on this?

Planeshifter commented 4 months ago

@irfan-iiitr yes, thanks! Notice that the examples/index.js file of the namespace will also have to be updated and that we should strive to come up with some novel code example that doesn't just copy-paste existing example code.

irfan-iiitr commented 4 months ago

@Planeshifter do we have to update the examples in the readme files of every sub-packages of stats/incr or just the main readme file or the stats/incr package?

kunal-511 commented 4 months ago

@Planeshifter This issue seems to be big can I also join @irfan-iiitr to resolve this ?

Planeshifter commented 4 months ago

@irfan-iiitr Just the top-level examples for the namespace; no need to touch any other READMEs as part of these issues.

@kunal-511 Why don't you pick a different issue for a separate namespace to work on? While it's great to collaborate and great for you to join and offer your help, it may be easier that way since coordinating a contribution among different people is challenging. Better to have separate, smaller PRs from everyone.

irfan-iiitr commented 4 months ago

@Planeshifter Should it be like this?

var getKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/stats/incr' );
var incrmmpe = require('@stdlib/stats/incr/mmpe');
var incrmmse = require('@stdlib/stats/incr/mmse');
var incrmpcorr = require('@stdlib/stats/incr/mpcorr');
var incrsumprod = require( '@stdlib/stats/incr/sumprod' );
var sin = require( '@stdlib/math/base/special/sin' );
var cos = require( '@stdlib/math/base/special/cos' );

console.log( getKeys( ns ) );

// Example 1: Computing a moving mean percentage error incrementally
var mmpe = incrmmpe(10); // Set the window size to 10
mmpe(5, 10); // Add data point (5, 10)
mmpe(8, 12); // Add data point (8, 12)
console.log(mmpe()); // Get the current mean percentage error
// Output: 0.25

// Example 2: Computing a moving mean squared error incrementally
var mmse = incrmmse(5); // Set the window size to 5
mmse(2, 3); // Add data point (2, 3)
mmse(4, 5); // Add data point (4, 5)
console.log(mmse()); // Get the current mean squared error
// Output: 1.5

// Example 3: Computing a moving sample Pearson product-moment correlation coefficient incrementally
var mpcorr = incrmpcorr(3); // Set the window size to 3
mpcorr(1, 2); // Add data point (1, 2)
mpcorr(3, 4); // Add data point (3, 4)
console.log(mpcorr()); // Get the current sample Pearson product-moment correlation coefficient
//0.86602540378

// Example 4: Compting mean of Squares
var incrmean = require('@stdlib/stats/incr/mean');
var accumulator;
var v;
// Initialize an accumulator:
accumulator = incrmean();

// For each number from 1 to 100, update the mean with the square of the number...
for (var i = 1; i <= 100; i++) {
    v = i * i; // square of the number
    accumulator(v);
}
console.log(accumulator());
//The output of the code will be the mean of the squares of the numbers from 1 to 100.

// Example 5: Computing the sum-product of sine and cosine of a number.
let accumulator = incrsumprod();

// For each number from 0 to 99, update the sum-product with the sine and cosine of the number...
for (let i = 0; i < 100; i++) {
    let v1 = sin(i);
    let v2 = cos(i);
    accumulator(v1, v2);
}
console.log(accumulator()); 
//Σ(sin(i) * cos(i)) for i from 0 to 99
irfan-iiitr commented 3 months ago

@Planeshifter is there something wrong in this? How can i improvise?