Skip to content

Commit 3b0aaac

Browse files
committed
Fix bug when computing correction term
1 parent 1723a33 commit 3b0aaac

11 files changed

Lines changed: 11 additions & 22 deletions

File tree

lib/node_modules/@stdlib/stats/base/dsvariancepn/lib/dsvariancepn.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ function dsvariancepn( N, correction, x, stride ) {
8585
M += d;
8686
ix += stride;
8787
}
88-
M /= n;
89-
return (M2/n) - (M*M);
88+
return (M2/n) - ((M/N)*(M/n));
9089
}
9190

9291

lib/node_modules/@stdlib/stats/base/dsvariancepn/lib/ndarray.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ function dsvariancepn( N, correction, x, stride, offset ) {
8383
M += d;
8484
ix += stride;
8585
}
86-
M /= n;
87-
return (M2/n) - (M*M);
86+
return (M2/n) - ((M/N)*(M/n));
8887
}
8988

9089

lib/node_modules/@stdlib/stats/base/dsvariancepn/src/dsvariancepn.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ double stdlib_strided_dsvariancepn( const int64_t N, const float correction, con
7171
M += d;
7272
ix += stride;
7373
}
74-
M /= n;
75-
return (M2/n) - (M*M);
74+
return (M2/n) - ((M/N)*(M/n));
7675
}

lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ function dvariancepn( N, correction, x, stride ) {
8585
M += d;
8686
ix += stride;
8787
}
88-
M /= n;
89-
return (M2/n) - (M*M);
88+
return (M2/n) - ((M/N)*(M/n));
9089
}
9190

9291

lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ function dvariancepn( N, correction, x, stride, offset ) {
8383
M += d;
8484
ix += stride;
8585
}
86-
M /= n;
87-
return (M2/n) - (M*M);
86+
return (M2/n) - ((M/N)*(M/n));
8887
}
8988

9089

lib/node_modules/@stdlib/stats/base/dvariancepn/src/dvariancepn.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ double stdlib_strided_dvariancepn( const int64_t N, const double correction, con
7171
M += d;
7272
ix += stride;
7373
}
74-
M /= n;
75-
return (M2/n) - (M*M);
74+
return (M2/n) - ((M/N)*(M/n));
7675
}

lib/node_modules/@stdlib/stats/base/svariancepn/lib/ndarray.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ function svariancepn( N, correction, x, stride, offset ) {
8484
M = float64ToFloat32( M + d );
8585
ix += stride;
8686
}
87-
M = float64ToFloat32( M / n );
88-
return float64ToFloat32( float64ToFloat32(M2/n) - float64ToFloat32(M*M) );
87+
return float64ToFloat32( float64ToFloat32(M2/n) - float64ToFloat32( float64ToFloat32(M/N)*float64ToFloat32(M/n) ) ); // eslint-disable-line max-len
8988
}
9089

9190

lib/node_modules/@stdlib/stats/base/svariancepn/lib/svariancepn.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ function svariancepn( N, correction, x, stride ) {
8686
M = float64ToFloat32( M + d );
8787
ix += stride;
8888
}
89-
M = float64ToFloat32( M / n );
90-
return float64ToFloat32( float64ToFloat32(M2/n) - float64ToFloat32(M*M) );
89+
return float64ToFloat32( float64ToFloat32(M2/n) - float64ToFloat32( float64ToFloat32(M/N)*float64ToFloat32(M/n) ) ); // eslint-disable-line max-len
9190
}
9291

9392

lib/node_modules/@stdlib/stats/base/svariancepn/src/svariancepn.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ float stdlib_strided_svariancepn( const int64_t N, const float correction, const
7171
M += d;
7272
ix += stride;
7373
}
74-
M /= n;
75-
return (M2/n) - (M*M);
74+
return (M2/n) - ((M/N)*(M/n));
7675
}

lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ function variancepn( N, correction, x, stride, offset ) {
8282
M += d;
8383
ix += stride;
8484
}
85-
M /= n;
86-
return (M2/n) - (M*M);
85+
return (M2/n) - ((M/N)*(M/n));
8786
}
8887

8988

0 commit comments

Comments
 (0)