Public
Edited
Aug 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { histogram } from "@jonhelfman/histogram"
Insert cell
function metalog(randIn, lowValueIn, medianValueIn, highValueIn) {
// const boundedness = "u"; // (u, sl, su, b) this example is ONLY using the unbounded
const lowProb = 0.1; //lowProbability; // fixed at 10% to keep is simple for now
// const lowerBnd = ""; // currently only unbounded in this notebook.
const low = lowValueIn; // value found at the lowProbability
const median = medianValueIn;
const high = highValueIn;
// const upperBnd = 100;
const probabilityOfy = randIn; // use rand unif to simulate or enter a probability for one CDFx on dist

var cdfX =
median +
0.5 *
Math.pow(
(1 - lowProb) / lowProb,
-1 / Math.exp(1) // (probabilityOfy / (1 - probabilityOfy)) // !double check this against whitepaper
) *
(high - low) *
Math.log(probabilityOfy / (1 - probabilityOfy)) +
Math.pow((1 - 2 * lowProb) * Math.log((1 - lowProb) / lowProb), -1) *
(1 - (2 * (high - median)) / (high - low)) *
(high - low) *
(probabilityOfy - 0.5) *
Math.log(probabilityOfy / (1 - probabilityOfy));

var cdfX2 =
median +
0.5 *
Math.pow((1 - 0.1) / 0.1, -1 / Math.exp(1)) *
(high - low) *
Math.log(probabilityOfy / (1 - probabilityOfy)) +
Math.pow((1 - 2 * 0.1) * Math.log((1 - 0.1) / 0.1), -1) *
(1 - (2 * (high - median)) / (high - low)) *
(high - low) *
(probabilityOfy - 0.5) *
Math.log(probabilityOfy / (1 - probabilityOfy));

return cdfX2;
}
Insert cell
test = metalogBounded(0.9, 0.01, 0.05, 0.12, 1, 0)
Insert cell
function metalogBounded(
randIn,
lowValueIn,
medianValueIn,
highValueIn,
upperBound,
lowerBound
) {
// const boundedness = "u"; // (u, sl, su, b) this example is ONLY using the unbounded
const lowProb = 0.1; //lowProbability; // fixed at 10% to keep is simple for now
const low = lowValueIn; // value found at the lowProbability
const median = medianValueIn;
const high = highValueIn;
const probabilityOfy = randIn; // use rand unif to simulate or enter a probability for one CDFx on dist

const cdfX =
(lowerBound +
upperBound *
Math.exp(
Math.log((median - lowerBound) / (upperBound - median)) +
(1 / 2) *
Math.log((1 - lowProb) / lowProb) *
Math.pow(-1, -1) *
Math.log(
(high - lowerBound) /
(upperBound - high) /
(low - lowerBound) /
(upperBound - low)
) *
Math.log(probabilityOfy / (1 - probabilityOfy)) +
Math.pow(
Math.pow(
(1 - 2 * lowProb) * Math.log((1 - lowProb) / lowProb),
-1
) *
Math.log(
(((high - lowerBound) / (upperBound - high)) *
((low - lowerBound) / (upperBound - low))) /
Math.pow((median - lowerBound) / (upperBound - median), 2)
) *
(probabilityOfy - 0.5) *
Math.log(probabilityOfy / (1 - probabilityOfy)),
1
)
)) /
(1 +
Math.exp(
Math.log((median - lowerBound) / (upperBound - median)) +
(1 / 2) *
Math.log((1 - lowProb) / lowProb) *
Math.pow(-1, -1) *
Math.log(
(high - lowerBound) /
(upperBound - high) /
(low - lowerBound) /
(upperBound - low)
) *
Math.log(probabilityOfy / (1 - probabilityOfy)) +
Math.pow(
Math.pow(
(1 - 2 * lowProb) * Math.log((1 - lowProb) / lowProb),
-1
) *
Math.log(
(((high - lowerBound) / (upperBound - high)) *
((low - lowerBound) / (upperBound - low))) /
Math.pow((median - lowerBound) / (upperBound - median), 2)
) *
(probabilityOfy - 0.5) *
Math.log(probabilityOfy / (1 - probabilityOfy)),
1
)
));

return cdfX;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more