Skip to content

Commit ccb2e60

Browse files
fix: addressed requested changes
1 parent 670172b commit ccb2e60

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

lib/node_modules/@stdlib/stats/base/dists/triangular/mean/benchmark/c/benchmark.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ static double benchmark( void ) {
9898

9999
// Generate random parameters for the triangular distribution
100100
for ( i = 0; i < 100; i++ ) {
101-
a[ i ] = rand_double(); // Lower bound
102-
b[ i ] = rand_double(); // Upper bound
103-
c[ i ] = rand_double(); // Mode
101+
a[ i ] = rand_double() * 20.0; // Lower bound
102+
b[ i ] = ( rand_double() * 20.0 ) + a[ i ]; // Upper bound
103+
c[ i ] = ( rand_double() * ( b[i] - a[i] ) ) + a[i]; // Mode
104104
}
105105

106106
t = tic();

lib/node_modules/@stdlib/stats/base/dists/triangular/mean/examples/c/example.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@
2020
#include <stdlib.h>
2121
#include <stdio.h>
2222

23+
static double random_uniform( const double min, const double max ) {
24+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
25+
return min + ( v*(max-min) );
26+
}
27+
2328
int main( void ) {
24-
double a, b, c;
25-
double v;
29+
double a;
30+
double b;
31+
double c;
32+
double y;
2633
int i;
2734

28-
for ( i = 0; i < 10; i++ ) {
29-
a = 20.0 * (double)rand() / ((double)RAND_MAX + 1.0);
30-
b = 20.0 * (double)rand() / ((double)RAND_MAX + 1.0) + a;
31-
c = 20.0 * (double)rand() / ((double)RAND_MAX + 1.0) + a;
32-
33-
v = stdlib_base_dists_triangular_mean( a, b, c );
34-
35-
printf( "a: %lf, b: %lf, c: %lf, E(X; a, b, c): %lf\n", a, b, c, v );
35+
for ( i = 0; i < 25; i++ ) {
36+
a = random_uniform( 0.0, 10.0 );
37+
b = random_uniform( 0.0, 10.0 ) + a;
38+
c = a + (b - a) * random_uniform( 0.0, 1.0 ); // mode between a and b
39+
y = stdlib_base_dists_triangular_mean( a, b, c );
40+
printf( "a: %lf, b: %lf, c: %lf, E(X;a,b,c): %lf\n", a, b, c, y );
3641
}
3742

3843
return 0;

lib/node_modules/@stdlib/stats/base/dists/triangular/mean/lib/native.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var addon = require( './../src/addon.node' );
2828
/**
2929
* Returns the expected value (mean) of a triangular distribution.
3030
*
31+
* @private
3132
* @param {NonNegativeNumber} a - lower bound
3233
* @param {NonNegativeNumber} b - upper bound
3334
* @param {NonNegativeNumber} c - mode (peak)

lib/node_modules/@stdlib/stats/base/dists/triangular/mean/src/main.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,16 @@
2020
#include "stdlib/math/base/assert/is_nan.h"
2121

2222
/**
23-
* Returns the expected value (mean) of a triangular distribution.
23+
* Evaluates the expected value (mean) of a triangular distribution with lower bound a, upper bound b and mode (peak) c.
2424
*
25-
* @param {NonNegativeNumber} a - lower bound
26-
* @param {NonNegativeNumber} b - upper bound
27-
* @param {NonNegativeNumber} c - mode (peak)
28-
* @returns {NonNegativeNumber} expected value (mean)
25+
* @param a lower bound
26+
* @param b upper bound
27+
* @param c mode (peak)
28+
* @returns expected value (mean)
2929
*
3030
* @example
31-
* var v = mean( 0.0, 10.0, 5.0 );
31+
* double v = mean( 0.0, 10.0, 5.0 );
3232
* // returns 5.0
33-
*
34-
* @example
35-
* var v = mean( 2.0, 8.0, 4.0 );
36-
* // returns 4.0
37-
*
38-
* @example
39-
* var v = mean( -1.0, 5.0, 6.0 );
40-
* // returns NaN
41-
*
42-
* @example
43-
* var v = mean( NaN, 10.0, 5.0 );
44-
* // returns NaN
4533
*/
4634
double stdlib_base_dists_triangular_mean( const double a, const double b, const double c ) {
4735
if (

0 commit comments

Comments
 (0)