File tree Expand file tree Collapse file tree 3 files changed +10
-24
lines changed
lib/node_modules/@stdlib/stats/base/dists/bernoulli/stdev Expand file tree Collapse file tree 3 files changed +10
-24
lines changed Original file line number Diff line number Diff line change 2020
2121// MODULES //
2222
23- var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
2423var sqrt = require ( '@stdlib/math/base/special/sqrt' ) ;
24+ var variance = require ( '@stdlib/stats/base/dists/bernoulli/variance' ) ;
2525
2626
2727// MAIN //
@@ -49,14 +49,7 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' );
4949* // returns NaN
5050*/
5151function stdev ( p ) {
52- if (
53- isnan ( p ) ||
54- p < 0.0 ||
55- p > 1.0
56- ) {
57- return NaN ;
58- }
59- return sqrt ( ( 1.0 - p ) * p ) ;
52+ return sqrt ( variance ( p ) ) ;
6053}
6154
6255
Original file line number Diff line number Diff line change 3939 "libpath" : [],
4040 "dependencies" : [
4141 " @stdlib/math/base/napi/unary" ,
42- " @stdlib/math/base/assert/is-nan " ,
43- " @stdlib/math /base/special/sqrt "
42+ " @stdlib/math/base/special/sqrt " ,
43+ " @stdlib/stats /base/dists/bernoulli/variance "
4444 ]
4545 },
4646 {
5555 "libraries" : [],
5656 "libpath" : [],
5757 "dependencies" : [
58- " @stdlib/math/base/assert/is-nan " ,
59- " @stdlib/math /base/special/sqrt "
58+ " @stdlib/math/base/special/sqrt " ,
59+ " @stdlib/stats /base/dists/bernoulli/variance "
6060 ]
6161 },
6262 {
7171 "libraries" : [],
7272 "libpath" : [],
7373 "dependencies" : [
74- " @stdlib/math/base/assert/is-nan " ,
75- " @stdlib/math /base/special/sqrt "
74+ " @stdlib/math/base/special/sqrt " ,
75+ " @stdlib/stats /base/dists/bernoulli/variance "
7676 ]
7777 }
7878 ]
Original file line number Diff line number Diff line change 1717*/
1818
1919#include "stdlib/stats/base/dists/bernoulli/stdev.h"
20- #include "stdlib/math/base/assert/is_nan.h"
2120#include "stdlib/math/base/special/sqrt.h"
21+ #include "stdlib/stats/base/dists/bernoulli/variance.h"
2222
2323/**
2424* Returns the standard deviation of a Bernoulli distribution.
3131* // returns ~0.3
3232*/
3333double stdlib_base_dists_bernoulli_stdev ( const double p ) {
34- if (
35- stdlib_base_is_nan ( p ) ||
36- p < 0.0 ||
37- p > 1.0
38- ) {
39- return 0.0 /0.0 ; // NaN
40- }
41- return stdlib_base_sqrt ( ( 1.0 - p ) * p );
34+ return stdlib_base_sqrt ( stdlib_base_dists_bernoulli_variance ( p ) );
4235}
You can’t perform that action at this time.
0 commit comments