() => { var script = document.createElement("script"); script.src = "https://visjs.github.io/vis-network/standalone/umd/vis-network.min.js"; document.head.appendChild(script); // var current_options; // var node_pass_prob, prelen, max_path, node_tokens, node_probs, links, tarlen; // var visible_nodes, map_max_path; // var visible_edges, sorted_links_out, sorted_links_in; // var nodes, edges, network; // var disable_edge_select; showing_node = undefined; showing_edge = undefined; function obtain_node_object(node_id) { var title = "Node " + node_id.toString() + " (Pass Prob = " + node_pass_prob[node_id].toFixed(2) + ")\n"; title += "==========\n" for(var j=0;j<5;j++){ if(node_probs[node_id][j]> 0.01){ title += node_tokens[node_id][j] + "\t" + node_probs[node_id][j].toFixed(2) + "\n"; } } var currentNode = {"id": node_id, "label": node_tokens[node_id][0], "value":node_pass_prob[node_id], "title": title}; if (current_options.show_node_detail){ currentNode.label = title; } if(map_max_path[node_id] !== undefined){ currentNode.x = map_max_path[node_id].x; currentNode.y = map_max_path[node_id].y; currentNode.fixed = true; currentNode.mass = 5; currentNode.color = {border: "red", background: "orange", highlight: {border: "red", background: "#ffcc66"}}; } return currentNode; } function set_node_visibility(node_id, flag){ if(visible_nodes[node_id] == flag) return; visible_nodes[node_id] = flag; if(flag){ nodes.add(obtain_node_object(node_id)); }else{ nodes.remove(node_id); } } function update_visible_nodes(clear_state=false){ if(typeof visible_nodes === "undefined" || clear_state){ visible_nodes = [...Array(prelen)].map((_, __) => false); // size: [prelen] map_max_path = {}; // {node_id -> position on max_path} var accumulated_x = 0; for (var i=0;i= current_options.minimum_node_pass_prob || map_max_path[i] !== undefined){ set_node_visibility(i, true); }else{ set_node_visibility(i, false); } } } function update_node_details(){ for(var i=0;i {return [...Array(prelen)].map((_, __) => false);}); // size: [prelen, prelen] sorted_links_out = []; // size: [prelen, prelen] for (var i=0;i {return {'idx': idx, 'val': val};}). sort((v1, v2) => v2.val - v1.val) ); } sorted_links_in = []; // size: [prelen, prelen], element {idx, val}, from big to small for (var i=0;i v2.val - v1.val)); } edges = new vis.DataSet(); } var next_visible_edges = [...Array(prelen)].map((_, __) => {return [...Array(prelen)].map((_, __) => false);}); // size: [prelen, prelen] var links_in_num = [...Array(prelen)].map((_, __) => 0); for (var i=0;i 0) continue; for(var j=0; j/g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function get_jumpable_node(idx){ if(visible_nodes[idx]){ return "" + idx.toString() + ""; }else{ return "" + idx.toString() + ""; } } function get_jumpable_edge(i, j, label){ var edge_id = i.toString() + "-" + j.toString(); if(visible_edges[i][j]){ return "" + label + ""; }else{ return "" + label + ""; } } show_hint_node = function(node_id){ showing_node = node_id; showing_edge = undefined; var title = "

You selected Node " + node_id.toString() + " "; if (visible_nodes[node_id]){ title += "(Find Me!). " }else{ title += "(Not shown). " } title += "Passing Probability: " + node_pass_prob[node_id].toFixed(2) + ". You can click the links below to jump to other edges or nodes.

"; document.getElementById("hintsupper").innerHTML = title; title = ""; for (var j=0;j<5;j++){ title += ""; } title += "" title += "

Top-5 Token Candidates:

"; document.getElementById("hintsleft").innerHTML = title; title = "
RankCandidateProbability
#" + (j+1).toString() + "" + escapeHtml(node_tokens[node_id][j]) + "" + node_probs[node_id][j].toFixed(2) + "
"; for (var j=0;j"; } } title += "" title += "

Top Outgoing Edges:

" document.getElementById("hintscenter").innerHTML = title; title = "
RankToTransition Prob.Passing Prob.
" + get_jumpable_node(idx) + "" + links[node_id][idx].toFixed(2) + "" + (node_pass_prob[node_id] * links[node_id][idx]).toFixed(2) + "
"; for (var j=0;j"; } } title += "" title += "

Top Incoming Edges:

" document.getElementById("hintsright").innerHTML = title; document.getElementById("hintsbottom").innerHTML = "
"+ "Passing probability of a node V represents how likely the node will be choosen in a random path, i.e., P(V \\in A).
" + "Passing probability of an edge from U to V represents how likely the node V follows the node U in a random path, i.e., P(a_i = U && a_{i+1} = V).
" + "Token probability represents how likely a token is predicted on the given node, i.e., P(y_i| v_{a_{i}}).
" + "Transition probability represents how likely a specific node is following the given node, i.e. P(a_{i+1} | a_{i}).
" } show_hint_edge = function(edge_id){ showing_edge = edge_id; showing_node = undefined; var i = parseInt(edge_id.split("-")[0]); var j = parseInt(edge_id.split("-")[1]); var label = links[i][j].toFixed(2); var passing_label = (links[i][j] * node_pass_prob[i]).toFixed(2); var title = "You selected an edge from Node " + get_jumpable_node(i) + " to Node " + get_jumpable_node(j) + "." if (visible_edges[i][j]){ title += "(Find Me!). " }else{ title += "(Not shown). " } title += "
You can click the links above to jump to the nodes.

" title += "Transition Probability:" + label + "
"; title += "Passing Probability:" + passing_label + "
"; title += "
" + "Transition probability represents how likely a specific node is following the given node, i.e. P(a_{i+1} | a_{i}).
" + "Passing probability of an edge from U to V represents how likely the node V follows the node U in a random path, i.e., P(a_i = U && a_{i+1} = V).
" document.getElementById("hintsupper").innerHTML = title; document.getElementById("hintsleft").innerHTML = ""; document.getElementById("hintsright").innerHTML = ""; document.getElementById("hintscenter").innerHTML = ""; document.getElementById("hintsbottom").innerHTML = ""; } function clear_hint(){ showing_node = undefined; showing_edge = undefined; document.getElementById("hintsupper").innerHTML = "Use scroll to zoom in or out. Select or Hover over nodes and edges for more information ... (Try dragging nodes to replace them.)"; document.getElementById("hintsleft").innerHTML = ""; document.getElementById("hintsright").innerHTML = ""; document.getElementById("hintscenter").innerHTML = ""; document.getElementById("hintsbottom").innerHTML = ""; } startNetwork = function(graph_info, options) { current_options = options; global_graph_info = graph_info; node_pass_prob = graph_info['node_pass_prob'][0] // size: [prelen] prelen = node_pass_prob.length max_path = graph_info['max_paths'][0] // size: [tarlen] tarlen = max_path.length node_tokens = graph_info['node_tokens'][0] // size: [prelen, 5] node_probs = graph_info['node_probs'][0] // size: [prelen, 5] links = graph_info['links'][0] // size: [prelen, prelen] update_visible_nodes(true); update_visible_edges(true); // create a network var container = document.getElementById("daggraph"); var data = { nodes: nodes, edges: edges, }; network_options = { nodes: { shape: "ellipse", scaling: { label: { min: 8, max: 20, }, customScalingFunction: customScalingFunction, }, }, edges: { arrowStrikethrough: false, arrows: "to", smooth: { type: "continuous" }, color: "#2B7CE9", font: { align: "bottom" }, length: 120, scaling: { min: 0.5, max: 3, label: { min: 8, max: 15, }, customScalingFunction: customScalingFunction, } } }; network = new vis.Network(container, data, network_options); network.off("dragStart"); network.on("dragStart", function (params) { var idx = this.getNodeAt(params.pointer.DOM); if (idx !== undefined) { // console.log("dragstart " + idx.toString()); if (map_max_path[idx] !== undefined){ data.nodes.update({id: idx, fixed: false}); } } }); network.off("dragEnd"); network.on("dragEnd", function (params) { var idx = this.getNodeAt(params.pointer.DOM); if (idx !== undefined){ // console.log("dragend " + idx.toString()); if (map_max_path[idx] !== undefined){ data.nodes.update({id: idx, fixed: true}); map_max_path[idx].x = params.pointer.canvas.x; map_max_path[idx].y = params.pointer.canvas.y; } } }); disable_edge_select = false; network.off("selectNode"); network.on("selectNode", function (params) { var node_id = params.nodes[0]; show_hint_node(node_id); disable_edge_select = true; setTimeout(() => {disable_edge_select=false;}, 200); }); network.off("selectEdge"); network.on("selectEdge", function (params) { if(disable_edge_select) return; var edge_id = params.edges[0]; show_hint_edge(edge_id); }); network.off("deselectNode"); network.on("deselectNode", function (params) { clear_hint(); showing_node = undefined; showing_edge = undefined; }); network.off("deselectEdge"); network.on("deselectEdge", function (params) { clear_hint(); }); } updateNetwork = function(options) { if(typeof node_pass_prob === "undefined") return; old_options = current_options; current_options = options; if(options.minimum_node_pass_prob != old_options.minimum_node_pass_prob){ update_visible_nodes(); } if(options.minimum_node_pass_prob != old_options.minimum_node_pass_prob || options.minimum_edge_prob != old_options.minimum_edge_prob || options.max_out_edge_num != old_options.max_out_edge_num || options.max_out_edge_prob != old_options.max_out_edge_prob || options.force_in_edge != old_options.force_in_edge){ update_visible_edges(); } if(options.show_node_detail != old_options.show_node_detail){ if(options.show_node_detail) { network_options.nodes.shape = "dot"; network_options.nodes.scaling.label.min=10; network_options.nodes.scaling.label.max=10; }else{ network_options.nodes.shape = "ellipse"; network_options.nodes.scaling.label.min=8; network_options.nodes.scaling.label.max=20; } network.setOptions(network_options); update_node_details(); } if(options.show_edge_label != old_options.show_edge_label){ update_edge_label(); } if(showing_node != undefined){ show_hint_node(showing_node); } if(showing_edge != undefined){ show_hint_edge(showing_edge); } } }
RankFromTransition Prob.Passing Prob.
" + get_jumpable_node(idx) + "" + links[idx][node_id].toFixed(2) + "" + (node_pass_prob[idx] * links[idx][node_id]).toFixed(2) + "