flow like the river

This commit is contained in:
root 2025-11-07 00:06:12 +01:00
commit 013fe673f3
42435 changed files with 5764238 additions and 0 deletions

3
VISUALIZACION/node_modules/ngraph.random/.travis.yml generated vendored Executable file
View file

@ -0,0 +1,3 @@
language: node_js
node_js:
- node

27
VISUALIZACION/node_modules/ngraph.random/LICENSE generated vendored Executable file
View file

@ -0,0 +1,27 @@
Copyright (c) 2013-2020, Andrei Kashcha
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the Andrei Kashcha nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

89
VISUALIZACION/node_modules/ngraph.random/README.md generated vendored Executable file
View file

@ -0,0 +1,89 @@
ngraph.random
=============
Operation with seeded random numbers for ngraph.*.
[![build status](https://secure.travis-ci.org/anvaka/ngraph.random.png)](http://travis-ci.org/anvaka/ngraph.random)
Install
=======
You can use CDN:
``` html
<script src='https://cdn.jsdelivr.net/npm/ngraph.random/dist/ngraph.random.js'></script>
```
or via [npm](http://npmjs.org):
```
npm install ngraph.random
```
and then:
``` js
var ngraphRandom = require('ngraph.random);
```
Usage
=====
API provides random number generation, and array shuffling.
Let's start with random number generation:
``` js
// create generator, seeded with 42
var randomGenerator = ngraphRandom(42);
// prints double number from [0..1)
console.log(randomGenerator.nextDouble());
// Get next non-negative random number, less than 100.
console.log(randomGenerator.next(100)); // prints 20, we are seeded
// Note: next() always expect maxValue. If you don't pass it it will return NaN.
// This is done for performance reasons, we don't want to check input arguments
// on each call.
```
Second part of the API is array shuffling:
``` js
var ngraphRandom = require('ngraph.random');
// create "shuffling" iterator:
var originalArray = [0, 1, 2, 3, 4, 5];
var randomIterator = ngraphRandom.randomIterator(originalArray);
// iterate over array in random order:
randomIterator.forEach(function(x) {
console.log(x); // prints originalArray's items in random order
});
// Note: using random iterator does modify original array.
// This is done to save memory.
// If you want to re-shuffle array in-place, you can use:
randomIterator.shuffle();
// Finally if you want to have seeded shuffling you can pass optional seeded
// random number generator:
var seededGenerator = ngraphRandom.random(42);
ngraphRandom.randomIterator(originalArray, seededGenerator);
```
## distributions
The library supports random number generation that follow Gaussian distribution:
``` js
var generator = ngraphRandom(42);
// returns a random number from a gaussian distribution with mean 0 and
// standard deviation 1
generator.gaussian();
```
License
=======
BSD 3-clause

View file

@ -0,0 +1,143 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ngraphRandom = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = random;
// TODO: Deprecate?
module.exports.random = random,
module.exports.randomIterator = randomIterator
/**
* Creates seeded PRNG with two methods:
* next() and nextDouble()
*/
function random(inputSeed) {
var seed = typeof inputSeed === 'number' ? inputSeed : (+new Date());
return new Generator(seed)
}
function Generator(seed) {
this.seed = seed;
}
/**
* Generates random integer number in the range from 0 (inclusive) to maxValue (exclusive)
*
* @param maxValue Number REQUIRED. Omitting this number will result in NaN values from PRNG.
*/
Generator.prototype.next = next;
/**
* Generates random double number in the range from 0 (inclusive) to 1 (exclusive)
* This function is the same as Math.random() (except that it could be seeded)
*/
Generator.prototype.nextDouble = nextDouble;
/**
* Returns a random real number from uniform distribution in [0, 1)
*/
Generator.prototype.uniform = nextDouble;
/**
* Returns a random real number from a Gaussian distribution
* with 0 as a mean, and 1 as standard deviation u ~ N(0,1)
*/
Generator.prototype.gaussian = gaussian;
function gaussian() {
// use the polar form of the Box-Muller transform
// based on https://introcs.cs.princeton.edu/java/23recursion/StdRandom.java
var r, x, y;
do {
x = this.nextDouble() * 2 - 1;
y = this.nextDouble() * 2 - 1;
r = x * x + y * y;
} while (r >= 1 || r === 0);
return x * Math.sqrt(-2 * Math.log(r)/r);
}
/**
* See https://twitter.com/anvaka/status/1296182534150135808
*/
Generator.prototype.levy = levy;
function levy() {
var beta = 3 / 2;
var sigma = Math.pow(
gamma( 1 + beta ) * Math.sin(Math.PI * beta / 2) /
(gamma((1 + beta) / 2) * beta * Math.pow(2, (beta - 1) / 2)),
1/beta
);
return this.gaussian() * sigma / Math.pow(Math.abs(this.gaussian()), 1/beta);
}
// gamma function approximation
function gamma(z) {
return Math.sqrt(2 * Math.PI / z) * Math.pow((1 / Math.E) * (z + 1 / (12 * z - 1 / (10 * z))), z);
}
function nextDouble() {
var seed = this.seed;
// Robert Jenkins' 32 bit integer hash function.
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff;
seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
this.seed = seed;
return (seed & 0xfffffff) / 0x10000000;
}
function next(maxValue) {
return Math.floor(this.nextDouble() * maxValue);
}
/*
* Creates iterator over array, which returns items of array in random order
* Time complexity is guaranteed to be O(n);
*/
function randomIterator(array, customRandom) {
var localRandom = customRandom || random();
if (typeof localRandom.next !== 'function') {
throw new Error('customRandom does not match expected API: next() function is missing');
}
return {
forEach: forEach,
/**
* Shuffles array randomly, in place.
*/
shuffle: shuffle
};
function shuffle() {
var i, j, t;
for (i = array.length - 1; i > 0; --i) {
j = localRandom.next(i + 1); // i inclusive
t = array[j];
array[j] = array[i];
array[i] = t;
}
return array;
}
function forEach(callback) {
var i, j, t;
for (i = array.length - 1; i > 0; --i) {
j = localRandom.next(i + 1); // i inclusive
t = array[j];
array[j] = array[i];
array[i] = t;
callback(t);
}
if (array.length) {
callback(array[0]);
}
}
}
},{}]},{},[1])(1)
});

View file

@ -0,0 +1 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ngraphRandom=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){module.exports=random;module.exports.random=random,module.exports.randomIterator=randomIterator;function random(inputSeed){var seed=typeof inputSeed==="number"?inputSeed:+new Date;return new Generator(seed)}function Generator(seed){this.seed=seed}Generator.prototype.next=next;Generator.prototype.nextDouble=nextDouble;Generator.prototype.uniform=nextDouble;Generator.prototype.gaussian=gaussian;function gaussian(){var r,x,y;do{x=this.nextDouble()*2-1;y=this.nextDouble()*2-1;r=x*x+y*y}while(r>=1||r===0);return x*Math.sqrt(-2*Math.log(r)/r)}Generator.prototype.levy=levy;function levy(){var beta=3/2;var sigma=Math.pow(gamma(1+beta)*Math.sin(Math.PI*beta/2)/(gamma((1+beta)/2)*beta*Math.pow(2,(beta-1)/2)),1/beta);return this.gaussian()*sigma/Math.pow(Math.abs(this.gaussian()),1/beta)}function gamma(z){return Math.sqrt(2*Math.PI/z)*Math.pow(1/Math.E*(z+1/(12*z-1/(10*z))),z)}function nextDouble(){var seed=this.seed;seed=seed+2127912214+(seed<<12)&4294967295;seed=(seed^3345072700^seed>>>19)&4294967295;seed=seed+374761393+(seed<<5)&4294967295;seed=(seed+3550635116^seed<<9)&4294967295;seed=seed+4251993797+(seed<<3)&4294967295;seed=(seed^3042594569^seed>>>16)&4294967295;this.seed=seed;return(seed&268435455)/268435456}function next(maxValue){return Math.floor(this.nextDouble()*maxValue)}function randomIterator(array,customRandom){var localRandom=customRandom||random();if(typeof localRandom.next!=="function"){throw new Error("customRandom does not match expected API: next() function is missing")}return{forEach:forEach,shuffle:shuffle};function shuffle(){var i,j,t;for(i=array.length-1;i>0;--i){j=localRandom.next(i+1);t=array[j];array[j]=array[i];array[i]=t}return array}function forEach(callback){var i,j,t;for(i=array.length-1;i>0;--i){j=localRandom.next(i+1);t=array[j];array[j]=array[i];array[i]=t;callback(t)}if(array.length){callback(array[0])}}}},{}]},{},[1])(1)});

140
VISUALIZACION/node_modules/ngraph.random/index.js generated vendored Executable file
View file

@ -0,0 +1,140 @@
module.exports = random;
// TODO: Deprecate?
module.exports.random = random,
module.exports.randomIterator = randomIterator
/**
* Creates seeded PRNG with two methods:
* next() and nextDouble()
*/
function random(inputSeed) {
var seed = typeof inputSeed === 'number' ? inputSeed : (+new Date());
return new Generator(seed)
}
function Generator(seed) {
this.seed = seed;
}
/**
* Generates random integer number in the range from 0 (inclusive) to maxValue (exclusive)
*
* @param maxValue Number REQUIRED. Omitting this number will result in NaN values from PRNG.
*/
Generator.prototype.next = next;
/**
* Generates random double number in the range from 0 (inclusive) to 1 (exclusive)
* This function is the same as Math.random() (except that it could be seeded)
*/
Generator.prototype.nextDouble = nextDouble;
/**
* Returns a random real number from uniform distribution in [0, 1)
*/
Generator.prototype.uniform = nextDouble;
/**
* Returns a random real number from a Gaussian distribution
* with 0 as a mean, and 1 as standard deviation u ~ N(0,1)
*/
Generator.prototype.gaussian = gaussian;
function gaussian() {
// use the polar form of the Box-Muller transform
// based on https://introcs.cs.princeton.edu/java/23recursion/StdRandom.java
var r, x, y;
do {
x = this.nextDouble() * 2 - 1;
y = this.nextDouble() * 2 - 1;
r = x * x + y * y;
} while (r >= 1 || r === 0);
return x * Math.sqrt(-2 * Math.log(r)/r);
}
/**
* See https://twitter.com/anvaka/status/1296182534150135808
*/
Generator.prototype.levy = levy;
function levy() {
var beta = 3 / 2;
var sigma = Math.pow(
gamma( 1 + beta ) * Math.sin(Math.PI * beta / 2) /
(gamma((1 + beta) / 2) * beta * Math.pow(2, (beta - 1) / 2)),
1/beta
);
return this.gaussian() * sigma / Math.pow(Math.abs(this.gaussian()), 1/beta);
}
// gamma function approximation
function gamma(z) {
return Math.sqrt(2 * Math.PI / z) * Math.pow((1 / Math.E) * (z + 1 / (12 * z - 1 / (10 * z))), z);
}
function nextDouble() {
var seed = this.seed;
// Robert Jenkins' 32 bit integer hash function.
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff;
seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
this.seed = seed;
return (seed & 0xfffffff) / 0x10000000;
}
function next(maxValue) {
return Math.floor(this.nextDouble() * maxValue);
}
/*
* Creates iterator over array, which returns items of array in random order
* Time complexity is guaranteed to be O(n);
*/
function randomIterator(array, customRandom) {
var localRandom = customRandom || random();
if (typeof localRandom.next !== 'function') {
throw new Error('customRandom does not match expected API: next() function is missing');
}
return {
forEach: forEach,
/**
* Shuffles array randomly, in place.
*/
shuffle: shuffle
};
function shuffle() {
var i, j, t;
for (i = array.length - 1; i > 0; --i) {
j = localRandom.next(i + 1); // i inclusive
t = array[j];
array[j] = array[i];
array[i] = t;
}
return array;
}
function forEach(callback) {
var i, j, t;
for (i = array.length - 1; i > 0; --i) {
j = localRandom.next(i + 1); // i inclusive
t = array[j];
array[j] = array[i];
array[i] = t;
callback(t);
}
if (array.length) {
callback(array[0]);
}
}
}

29
VISUALIZACION/node_modules/ngraph.random/package.json generated vendored Executable file
View file

@ -0,0 +1,29 @@
{
"name": "ngraph.random",
"version": "1.1.0",
"description": "Operation with random numbers for ngraph.*",
"main": "index.js",
"scripts": {
"test": "tap test/*.js",
"build": "browserify index.js -s ngraphRandom -o dist/ngraph.random.js && uglifyjs dist/ngraph.random.js -o dist/ngraph.random.min.js"
},
"repository": {
"type": "git",
"url": "https://github.com/anvaka/ngraph.random.git"
},
"keywords": [
"ngraph",
"ngraphjs"
],
"author": "Andrei Kashcha",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/anvaka/ngraph.random/issues"
},
"devDependencies": {
"benchmark": "^2.1.2",
"seedrandom": "^2.4.2",
"uglify-js": "^3.10.0",
"tap": "^14.10.8"
}
}

46
VISUALIZACION/node_modules/ngraph.random/perf/index.js generated vendored Executable file
View file

@ -0,0 +1,46 @@
var random = require('../').random(42)
var seedrandom = require('seedrandom');
var alea = seedrandom.alea(42);
var xor128 = seedrandom.xor128(42);
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var testCount = 200;
var randomNumbers = [];
// add tests
suite.add('Native Math.random()', function() {
var sum = 0;
for (var i = 0; i < testCount; ++i) {
sum += Math.random();
}
randomNumbers.push(sum);
}).add('ngraph.random', function() {
var sum = 0;
for (var i = 0; i < testCount; ++i) {
sum += random.nextDouble()
}
randomNumbers.push(sum);
})
.add('xor128', function() {
var sum = 0;
for (var i = 0; i < testCount; ++i) {
var res = xor128.double();
sum += res
}
randomNumbers.push(sum);
})
.add('alea', function() {
var sum = 0;
for (var i = 0; i < testCount; ++i) {
var res = alea.double();
sum += res
}
randomNumbers.push(sum);
})
.on('cycle', function(event) {
randomNumbers = [];
console.log(String(event.target));
})
.run();

39
VISUALIZACION/node_modules/ngraph.random/test/random.js generated vendored Executable file
View file

@ -0,0 +1,39 @@
var test = require('tap').test,
randomAPI = require('..');
test('random iterator returns all items', function (t) {
var a = [1, 2, 3, 4, 5, 6],
aCopy = a.map(function (i) { return i; }),
shuffle = randomAPI.randomIterator(aCopy),
iterated = [];
shuffle.forEach(function (i) {
iterated.push(i);
t.ok(a.indexOf(i) !== -1, 'Shuffle iterator should return only items from original array. Passed ' + i);
});
t.ok(iterated.length === a.length, 'Number of iterated items does not match number of original array items');
t.end();
});
test('Same seed gives same values', function (t) {
var random1 = randomAPI.random(42);
var random2 = randomAPI.random(42);
t.equal(random1.next(100), random2.next(100), "Same seed should give same values");
t.end();
});
test('it can generate gaussian', function (t) {
var random = randomAPI.random(42);
t.ok(typeof random.gaussian() === 'number', 'number generated');
t.end();
});
test('can use function syntax', function (t) {
var random1 = randomAPI(42);
var random2 = randomAPI.random(42);
t.equal(random1.nextDouble(), random2.nextDouble(), "Same seed should give same values");
t.end();
});