Published
Edited
Mar 23, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
init(nodes)
Insert cell
function init(nodes, rootNode) {
rootNode = rootNode || nodes[0];

const children = getChildren(nodes, rootNode);
const parents = rootNode.parents.length || 1;
const cost = rootNode.done ? 0 : rootNode.cost || 0;

rootNode.costPrime =
children.reduce((cost, node) => cost + init(nodes, node), cost) / parents;

// if we are at a leaf node, we'll climb back up the tree
if (children.length === 0) {
computeReward(nodes, rootNode);
}

if (rootNode === nodes[0]) {
let nextNodeValue = -Infinity;
let nextNode = null;
for (let node of nodes) {
if (getValue(node) > getValue(nextNode) && !node.done) {
if (nextNode) {
nextNode.next = false;
}
nextNode = node;
node.next = true;
} else {
node.next = false;
}
}
}

return rootNode.costPrime;
}
Insert cell
function getValue(node) {
if (node && node.costPrime && node.rewardPrime) {
return node.rewardPrime / node.costPrime;
} else {
return -Infinity;
}
}
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