Skip to content

Commit 874afd7

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into fix/triangular-mgf-divergence
2 parents 63bc5ad + 6a802bc commit 874afd7

File tree

11 files changed

+198
-57
lines changed

11 files changed

+198
-57
lines changed

.github/workflows/scripts/create_address_commit_comments_issues

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@ update_commit_map() {
248248
local endLine=$(( line + 3 ))
249249
local code_snippet="https://github.com/stdlib-js/stdlib/blob/${key}/${path}#L${startLine}-L${endLine}"
250250

251+
local formatted_body=$(echo "${body}" | sed $'s/\n/\n /g')
252+
251253
for existing in "${commit_keys[@]}"; do
252254
if [ "$existing" = "$key" ]; then
253255
commit_counts[i]=$(( commit_counts[i] + 1 ))
254-
commit_comments[i]="${commit_comments[i]}"$'\n\n'"- ${link}"$'\n\n'" > **Line ${line}**: ${body}"$'\n\n'" ${code_snippet}"
256+
commit_comments[i]="${commit_comments[i]}"$'\n\n'"- ${link}"$'\n\n'" > **Line ${line}**: ${formatted_body}"$'\n\n'" ${code_snippet}"
255257
found=1
256258
break
257259
fi
@@ -261,7 +263,7 @@ update_commit_map() {
261263
if [ "$found" -eq 0 ]; then
262264
commit_keys+=("$key")
263265
commit_counts+=("1")
264-
commit_comments+=("- ${link}"$'\n\n'" > **Line ${line}**: ${body}"$'\n\n'" ${code_snippet}")
266+
commit_comments+=("- ${link}"$'\n\n'" > **Line ${line}**: ${formatted_body}"$'\n\n'" ${code_snippet}")
265267
fi
266268
}
267269

@@ -350,7 +352,6 @@ main() {
350352
for comment in "${all_comments[@]}"; do
351353
# Extract the comment body:
352354
local comment_body=$(echo "$comment" | jq -r '.body')
353-
local comment_line=$(echo "$comment" | jq -r '.line')
354355

355356
# Check if the comment body contains '@stdlib-bot':
356357
if [[ "$comment_body" == *"@stdlib-bot"* ]]; then

lib/node_modules/@stdlib/stats/base/dists/triangular/ctor/test/test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var logcdf = require( '@stdlib/stats/base/dists/triangular/logcdf' );
2828
var logpdf = require( '@stdlib/stats/base/dists/triangular/logpdf' );
2929
var cdf = require( '@stdlib/stats/base/dists/triangular/cdf' );
3030
var pdf = require( '@stdlib/stats/base/dists/triangular/pdf' );
31+
var mgf = require( '@stdlib/stats/base/dists/triangular/mgf' );
3132
var kurtosis = require( '@stdlib/stats/base/dists/triangular/kurtosis' );
3233
var skewness = require( '@stdlib/stats/base/dists/triangular/skewness' );
3334
var variance = require( '@stdlib/stats/base/dists/triangular/variance' );
@@ -328,6 +329,19 @@ tape( 'the created distribution throws an error if one attempts to set `b` to a
328329
}
329330
});
330331

332+
tape( 'the created distribution has a property for getting and setting `c`', function test( t ) {
333+
var triangular;
334+
335+
triangular = new Triangular( 2.0, 4.0, 2.5 );
336+
t.strictEqual( hasOwnProp( triangular, 'c' ), true, 'has property' );
337+
t.strictEqual( triangular.c, 2.5, 'returns expected value' );
338+
339+
triangular.c = 3.0;
340+
t.strictEqual( triangular.c, 3.0, 'returns expected value' );
341+
342+
t.end();
343+
});
344+
331345
tape( 'the created distribution throws an error if one attempts to set `c` to a value which is not a number primitive', function test( t ) {
332346
var values;
333347
var i;
@@ -525,6 +539,20 @@ tape( 'the distribution prototype has a method for evaluating the probability de
525539
t.end();
526540
});
527541

542+
tape( 'the distribution prototype has a method for evaluating the moment-generating function (MGF)', function test( t ) {
543+
var triangular;
544+
var y;
545+
546+
t.strictEqual( hasOwnProp( Triangular.prototype, 'mgf' ), true, 'has property' );
547+
t.strictEqual( isFunction( Triangular.prototype.mgf ), true, 'has method' );
548+
549+
triangular = new Triangular();
550+
y = triangular.mgf( 0.2 );
551+
552+
t.strictEqual( y, mgf( 0.2, 0.0, 1.0, 0.5 ), 'returns expected value' );
553+
t.end();
554+
});
555+
528556
tape( 'the distribution prototype has a method for evaluating the quantile function', function test( t ) {
529557
var triangular;
530558
var y;

lib/node_modules/@stdlib/stats/base/dists/triangular/median/test/fixtures/julia/data.json

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

lib/node_modules/@stdlib/stats/base/dists/triangular/median/test/fixtures/julia/data1.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/stats/base/dists/triangular/median/test/fixtures/julia/data2.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/stats/base/dists/triangular/median/test/fixtures/julia/runner.jl

100644100755
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ dir = dirname( file );
7474
# Generate fixtures:
7575
a = rand( 500 ) .* 10.0;
7676
b = ( rand( 500 ) .* 10.0 ) .+ a;
77-
c = a .+ ( b .- a ) .* rand();
78-
gen( a, b, c, "data.json" );
77+
# Case: c < (a + b) / 2
78+
c1 = a .+ ( b .- a ) .* ( 0.5 .* rand( 500 ) );
79+
gen( a, b, c1, "data1.json" );
80+
# Case: c >= (a + b) / 2
81+
c2 = ( a .+ b ) ./ 2 .+ ( b .- a ) .* ( 0.5 .* rand( 500 ) );
82+
gen( a, b, c2, "data2.json" );
7983

lib/node_modules/@stdlib/stats/base/dists/triangular/median/test/test.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ var median = require( './../lib' );
2929

3030
// FIXTURES //
3131

32-
var data = require( './fixtures/julia/data.json' );
32+
var data1 = require( './fixtures/julia/data1.json' );
33+
var data2 = require( './fixtures/julia/data2.json' );
3334

3435

3536
// TESTS //
@@ -42,13 +43,13 @@ tape( 'main export is a function', function test( t ) {
4243

4344
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4445
var v = median( NaN, 1.0, 0.5 );
45-
t.equal( isnan( v ), true, 'returns NaN' );
46+
t.equal( isnan( v ), true, 'returns expected value' );
4647

4748
v = median( 0.0, NaN, 0.5 );
48-
t.equal( isnan( v ), true, 'returns NaN' );
49+
t.equal( isnan( v ), true, 'returns expected value' );
4950

5051
v = median( 0.0, 10.0, NaN );
51-
t.equal( isnan( v ), true, 'returns NaN' );
52+
t.equal( isnan( v ), true, 'returns expected value' );
5253

5354
t.end();
5455
});
@@ -57,21 +58,21 @@ tape( 'if provided parameters not satisfying `a <= c <= b`, the function returns
5758
var y;
5859

5960
y = median( -1.0, -1.1, -1.0 );
60-
t.equal( isnan( y ), true, 'returns NaN' );
61+
t.equal( isnan( y ), true, 'returns expected value' );
6162

6263
y = median( 3.0, 2.0, 2.5 );
63-
t.equal( isnan( y ), true, 'returns NaN' );
64+
t.equal( isnan( y ), true, 'returns expected value' );
6465

6566
y = median( 0.0, 1.0, -1.0 );
66-
t.equal( isnan( y ), true, 'returns NaN' );
67+
t.equal( isnan( y ), true, 'returns expected value' );
6768

6869
y = median( 0.0, 1.0, 2.0 );
69-
t.equal( isnan( y ), true, 'returns NaN' );
70+
t.equal( isnan( y ), true, 'returns expected value' );
7071

7172
t.end();
7273
});
7374

74-
tape( 'the function returns the median of a triangular distribution', function test( t ) {
75+
tape( 'the function returns the median of a triangular distribution if provided parameters satisfy `c < (a + b) / 2`', function test( t ) {
7576
var expected;
7677
var delta;
7778
var tol;
@@ -81,10 +82,37 @@ tape( 'the function returns the median of a triangular distribution', function t
8182
var i;
8283
var y;
8384

84-
expected = data.expected;
85-
a = data.a;
86-
b = data.b;
87-
c = data.c;
85+
expected = data1.expected;
86+
a = data1.a;
87+
b = data1.b;
88+
c = data1.c;
89+
for ( i = 0; i < expected.length; i++ ) {
90+
y = median( a[i], b[i], c[i] );
91+
if ( y === expected[i] ) {
92+
t.equal( y, expected[i], 'a: '+a[i]+', b: '+b[i]+', c: '+c[i]+', y: '+y+', expected: '+expected[i] );
93+
} else {
94+
delta = abs( y - expected[ i ] );
95+
tol = 1.0 * EPS * abs( expected[ i ] );
96+
t.ok( delta <= tol, 'within tolerance. a: '+a[i]+'. b: '+b[i]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
97+
}
98+
}
99+
t.end();
100+
});
101+
102+
tape( 'the function returns the median of a triangular distribution if provided parameters satisfy `c >= (a + b) / 2`', function test( t ) {
103+
var expected;
104+
var delta;
105+
var tol;
106+
var a;
107+
var b;
108+
var c;
109+
var i;
110+
var y;
111+
112+
expected = data2.expected;
113+
a = data2.a;
114+
b = data2.b;
115+
c = data2.c;
88116
for ( i = 0; i < expected.length; i++ ) {
89117
y = median( a[i], b[i], c[i] );
90118
if ( y === expected[i] ) {

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ var EPS = require( '@stdlib/constants/float64/eps' );
3030

3131
// FIXTURES //
3232

33-
var data = require( './fixtures/julia/data.json' );
33+
var data1 = require( './fixtures/julia/data1.json' );
34+
var data2 = require( './fixtures/julia/data2.json' );
3435

3536

3637
// VARIABLES //
@@ -51,13 +52,13 @@ tape( 'main export is a function', opts, function test( t ) {
5152

5253
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
5354
var v = median( NaN, 1.0, 0.5 );
54-
t.equal( isnan( v ), true, 'returns NaN' );
55+
t.equal( isnan( v ), true, 'returns expected value' );
5556

5657
v = median( 0.0, NaN, 0.5 );
57-
t.equal( isnan( v ), true, 'returns NaN' );
58+
t.equal( isnan( v ), true, 'returns expected value' );
5859

5960
v = median( 0.0, 10.0, NaN );
60-
t.equal( isnan( v ), true, 'returns NaN' );
61+
t.equal( isnan( v ), true, 'returns expected value' );
6162

6263
t.end();
6364
});
@@ -66,21 +67,21 @@ tape( 'if provided parameters not satisfying `a <= c <= b`, the function returns
6667
var y;
6768

6869
y = median( -1.0, -1.1, -1.0 );
69-
t.equal( isnan( y ), true, 'returns NaN' );
70+
t.equal( isnan( y ), true, 'returns expected value' );
7071

7172
y = median( 3.0, 2.0, 2.5 );
72-
t.equal( isnan( y ), true, 'returns NaN' );
73+
t.equal( isnan( y ), true, 'returns expected value' );
7374

7475
y = median( 0.0, 1.0, -1.0 );
75-
t.equal( isnan( y ), true, 'returns NaN' );
76+
t.equal( isnan( y ), true, 'returns expected value' );
7677

7778
y = median( 0.0, 1.0, 2.0 );
78-
t.equal( isnan( y ), true, 'returns NaN' );
79+
t.equal( isnan( y ), true, 'returns expected value' );
7980

8081
t.end();
8182
});
8283

83-
tape( 'the function returns the median of a triangular distribution', opts, function test( t ) {
84+
tape( 'the function returns the median of a triangular distribution if provided parameters satisfy `c < (a + b) / 2`', opts, function test( t ) {
8485
var expected;
8586
var delta;
8687
var tol;
@@ -90,10 +91,37 @@ tape( 'the function returns the median of a triangular distribution', opts, func
9091
var i;
9192
var y;
9293

93-
expected = data.expected;
94-
a = data.a;
95-
b = data.b;
96-
c = data.c;
94+
expected = data1.expected;
95+
a = data1.a;
96+
b = data1.b;
97+
c = data1.c;
98+
for ( i = 0; i < expected.length; i++ ) {
99+
y = median( a[i], b[i], c[i] );
100+
if ( y === expected[i] ) {
101+
t.equal( y, expected[i], 'a: '+a[i]+', b: '+b[i]+', c: '+c[i]+', y: '+y+', expected: '+expected[i] );
102+
} else {
103+
delta = abs( y - expected[ i ] );
104+
tol = 1.0 * EPS * abs( expected[ i ] );
105+
t.ok( delta <= tol, 'within tolerance. a: '+a[i]+'. b: '+b[i]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
106+
}
107+
}
108+
t.end();
109+
});
110+
111+
tape( 'the function returns the median of a triangular distribution if provided parameters satisfy `c >= (a + b) / 2`', opts, function test( t ) {
112+
var expected;
113+
var delta;
114+
var tol;
115+
var a;
116+
var b;
117+
var c;
118+
var i;
119+
var y;
120+
121+
expected = data2.expected;
122+
a = data2.a;
123+
b = data2.b;
124+
c = data2.c;
97125
for ( i = 0; i < expected.length; i++ ) {
98126
y = median( a[i], b[i], c[i] );
99127
if ( y === expected[i] ) {

lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/test/test.factory.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,39 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',
6060

6161
mgf = factory( 0.0, 1.0, 0.5 );
6262
y = mgf( NaN );
63-
t.equal( isnan( y ), true, 'returns NaN' );
63+
t.equal( isnan( y ), true, 'returns expected value' );
6464

6565
mgf = factory( NaN, 1.0, 0.5 );
6666
y = mgf( 0.0 );
67-
t.equal( isnan( y ), true, 'returns NaN' );
67+
t.equal( isnan( y ), true, 'returns expected value' );
6868

6969
mgf = factory( 0.0, NaN, 0.5 );
7070
y = mgf( 0.0 );
71-
t.equal( isnan( y ), true, 'returns NaN' );
71+
t.equal( isnan( y ), true, 'returns expected value' );
7272

7373
mgf = factory( 0.0, 1.0, NaN );
7474
y = mgf( 0.0 );
75-
t.equal( isnan( y ), true, 'returns NaN' );
75+
t.equal( isnan( y ), true, 'returns expected value' );
7676

7777
mgf = factory( NaN, NaN, NaN );
7878
y = mgf( 0.0 );
79-
t.equal( isnan( y ), true, 'returns NaN' );
79+
t.equal( isnan( y ), true, 'returns expected value' );
8080

8181
mgf = factory( 0.0, NaN, NaN );
8282
y = mgf( 0.0 );
83-
t.equal( isnan( y ), true, 'returns NaN' );
83+
t.equal( isnan( y ), true, 'returns expected value' );
8484

8585
mgf = factory( NaN, 1.0, NaN );
8686
y = mgf( 0.0 );
87-
t.equal( isnan( y ), true, 'returns NaN' );
87+
t.equal( isnan( y ), true, 'returns expected value' );
8888

8989
mgf = factory( NaN, NaN, 0.5 );
9090
y = mgf( 0.0 );
91-
t.equal( isnan( y ), true, 'returns NaN' );
91+
t.equal( isnan( y ), true, 'returns expected value' );
9292

9393
mgf = factory( NaN, NaN, 0.5 );
9494
y = mgf( NaN );
95-
t.equal( isnan( y ), true, 'returns NaN' );
95+
t.equal( isnan( y ), true, 'returns expected value' );
9696

9797
t.end();
9898
});
@@ -104,34 +104,49 @@ tape( 'if provided parameters not satisfying `a <= c <= b`, the created function
104104
mgf = factory( 2.0, 1.0, 0.5 );
105105

106106
y = mgf( 2.0 );
107-
t.equal( isnan( y ), true, 'returns NaN' );
107+
t.equal( isnan( y ), true, 'returns expected value' );
108108

109109
y = mgf( 0.0 );
110-
t.equal( isnan( y ), true, 'returns NaN' );
110+
t.equal( isnan( y ), true, 'returns expected value' );
111111

112112
mgf = factory( 0.0, NINF, 0.5 );
113113
y = mgf( 2.0 );
114-
t.equal( isnan( y ), true, 'returns NaN' );
114+
t.equal( isnan( y ), true, 'returns expected value' );
115115

116116
mgf = factory( PINF, NINF, 0.5 );
117117
y = mgf( 2.0 );
118-
t.equal( isnan( y ), true, 'returns NaN' );
118+
t.equal( isnan( y ), true, 'returns expected value' );
119119

120120
mgf = factory( NINF, NINF, 0.5 );
121121
y = mgf( 2.0 );
122-
t.equal( isnan( y ), true, 'returns NaN' );
122+
t.equal( isnan( y ), true, 'returns expected value' );
123123

124124
mgf = factory( -1.0, -2.0, 0.5 );
125125
y = mgf( 2.0 );
126-
t.equal( isnan( y ), true, 'returns NaN' );
126+
t.equal( isnan( y ), true, 'returns expected value' );
127127

128128
mgf = factory( -10.0, 10.0, 12.0 );
129129
y = mgf( 2.0 );
130-
t.equal( isnan( y ), true, 'returns NaN' );
130+
t.equal( isnan( y ), true, 'returns expected value' );
131131

132132
mgf = factory( -10.0, 10.0, -12.0 );
133133
y = mgf( 2.0 );
134-
t.equal( isnan( y ), true, 'returns NaN' );
134+
t.equal( isnan( y ), true, 'returns expected value' );
135+
136+
t.end();
137+
});
138+
139+
tape( 'if provided valid `a`, `b`, and `c`, the function returns a function which returns `1` when provided `0` for `t`', function test( t ) {
140+
var mgf;
141+
var y;
142+
143+
mgf = factory( 0.0, 1.0, 0.5 );
144+
y = mgf( 0.0 );
145+
t.equal( y, 1.0, 'returns expected value' );
146+
147+
mgf = factory( -1.0, 1.0, 0.0 );
148+
y = mgf( 0.0 );
149+
t.equal( y, 1.0, 'returns expected value' );
135150

136151
t.end();
137152
});

0 commit comments

Comments
 (0)