add lisp packages

This commit is contained in:
2020-12-05 21:29:49 +01:00
parent 85e20365ae
commit a6e2395755
7272 changed files with 1363243 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import defaultSource from "./defaultSource";
import irwinHall from "./irwinHall";
export default (function sourceRandomBates(source) {
function randomBates(n) {
var randomIrwinHall = irwinHall.source(source)(n);
return function() {
return randomIrwinHall() / n;
};
}
randomBates.source = sourceRandomBates;
return randomBates;
})(defaultSource);

View File

@@ -0,0 +1,3 @@
export default function() {
return Math.random();
}

View File

@@ -0,0 +1,13 @@
import defaultSource from "./defaultSource";
export default (function sourceRandomExponential(source) {
function randomExponential(lambda) {
return function() {
return -Math.log(1 - source()) / lambda;
};
}
randomExponential.source = sourceRandomExponential;
return randomExponential;
})(defaultSource);

View File

@@ -0,0 +1,6 @@
export {default as randomUniform} from "./uniform";
export {default as randomNormal} from "./normal";
export {default as randomLogNormal} from "./logNormal";
export {default as randomBates} from "./bates";
export {default as randomIrwinHall} from "./irwinHall";
export {default as randomExponential} from "./exponential";

View File

@@ -0,0 +1,14 @@
import defaultSource from "./defaultSource";
export default (function sourceRandomIrwinHall(source) {
function randomIrwinHall(n) {
return function() {
for (var sum = 0, i = 0; i < n; ++i) sum += source();
return sum;
};
}
randomIrwinHall.source = sourceRandomIrwinHall;
return randomIrwinHall;
})(defaultSource);

View File

@@ -0,0 +1,15 @@
import defaultSource from "./defaultSource";
import normal from "./normal";
export default (function sourceRandomLogNormal(source) {
function randomLogNormal() {
var randomNormal = normal.source(source).apply(this, arguments);
return function() {
return Math.exp(randomNormal());
};
}
randomLogNormal.source = sourceRandomLogNormal;
return randomLogNormal;
})(defaultSource);

View File

@@ -0,0 +1,28 @@
import defaultSource from "./defaultSource";
export default (function sourceRandomNormal(source) {
function randomNormal(mu, sigma) {
var x, r;
mu = mu == null ? 0 : +mu;
sigma = sigma == null ? 1 : +sigma;
return function() {
var y;
// If available, use the second previously-generated uniform random.
if (x != null) y = x, x = null;
// Otherwise, generate a new x and y.
else do {
x = source() * 2 - 1;
y = source() * 2 - 1;
r = x * x + y * y;
} while (!r || r > 1);
return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
};
}
randomNormal.source = sourceRandomNormal;
return randomNormal;
})(defaultSource);

View File

@@ -0,0 +1,17 @@
import defaultSource from "./defaultSource";
export default (function sourceRandomUniform(source) {
function randomUniform(min, max) {
min = min == null ? 0 : +min;
max = max == null ? 1 : +max;
if (arguments.length === 1) max = min, min = 0;
else max -= min;
return function() {
return source() * max + min;
};
}
randomUniform.source = sourceRandomUniform;
return randomUniform;
})(defaultSource);