Skip to content

Commit b8a9c08

Browse files
committed
fix bug where distribution instances were returning a sequence, not a single value
1 parent 921a7ee commit b8a9c08

File tree

1 file changed

+24
-40
lines changed

1 file changed

+24
-40
lines changed

src/distribution.js

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ jStat.extend( jStat.beta, {
5555
// extend the beta objects prototype
5656
(function( vals ) {
5757
for ( var item in vals ) (function( item ) {
58-
jStat.beta.prototype[ item ] = function( min, max, len ) {
59-
var alpha = this.alpha, beta = this.beta;
60-
return jStat.seq( min, max, len, function( x ) { return jStat.beta[ item ]( x, alpha, beta );});
58+
jStat.beta.prototype[ item ] = function( x ) {
59+
return jStat.beta[ item ]( x, this.alpha, this.beta );
6160
};
6261
})( vals[ item ]);
6362
})( 'pdf cdf inv'.split( ' ' ));
@@ -122,9 +121,8 @@ jStat.extend( jStat.cauchy, {
122121
// extend the cauchy objects prototype
123122
(function( vals ) {
124123
for ( var item in vals ) (function( item ) {
125-
jStat.cauchy.prototype[ item ] = function( min, max, len ) {
126-
var local = this.local, scale = this.scale;
127-
return jStat.seq( min, max, len, function( x ) { return jStat.cauchy[ item ]( x, local, scale );});
124+
jStat.cauchy.prototype[ item ] = function( x ) {
125+
return jStat.cauchy[ item ]( x, this.local, this.scale );
128126
};
129127
})( vals[ item ]);
130128
})( 'pdf cdf inv'.split( ' ' ));
@@ -191,9 +189,8 @@ jStat.extend( jStat.chisquare, {
191189
// extend the chisquare objects prototype
192190
(function( vals ) {
193191
for ( var item in vals ) (function( item ) {
194-
jStat.chisquare.prototype[ item ] = function( min, max, len ) {
195-
var dof = this.dof;
196-
return jStat.seq( min, max, len, function( x ) { return jStat.chisquare[ item ]( x, dof );});
192+
jStat.chisquare.prototype[ item ] = function( x ) {
193+
return jStat.chisquare[ item ]( x, this.dof );
197194
};
198195
})( vals[ item ]);
199196
})( 'pdf cdf inv'.split( ' ' ));
@@ -257,9 +254,8 @@ jStat.extend( jStat.exponential, {
257254
// extend the exponential objects prototype
258255
(function( vals ) {
259256
for ( var item in vals ) (function( item ) {
260-
jStat.exponential.prototype[ item ] = function( min, max, len ) {
261-
var rate = this.rate;
262-
return jStat.seq( min, max, len, function( x ) { return jStat.exponential[ item ]( x, rate );});
257+
jStat.exponential.prototype[ item ] = function( x ) {
258+
return jStat.exponential[ item ]( x, this.rate );
263259
};
264260
})( vals[ item ]);
265261
})( 'pdf cdf inv'.split( ' ' ));
@@ -323,9 +319,8 @@ jStat.extend( jStat.gamma, {
323319
// extend the gamma objects prototype
324320
(function( vals ) {
325321
for ( var item in vals ) (function( item ) {
326-
jStat.gamma.prototype[ item ] = function( min, max, len ) {
327-
var shape = this.shape, scale = this.scale;
328-
return jStat.seq( min, max, len, function( x ) { return jStat.gamma[ item ]( x, shape, scale );});
322+
jStat.gamma.prototype[ item ] = function( x ) {
323+
return jStat.gamma[ item ]( x, this.shape, this.scale );
329324
};
330325
})( vals[ item ]);
331326
})( 'pdf cdf inv'.split( ' ' ));
@@ -375,9 +370,8 @@ jStat.extend( jStat.kumaraswamy, {
375370
// extend the kumaraswamy objects prototype
376371
(function( vals ) {
377372
for ( var item in vals ) (function( item ) {
378-
jStat.kumaraswamy.prototype[ item ] = function( min, max, len ) {
379-
var alpha = this.alpha, beta = this.beta;
380-
return jStat.seq( min, max, len, function( x ) { return jStat.kumaraswamy[ item ]( x, alpha, beta );});
373+
jStat.kumaraswamy.prototype[ item ] = function( x ) {
374+
return jStat.kumaraswamy[ item ]( x, this.alpha, this.beta );
381375
};
382376
})( vals[ item ]);
383377
})( 'pdf cdf'.split( ' ' ));
@@ -442,9 +436,8 @@ jStat.extend( jStat.lognormal, {
442436
// extend the lognormal objects prototype
443437
(function( vals ) {
444438
for ( var item in vals ) (function( item ) {
445-
jStat.lognormal.prototype[ item ] = function( min, max, len ) {
446-
var mu = this.mu, sigma = this.sigma;
447-
return jStat.seq( min, max, len, function( x ) { return jStat.lognormal[ item ]( x, mu, sigma );});
439+
jStat.lognormal.prototype[ item ] = function( x ) {
440+
return jStat.lognormal[ item ]( x, this.mu, this.sigma );
448441
};
449442
})( vals[ item ]);
450443
})( 'pdf cdf inv'.split( ' ' ));
@@ -511,9 +504,8 @@ jStat.extend( jStat.normal, {
511504
// extend the normal objects prototype
512505
(function( vals ) {
513506
for ( var item in vals ) (function( item ) {
514-
jStat.normal.prototype[ item ] = function( min, max, len ) {
515-
var mean = this.mean, std = this.std;
516-
return jStat.seq( min, max, len, function( x ) { return jStat.normal[ item ]( x, mean, std );});
507+
jStat.normal.prototype[ item ] = function( x ) {
508+
return jStat.normal[ item ]( x, this.mean, this.std );
517509
};
518510
})( vals[ item ]);
519511
})( 'pdf cdf inv'.split( ' ' ));
@@ -564,9 +556,8 @@ jStat.extend( jStat.pareto, {
564556
// extend the pareto objects prototype
565557
(function( vals ) {
566558
for ( var item in vals ) (function( item ) {
567-
jStat.pareto.prototype[ item ] = function( min, max, len ) {
568-
var shape = this.shape, scale = this.scale;
569-
return jStat.seq( min, max, len, function( x ) { return jStat.pareto[ item ]( x, scale, shape );});
559+
jStat.pareto.prototype[ item ] = function( x ) {
560+
return jStat.pareto[ item ]( x, this.shape, this.scale );
570561
};
571562
})( vals[ item ]);
572563
})( 'pdf cdf'.split( ' ' ));
@@ -634,9 +625,8 @@ jStat.extend( jStat.studentt, {
634625
// extend the studentt objects prototype
635626
(function( vals ) {
636627
for ( var item in vals ) (function( item ) {
637-
jStat.studentt.prototype[ item ] = function( min, max, len ) {
638-
var dof = this.dof;
639-
return jStat.seq( min, max, len, function( x ) { return jStat.studentt[ item ]( x, dof );});
628+
jStat.studentt.prototype[ item ] = function( x ) {
629+
return jStat.studentt[ item ]( x, this.dof );
640630
};
641631
})( vals[ item ]);
642632
})( 'pdf cdf inv'.split( ' ' ));
@@ -701,9 +691,8 @@ jStat.extend( jStat.weibull, {
701691
// extend the weibull objects prototype
702692
(function( vals ) {
703693
for ( var item in vals ) (function( item ) {
704-
jStat.weibull.prototype[ item ] = function( min, max, len ) {
705-
var scale = this.scale, shape = this.shape;
706-
return jStat.seq( min, max, len, function( x ) { return jStat.weibull[ item ]( x, scale, shape );});
694+
jStat.weibull.prototype[ item ] = function( x ) {
695+
return jStat.weinbull[ item ]( x, this.scale, this.shape );
707696
};
708697
})( vals[ item ]);
709698
})( 'pdf cdf inv'.split( ' ' ));
@@ -769,9 +758,8 @@ jStat.extend( jStat.uniform, {
769758
// extend the uniform objects prototype
770759
(function( vals ) {
771760
for ( var item in vals ) (function( item ) {
772-
jStat.uniform.prototype[ item ] = function( min, max, len ) {
773-
var a = this.a, b = this.b;
774-
return jStat.seq( min, max, len, function( x ) { return jStat.uniform[ item ]( x, a, b );});
761+
jStat.uniform.prototype[ item ] = function( x ) {
762+
return jStat.uniform[ item ]( x, this.a, this.b );
775763
};
776764
})( vals[ item ]);
777765
})( 'pdf cdf inv'.split( ' ' ));
@@ -791,10 +779,6 @@ jStat.extend( jStat.uniform, {
791779
// all these still need to be implemented as their own instance methods
792780
jStat.extend({
793781

794-
// Discrete distributions //
795-
796-
// TODO: update these with proper notations.
797-
798782
// uniform distribution in terms of mean and standard dev
799783
uniformmv : {
800784
pdf : function( x, m, s ) {

0 commit comments

Comments
 (0)