Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @example
* var FLOAT32_NINF = require( '@stdlib/constants/float32/ninf' );
* // returns -infinity
* // returns -Infinity
*/

// MODULES //
Expand Down
17 changes: 11 additions & 6 deletions lib/node_modules/@stdlib/random/sample/lib/renormalizing.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

'use strict';

// MODULES //

var copy = require( '@stdlib/array/base/copy' );


// MAIN //

/**
* Samples without replacement from a discrete set using custom probabilities.
*
Expand All @@ -43,11 +50,9 @@ function renormalizing( x, size, rand, probabilities ) {
var u;

N = x.length;
probs = new Array( N );
for ( i = 0; i < N; i++ ) {
probs[ i ] = probabilities[ i ];
}
out = new Array( size );
probs = copy( probabilities );

out = [];
for ( i = 0; i < size; i++ ) {
u = rand();
psum = 0;
Expand All @@ -64,7 +69,7 @@ function renormalizing( x, size, rand, probabilities ) {
probs[ k ] /= 1.0 - probs[ j ];
}
probs[ j ] = 0.0;
out[ i ] = x[ j ];
out.push( x[ j ] );
}
return out;
}
Expand Down