Published
Edited
Apr 14, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
randMat = randomIntMatrix([2,4],.7, true, true)
Insert cell
Insert cell
Insert cell
randHMat = randomWeightMatrix(randMat,[.4,.1])
Insert cell
Insert cell
function iterateLinearList(mat, vec, avec, times) {
let res = [vec];
while (times > 0) {res.push(math.add( avec, math.multiply(mat, res[res.length - 1]))); times--};
return res;
}
Insert cell
function iterateList(iteFunc, vec, times, bounds) {
let res = [vec];
while (times > 0) {
vec = iteFunc(vec);
if (bounds != undefined) {vec = bindList(vec, bounds)};
res.push(vec)
times--};
return res;
}
Insert cell
iteVecList = iterateLinearList(randWMat, [ 20, 10], [10, 10], 3)
Insert cell
iterateLinearFunction = function (mat, avec){
return function (vec) {
return math.add(avec, math.multiply(mat, vec));
}
}
Insert cell
iteFunc = iterateLinearFunction(randWMat, [10,10]);
Insert cell
iterateList(iteFunc,[20,10],3)
Insert cell
iteFunc(iteFunc([20,10]))
Insert cell
Insert cell
function iterateLinear(mat, vec, avec, times) {
let res = vec;
while (times > 0) {res = math.add(avec, math.multiply(mat, res)); times--};
return res;
}
Insert cell
ite = iterateLinear(randWMat, [ 20, 10], [10, 10], 2)
Insert cell
Insert cell
randVector(4, 1 ,2)
Insert cell
Insert cell
randIntegerVector(4, 1 ,2)
Insert cell
Insert cell
randWMat = getColumns(randHMat, [0,1])
Insert cell
function matrixToTeXInline(mat, prec)
{
let res ="\\begin{pmatrix}\n";
mat.forEach(function(r, j) {r.map((c,i) => (res += c.toFixed(prec) + (i < r.length - 1 ? "&" : ""))); res += (j < mat.length - 1 ? "\\\\" : "")}
);
res += "\n\\end{pmatrix}";
return res;
}
Insert cell
md`
${tex`\mathbf W=${matrixToTeXInline(randWMat, 3)}`}
`
Insert cell
Insert cell
matrixToTeX(randWMat, "\\mathbf W =", 1)
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
function bindList(vec, ints)
{
return vec.map((x, i) => bind(x, ints[i]));
}
Insert cell
Insert cell
function bndExpectation (pdf, a, b, ites){
const dif = b - a;
return Array(ites).fill().reduce((acc, d, i) => {
const x = a + i * dif / (ites - 1);
return acc + x * pdf(x) * dif / ites;
},0)
}
Insert cell
Insert cell
Insert cell
function renormedPDF (pdf, m, d, ...pars){
return function(x) {
return pdf((x - m) / d, ...pars) / d
}
}
Insert cell
function renormedCDF (cdf, m, d, ...pars){
return function(x) {
return cdf((x - m) / d, ...pars)
}
}
Insert cell
function fattenPDF (pdf, a, b, epsilon2, ...pars){
return function(x) {
//return x >= a && x <= b ? (pdf(x, ...pars) + epsilon) / (1 + (b - a) * epsilon) : 0
return x >= a && x <= b ? pdf(x, ...pars) * (1 - (b - a) * epsilon2) + epsilon2: 0
}
}
Insert cell
rCDF = renormedCDF(jStat.beta.cdf, 50, 100, 2, 3)
Insert cell
rPDF = renormedPDF(jStat.beta.pdf, 50, 100, 2, 3)
Insert cell
rPDF(149)
Insert cell
{ const n=10000;
return math.sum(Array(n).fill().map((d, i) => fPDF(50 + i * 100 / n))) * 100 / n
}
Insert cell
fPDF(49.99)
Insert cell
fPDF=fattenPDF(rPDF, 50, 150, 0.0000000000001)
Insert cell
{ const n=1000;
return math.sum(Array(n).fill().map((d, i) => rPDF(50 + i * 100 / n))) * 100 / n
}
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