Skip to content

Commit bc4babf

Browse files
committed
Auto-generated commit
1 parent 0d563b8 commit bc4babf

File tree

6 files changed

+140
-9
lines changed

6 files changed

+140
-9
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,42 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-09-01)
7+
## Unreleased (2024-09-07)
88

9-
No changes reported for this release.
9+
<section class="packages">
10+
11+
### Packages
12+
13+
</section>
14+
15+
<!-- /.packages -->
16+
17+
<section class="contributors">
18+
19+
### Contributors
20+
21+
A total of 2 people contributed to this release. Thank you to the following contributors:
22+
23+
- Philipp Burckhardt
24+
- Tufail
25+
26+
</section>
27+
28+
<!-- /.contributors -->
29+
30+
<section class="commits">
31+
32+
### Commits
33+
34+
<details>
35+
36+
- [`71af75e`](https://github.com/stdlib-js/stdlib/commit/71af75ec2c9066eb59288ad525ddbf1ad782db0c) - **docs:** improve examples `stats/base/dists/triangular` namespace _(by Tufail, Philipp Burckhardt)_
37+
38+
</details>
39+
40+
</section>
41+
42+
<!-- /.commits -->
1043

1144
</section>
1245

CONTRIBUTORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com>
2626
Frank Kovacs <fran70kk@gmail.com>
2727
Golden Kumar <103646877+AuenKr@users.noreply.github.com>
2828
Gunj Joshi <gunjjoshi8372@gmail.com>
29+
HarshaNP <96897754+GittyHarsha@users.noreply.github.com>
2930
Harshita Kalani <harshitakalani02@gmail.com>
3031
Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
3132
Jaimin Godhani <112328542+Jai0401@users.noreply.github.com>
@@ -96,3 +97,4 @@ nishant-s7 <97207366+nishant-s7@users.noreply.github.com>
9697
orimiles5 <97595296+orimiles5@users.noreply.github.com>
9798
rainn <88160429+AmCodesLame@users.noreply.github.com>
9899
rei2hu <reimu@reimu.ws>
100+
yaswanth <116426380+yaswanthkosuru@users.noreply.github.com>

README.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,62 @@ y = dist.quantile( 1.9 );
140140

141141
## Examples
142142

143-
<!-- TODO: better examples -->
144-
145143
<!-- eslint no-undef: "error" -->
146144

147145
```javascript
148-
var objectKeys = require( '@stdlib/utils-keys' );
146+
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
149147
var triangular = require( '@stdlib/stats-base-dists-triangular' );
150148

151-
console.log( objectKeys( triangular ) );
149+
// Scenario: Modeling completion time for a software development task
150+
151+
// Define the distribution parameters (in hours):
152+
var a = 1.5; // Minimum time (best-case scenario)
153+
var b = 4.5; // Maximum time (worst-case scenario)
154+
var c = discreteUniform( 2, 4 ); // Most likely time (mode)
155+
console.log( 'a: %d, b: %d, c: %d', a, b, c );
156+
157+
// Expected (mean) completion time:
158+
var mean = triangular.mean( a, b, c );
159+
console.log( '\nExpected completion time: %d hours', mean );
160+
161+
// Median completion time:
162+
var median = triangular.median( a, b, c );
163+
console.log( 'Median completion time: %d hours', median );
164+
165+
// Variance in completion time:
166+
var variance = triangular.variance( a, b, c );
167+
console.log( 'Variance in completion time: %d hours^2', variance );
168+
169+
// Probability of completing the task within 3 hours:
170+
var x = 3.0;
171+
var prob = triangular.cdf( x, a, b, c );
172+
console.log( '\nProbability of completing within %d hours: %d', x, prob );
173+
174+
// 90th percentile of completion time:
175+
var p = 0.9;
176+
var percentile = triangular.quantile( p, a, b, c );
177+
console.log( '90% of tasks will be completed within %d hours', percentile );
178+
179+
// Relative likelihood of completing the task in exactly 2.5 hours:
180+
x = 2.5;
181+
var likelihood = triangular.pdf( x, a, b, c );
182+
console.log( '\nRelative likelihood of completing in exactly %d hours: %d', x, likelihood );
183+
184+
// Skewness to understand the distribution's shape:
185+
var skewness = triangular.skewness( a, b, c );
186+
console.log( '\nSkewness of completion times: %d', skewness );
187+
if ( skewness > 0 ) {
188+
console.log( 'The distribution is right-skewed, suggesting occasional longer completion times.' );
189+
} else if ( skewness < 0 ) {
190+
console.log( 'The distribution is left-skewed, suggesting occasional shorter completion times.' );
191+
} else {
192+
console.log( 'The distribution is symmetric.' );
193+
}
194+
195+
// Entropy as a measure of uncertainty in the estimate:
196+
var entropy = triangular.entropy( a, b, c );
197+
console.log( '\nEntropy of the distribution: %d nats', entropy );
198+
console.log( 'Higher entropy indicates more uncertainty in completion times.' );
152199
```
153200

154201
</section>

examples/index.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,56 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils-keys' );
21+
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
2222
var triangular = require( './../lib' );
2323

24-
console.log( objectKeys( triangular ) );
24+
// Scenario: Modeling completion time for a software development task
25+
26+
// Define the distribution parameters (in hours):
27+
var a = 1.5; // Minimum time (best-case scenario)
28+
var b = 4.5; // Maximum time (worst-case scenario)
29+
var c = discreteUniform( 2, 4 ); // Most likely time (mode)
30+
console.log( 'a: %d, b: %d, c: %d', a, b, c );
31+
32+
// Expected (mean) completion time:
33+
var mean = triangular.mean( a, b, c );
34+
console.log( '\nExpected completion time: %d hours', mean );
35+
36+
// Median completion time:
37+
var median = triangular.median( a, b, c );
38+
console.log( 'Median completion time: %d hours', median );
39+
40+
// Variance in completion time:
41+
var variance = triangular.variance( a, b, c );
42+
console.log( 'Variance in completion time: %d hours^2', variance );
43+
44+
// Probability of completing the task within 3 hours:
45+
var x = 3.0;
46+
var prob = triangular.cdf( x, a, b, c );
47+
console.log( '\nProbability of completing within %d hours: %d', x, prob );
48+
49+
// 90th percentile of completion time:
50+
var p = 0.9;
51+
var percentile = triangular.quantile( p, a, b, c );
52+
console.log( '90% of tasks will be completed within %d hours', percentile );
53+
54+
// Relative likelihood of completing the task in exactly 2.5 hours:
55+
x = 2.5;
56+
var likelihood = triangular.pdf( x, a, b, c );
57+
console.log( '\nRelative likelihood of completing in exactly %d hours: %d', x, likelihood );
58+
59+
// Skewness to understand the distribution's shape:
60+
var skewness = triangular.skewness( a, b, c );
61+
console.log( '\nSkewness of completion times: %d', skewness );
62+
if ( skewness > 0 ) {
63+
console.log( 'The distribution is right-skewed, suggesting occasional longer completion times.' );
64+
} else if ( skewness < 0 ) {
65+
console.log( 'The distribution is left-skewed, suggesting occasional shorter completion times.' );
66+
} else {
67+
console.log( 'The distribution is symmetric.' );
68+
}
69+
70+
// Entropy as a measure of uncertainty in the estimate:
71+
var entropy = triangular.entropy( a, b, c );
72+
console.log( '\nEntropy of the distribution: %d nats', entropy );
73+
console.log( 'Higher entropy indicates more uncertainty in completion times.' );

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@stdlib/math-base-special-ln": "^0.2.4",
6969
"@stdlib/math-base-special-pow": "^0.3.0",
7070
"@stdlib/math-base-special-sqrt": "^0.2.2",
71+
"@stdlib/random-base-discrete-uniform": "^0.2.1",
7172
"@stdlib/random-base-randu": "^0.2.1",
7273
"@stdlib/string-format": "^0.2.2",
7374
"@stdlib/utils-constant-function": "^0.2.2",

0 commit comments

Comments
 (0)