提交 07978a50 authored 作者: Christof Angermueller's avatar Christof Angermueller

Shorten node labels and show additional details

上级 83012726
.d3-context-menu {
position: absolute;
display: none;
background-color: #f2f2f2;
border-radius: 4px;
font-family: Arial, sans-serif;
font-size: 14px;
min-width: 50px;
border: 1px solid #d4d4d4;
z-index:1200;
}
.d3-context-menu ul {
list-style-type: none;
margin: 4px 0px;
padding: 0px;
cursor: default;
}
.d3-context-menu ul li {
padding: 4px 16px;
}
.d3-context-menu ul li:hover {
background-color: #4677f8;
color: #fefefe;
}
d3.contextMenu = function (menu, openCallback) {
// create the div element that will hold the context menu
d3.selectAll('.d3-context-menu').data([1])
.enter()
.append('div')
.attr('class', 'd3-context-menu');
// close menu
d3.select('body').on('click.d3-context-menu', function() {
d3.select('.d3-context-menu').style('display', 'none');
});
// this gets executed when a contextmenu event occurs
return function(data, index) {
var elm = this;
d3.selectAll('.d3-context-menu').html('');
var list = d3.selectAll('.d3-context-menu').append('ul');
list.selectAll('li').data(menu).enter()
.append('li')
.html(function(d) {
return d.title;
})
.on('click', function(d, i) {
d.action(elm, data, index);
d3.select('.d3-context-menu').style('display', 'none');
});
// the openCallback allows an action to fire before the menu is displayed
// an example usage would be closing a tooltip
if (openCallback) openCallback(data, index);
// display context menu
d3.select('.d3-context-menu')
.style('left', (d3.event.pageX - 2) + 'px')
.style('top', (d3.event.pageY - 2) + 'px')
.style('display', 'block');
d3.event.preventDefault();
};
};
This source diff could not be displayed because it is too large. You can view the blob instead.
svg {
margin-left:auto;
margin-right:auto;
display:block;
position: fixed;
border: 0px solid black;
top:5%; left:0%; right:0% bottom=10%
}
.nodeRect {
stroke: black;
border: 3px solid black;
}
.nodeEllipse {
stroke: black;
border: 3px solid black;
}
.nodeText {
color: black;
}
.edge {
stroke-width: 3px;
cursor: pointer;
opacity: 0.4;
}
.edgeLabelRect {
stroke: black;
border: 1px solid black;
fill: skyblue;
opacity: 0.9;
}
.edgeLabelText {
fill: black;
text-anchor: start;
}
.arrowHead {
stroke: green;
stroke-width: 1px;
}
.arrowHead_n {
stroke: green;
}
.arrowHead_r {
stroke-width: 3px;
fill: red;
stroke: red;
}
.arrowHead_b {
stroke: dodgerblue;
}
.edgeTooltip {
position: absolute;
text-align: center;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
.nodeTooltip {
position: absolute;
text-align: left;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
path.hull {
fill: lightsteelblue;
fill-opacity: 0.3;
}
\ No newline at end of file
function flipAxes(nodes) {
var size = [0, 0];
for (var i in nodes) {
var node = nodes[i];
size[0] = Math.max(size[0], node.pos[0] + node.width);
size[1] = Math.max(size[1], node.pos[1] + node.height);
}
for (var i in nodes) {
var node = nodes[i];
node.pos[1] = size[1] - (node.pos[1] + node.height);
}
}
function processDotGraph(dotGraph) {
dotGraph.rnodes = {};
for (var nodeId in dotGraph._nodes) {
var node = dotGraph._nodes[nodeId];
node.id = nodeId;
node.isCluster = nodeId.startsWith('cluster');
if (!node.isCluster) {
dotGraph.rnodes[nodeId] = node;
}
}
var i = 0;
for (var nodeId in dotGraph.rnodes) {
var node = dotGraph._nodes[nodeId];
node.pos = node.pos.split(',').map(function(d) {return parseInt(d);});
var size = textSize(node.label, {'class': 'nodeText'});
node.width = size.width + 2 * pad;
node.height = size.height + 2 * pad;
node.cx = node.width / 2;
node.cy = node.height / 2;
node.hasChilds = exists(node.subg);
node.showChilds = false;
if (exists(node.profile)) {
node.profile = parseProfile(node.profile);
isProfiled = true;
}
if (exists(node.tag)) {
node.tag = parseList(node.tag);
}
if (exists(node.subg_map_inputs)) {
node.subg_map_inputs = eval(node.subg_map_inputs)
}
if (exists(node.subg_map_outputs)) {
node.subg_map_outputs = eval(node.subg_map_outputs)
}
}
flipAxes(dotGraph.rnodes);
// Offset and scale positions
var posMin = [Infinity, Infinity];
for (var i in dotGraph.rnodes) {
var node = dotGraph._nodes[i];
posMin[0] = Math.min(posMin[0], node.pos[0]);
posMin[1] = Math.min(posMin[1], node.pos[1]);
}
for (var i in dotGraph.rnodes) {
var node = dotGraph._nodes[i];
var pos = node.pos;
pos[0] -= posMin[0];
pos[1] -= posMin[1];
pos[0] = 1.2 * pos[0];
pos[1] = 1.2 * pos[1];
}
var edges = dotGraph.edges();
for (var i in edges) {
var edge = dotGraph.edge(edges[i]);
var size = textSize(edge.label, {'class': 'edgeLabelText'});
edge.width = size.width + 2 * pad;
edge.height = size.height + 2 * pad;
if (!exists(edge.color)) {
edge.color = 'black';
}
switch (edge.color) {
case 'dodgerblue':
edge.type = 'b';
break;
case 'red':
edge.type = 'r';
break;
default:
edge.type = 'n';
}
}
}
function traverseChilds(dotGraph, nodes, groups, parent) {
var preId = '';
var ref = undefined;
var group = {'id': groups.length, 'nodes': [], 'parent': parent};
if (exists(parent)) {
ref = parent.value.subg;
group.parent = parent;
group.nodes.push(parent);
parent.group = group;
}
groups.push(group);
var childs = dotGraph.children(ref);
for (var i in childs) {
var child = dotGraph.node(childs[i]);
if (child.isCluster) {
continue;
}
var node = {
'id': child.id,
'value': child,
'index': nodes.length,
'fixed': fixedDefault,
'group': group,
'isParent': child.showChilds,
'parent': parent
};
nodes.push(node);
if (child.showChilds) {
traverseChilds(dotGraph, nodes, groups, node);
} else {
group.nodes.push(node);
}
group.childs = [];
for (var i = group.id + 1; i < groups.length; ++i) {
group.childs.push(groups[i].id);
}
}
}
function groupSize(nodes) {
var minPos = [Infinity, Infinity];
var maxPos = [-Infinity, -Infinity];
for (var i in nodes) {
var node = nodes[i];
if (node.isParent) {
continue;
}
minPos[0] = Math.min(minPos[0], node.value.pos[0]);
minPos[1] = Math.min(minPos[1], node.value.pos[1]);
maxPos[0] = Math.max(maxPos[0], node.value.pos[0] + node.value.width);
maxPos[1] = Math.max(maxPos[1], node.value.pos[1] + node.value.height);
}
return [maxPos[0] - minPos[0], maxPos[1] - minPos[1]];
}
function forceGraph(dotGraph, prevGraph) {
var graph = {'nodes': [], 'groups': []};
traverseChilds(dotGraph, graph.nodes, graph.groups);
graph.nodesd = {};
for (var i in graph.nodes) {
var node = graph.nodes[i];
graph.nodesd[node.id] = node;
}
graph.groupsd = {};
for (var i in graph.groups) {
var group = graph.groups[i];
graph.groupsd[group.id] = group;
}
graph.nodesp = graph.nodes.filter(function(d) {return d.isParent;});
graph.nodesn = graph.nodes.filter(function(d) {return !d.isParent;});
for (i in graph.groups) {
var group = graph.groups[i];
group.size = groupSize(group.nodes);
var parent = group.parent;
if (exists(parent)) {
var prevParent = prevGraph.nodesd[group.parent.id];
if (exists(prevParent)) {
group.pos = [prevParent.x, prevParent.y];
} else {
group.pos = parent.value.pos.slice(0);
}
group.pos[0] += parent.value.cx;
group.pos[1] += parent.value.cy;
} else {
group.pos = [group.size[0] / 2, group.size[1] / 2];
}
var min = [Infinity, Infinity];
for (var j in group.nodes) {
var node = group.nodes[j];
if (!node.isParent) {
min[0] = Math.min(min[0], node.value.pos[0]);
min[1] = Math.min(min[0], node.value.pos[1]);
}
}
for (var j in group.nodes) {
var node = group.nodes[j];
if (!node.isParent) {
node.x = group.pos[0] - group.size[0] / 2 + node.value.pos[0] - min[0];
node.y = group.pos[1] - group.size[1] / 2 + node.value.pos[1] - min[1];
}
}
}
graph.size = graph.groups[0].size;
// Reuse previous positions
if (exists(prevGraph)) {
for (var i in graph.nodes) {
var node = graph.nodes[i];
var prevNode;
prevNode = prevGraph.nodesd[node.id];
if (exists(prevNode)) {
node.x = prevNode.x;
node.y = prevNode.y;
node.fixed = prevNode.fixed;
} else {
for (var j in prevGraph.groups) {
var group = prevGraph.groups[j];
if (exists(group.parent) && group.parent.id == node.id) {
node.x = group.pos[0] + group.size[0] / 2;
node.y = group.pos[1] + group.size[1] / 2;
}
}
}
}
}
// Edges
graph.edges = [];
for (var i in graph.nodesn) {
for (var j in graph.nodesn) {
var source = graph.nodesn[i];
var target = graph.nodesn[j];
var dotEdge = dotGraph.edge(source.value.id, target.value.id);
if (exists(dotEdge)) {
var edge = {};
edge.source = parseInt(source.index);
edge.target = parseInt(target.index);
edge.value = dotEdge;
graph.edges.push(edge);
}
function redirectEdges(map, dotEdge) {
for (var k in map) {
var kmap = map[k];
if (kmap[0] == source.id && kmap[1] == target.id) {
var edge = {};
edge.source = parseInt(source.index);
edge.target = parseInt(target.index);
edge.value = dotEdge;
graph.edges.push(edge);
}
}
}
var map = undefined;
if (exists(target.parent)) {
var parent = target.parent;
var dotEdge = dotGraph.edge(source.id, parent.id);
if (exists(dotEdge)) {
map = parent.value.subg_map_inputs;
redirectEdges(map, dotEdge);
}
}
if (exists(source.parent)) {
var parent = source.parent;
var dotEdge = dotGraph.edge(parent.id, target.id);
if (exists(dotEdge)) {
map = parent.value.subg_map_outputs;
redirectEdges(map, dotEdge);
}
}
}
}
return graph;
}
function convexHulls(graph, offset) {
var hulls = [];
offset = offset || 20;
for (var i in graph.groups) {
var group = graph.groups[i];
if (!exists(group.parent)) {
continue;
}
var points = [];
for (var j in group.nodes) {
var node = group.nodes[j];
if (!node.isParent) {
points.push([node.x - node.value.cx - offset, node.y - node.value.cy - offset]);
points.push([node.x - node.value.cx - offset, node.y + node.value.cy + offset]);
points.push([node.x + node.value.cx + offset, node.y - node.value.cy - offset]);
points.push([node.x + node.value.cx + offset, node.y + node.value.cy + offset]);
}
}
for (var k in group.childs) {
var nodes = graph.groupsd[group.childs[k]].nodes;
for (var j in nodes) {
var node = nodes[j];
if (!node.isParent) {
points.push([node.x - node.value.cx - offset, node.y - node.value.cy - offset]);
points.push([node.x - node.value.cx - offset, node.y + node.value.cy + offset]);
points.push([node.x + node.value.cx + offset, node.y - node.value.cy - offset]);
points.push([node.x + node.value.cx + offset, node.y + node.value.cy + offset]);
}
}
}
hulls.push({group: i, path: d3.geom.hull(points)});
}
return hulls;
}
function drawCluster(d) {
return curve(d.path); // 0.8
}
function setupGraph() {
if (isProfiled) {
d3.select('body').select('#menu').append('input')
.attr('name', 'tColors')
.attr('type', 'button')
.attr('value', 'Toggle profile colors')
.attr('onclick', "toggleColors()");
maxProfilePer = 0;
for (i in graph.nodes) {
var p = graph.nodes[i].value.profile;
if (exists(p)) {
maxProfilePer = Math.max(maxProfilePer, p[0] / p[1]);
}
}
}
var isEdgeOver = false;
var isEdgeLabelOver = false;
var dragHulls = d3.behavior.drag()
.origin(function(d) { return d; })
.on("dragstart", function(d) {
d3.event.sourceEvent.stopPropagation();
d3.event.sourceEvent.preventDefault();
layout.stop();
})
.on("drag", function dragged(d) {
var group = graph.groups[d.group];
for (var i in group.nodes) {
var node = group.nodes[i];
node.x += d3.event.dx;
node.y += d3.event.dy;
node.px += d3.event.dx;
node.py += d3.event.dy;
}
group.pos[0] += d3.event.dx;
group.pos[1] += d3.event.dy;
for (var k in group.childs) {
var cgroup = graph.groupsd[group.childs[k]];
var nodes = cgroup.nodes;
for (var j in nodes) {
var node = nodes[j];
node.x += d3.event.dx;
node.y += d3.event.dy;
node.px += d3.event.dx;
node.py += d3.event.dy;
cgroup.pos[0] += d3.event.dx;
cgroup.pos[1] += d3.event.dy;
}
}
updateGraph();
})
.on('dragend', function(d) {layout.resume();});
graph.hulls = convexHulls(graph);
hulls = pane.selectAll('#hulls').remove();
hulls = pane.append('g').attr('id', 'hulls')
.selectAll('path')
.data(graph.hulls).enter()
.append('path')
.attr('class', 'hull')
.attr('d', drawCluster)
.call(dragHulls);
hulls.on('dblclick', function(d) {
var group = graph.groups[d.group];
group.parent.value.showChilds = !group.parent.value.showChilds;
if (!group.parent.value.showChilds) {
for (i in group.childs) {
var child = graph.groupsd[group.childs[i]];
child.parent.value.showChilds = false;
}
}
graph = forceGraph(dotGraph, graph);
setupGraph();
});
// Add edges
edges = pane.selectAll('#edges').remove();
edges = pane.append('g').attr('id', 'edges')
.selectAll('path').data(graph.edges).enter().append('path')
.attr('class', 'edge')
.attr('stroke', function(d) {return d.value.color;})
.attr('marker-mid', function(d) { return 'url(#edgeArrow_' + d.value.type + ')';});
edges.on('mouseover', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 1.0);
edgeDiv.transition()
.duration(200)
.style('opacity', .9);
edgeDiv
.html(d.value.label)
.style('left', (d3.event.pageX) + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
});
edges.on('mouseout', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 0.4);
edgeDiv.transition()
.duration(200)
.style('opacity', 0);
});
// Add nodes
pane.selectAll('#nodes').remove();
nodes = pane.append('g').attr('id', 'nodes')
.selectAll('g').data(graph.nodesn).enter().append('g');
updateNodes();
updateGraph();
nodes.on('dblclick', function(d) {
if (d.value.hasChilds) {
d.value.showChilds = !d.value.showChilds;
graph = forceGraph(dotGraph, graph);
if (!fixedDefault && d.value.showChilds) {
var n = dotGraph.neighbors(d.id);
for (i in n) {
graph.nodesd[n[i]].fixed = false;
}
}
setupGraph();
}
});
nodes.on('mouseover', function(node) {
// Highlight incoming edges
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source == node || d.target == node) {
edge.transition()
.duration(200)
.style('opacity', 1.0);
}
});
// Show node details if node is not edited as has profiling information
if (!isEditNode) {
nodeDiv.transition()
.duration(200)
.style('opacity', .9);
nodeDiv
.html(nodeDetails(node))
.style('left', (d3.event.pageX) + 30 + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
}
});
nodes.on('mouseout', function(node) {
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source.index == node.index || d.target.index == node.index) {
edge.transition()
.duration(200)
.style('opacity', 0.4);
}
});
hideNodeDiv();
});
nodes.on('contextmenu', d3.contextMenu(menuItems));
// Force layout
layout = d3.layout.force()
.nodes(graph.nodes)
.links(graph.edges)
.size(graph.size)
.linkDistance(function(d) {
return 300;
})
.charge(-600)
.linkStrength(1)
.gravity(0.05)
.friction(0.5)
.on('tick', updateGraph)
.start();
// Drag behavour
var drag = layout.drag()
.on('dragstart', function(d) {
d3.event.sourceEvent.stopPropagation();
d3.event.sourceEvent.preventDefault();
d.fixed = true;
});
nodes.call(drag);
}
function length(x1, y1, x2, y2) {
return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2));
}
function pathPos(x1, y1, x2, y2, c) {
x = (1 - c) * x1 + c * x2;
y = (1 - c) * y1 + c * y2;
p = x + ',' + y;
return p;
}
function collide(node) {
var eps = 10;
var nx1 = node.x - node.value.cx - eps;
var nx2 = node.x + node.value.cx + eps;
var ny1 = node.y - node.value.cy - eps;
var ny2 = node.y + node.value.cy + eps;
return function(quad, x1, y1, x2, y2) {
var point = quad.point;
if (point && (point != node) && !point.fixed && ! node.fixed) {
var px1 = point.x - point.value.cx;
var px2 = point.x + point.value.cx;
var py1 = point.y - point.value.cy;
var py2 = point.y + point.value.cy;
if (!(px1 > nx2 || px2 < nx1 || py1 >= ny2 || py2 <= ny1)) {
var eta = 0.1;
if (px1 < nx1) {
// move quad to left
var d = eta * (px2 - nx1);
point.x -= d;
node.x += d;
} else {
var d = eta * (nx2 - px1);
point.x += d;
node.x -= d;
}
if (py1 < ny1) {
// move quad to top
var d = eta * (py2 - ny1);
point.y -= d;
node.y += d;
} else {
var d = eta * (ny2 - py1);
point.y += d;
node.y -= d;
}
}
}
return x1 > nx2 || x2 < nx1 || y1 >= ny2 || y2 <= ny1;
};
}
function updateGraph() {
var q = d3.geom.quadtree(graph.nodes);
for (var i in graph.nodes) {
q.visit(collide(graph.nodes[i]));
}
graph.hulls = convexHulls(graph);
hulls.data(graph.hulls)
.attr('d', drawCluster);
// Update nodes
nodes.attr('transform', function(d) { return 'translate(' + (d.x - d.value.cx) + ' ' + (d.y - d.value.cy) + ')'; });
// Update edges
edges.attr('d', function(d) {
var dist = 100;
var l = length(d.source.x, d.source.y, d.target.x, d.target.y);
var n = Math.max(2, Math.floor(l / dist));
var marker = [];
for (var i = 1; i < n; ++i) {
marker.push(i / n);
}
var markerPos = marker.map(function(c) {return pathPos(d.source.x, d.source.y, d.target.x, d.target.y, c);});
var markerPos = ' L' + markerPos.join(' L');
return 'M' + d.source.x + ',' + d.source.y + markerPos + ' L' + d.target.x + ',' + d.target.y;
});
}
function toggleColors() {
colorProfile = !colorProfile;
updateNodes();
updateGraph();
}
function textSize(text, attr) {
var t = svg.append('text').text(text);
if (typeof(attr) != 'undefined') {
for (a in attr) {
t.attr(a, attr[a]);
}
}
var bbox = t.node().getBBox();
t.remove();
return bbox;
}
function assert(condition, message) {
if (!condition) {
throw message || "Assertion failed";
}
}
function exists(x) {
return typeof(x) != 'undefined';
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
function parseList(s) {
var h = ['(', ')', '[', ']', '<', '>'];
for (var i = 0; i < h.length; ++i) {
s = s.replace(h[i], '');
}
s = replaceAll(s, "'", "");
s = replaceAll(s, ' ', '');
s = s.split(',');
return s;
}
function parseProfile(s) {
var p = parseList(s);
p = p.map(function(x) { return parseFloat(x); });
return p;
}
function linspace(start, end, len) {
var d = (end - start) / (len - 1);
var rv = [start];
for (i = 1; i < len; ++i) {
rv.push(rv[i - 1] + d);
}
return rv;
}
function profileColor(per) {
var s = d3.scale.linear()
.domain(linspace(0, maxProfilePer, profileColors.length))
.range(profileColors)
.interpolate(d3.interpolateRgb);
return s(per);
}
function fillColor(d) {
if (colorProfile && exists(d.value.profile)) {
if (d.value.shape == 'ellipse') {
return profileColor(d.value.profile[0] / d.value.profile[1]);
} else {
return 'white';
}
} else {
return typeof(d.value.fillcolor) == 'undefined' ? 'white' : d.value.fillcolor;
}
}
function formatTime(sec) {
var s;
if (sec < 0.1) {
s = (sec * 1000).toFixed(1) + 'ms';
} else {
s = sec.toFixed(1) + 's';
}
return s;
}
function nodeDetails(node) {
var v = node.value;
var s = '<b><center>' + v.label + '</center></b>';
if (exists(v.dtype)) {
s += 'Type: ' + v.dtype;
}
if (exists(v.tag)) {
s += '<br>File: ' + v.tag[0];
s += '<br>Line: ' + v.tag[1];
s += '<br>Definition: ' + v.tag[2];
}
var p = v.profile;
if (exists(p) && length(p)) {
s += '<br>Time: ' + formatTime(p[0]);
s += '<br>Time: ' + (p[0] / p[1] * 100).toFixed(1) + '%';
}
return s;
}
function updateNode(d, node) {
var shape;
if (d.value.shape == 'ellipse') {
node.selectAll('ellipse').remove();
shape = node.append('ellipse')
.attr('class', 'nodeEllipse')
.attr('cx', d.value.cx)
.attr('cy', d.value.cy)
.attr('rx', d.value.width * 0.6)
.attr('ry', d.value.height * 0.6);
} else {
node.selectAll('rect').remove();
shape = node.append('rect')
.attr('class', 'nodeRect')
.attr('width', d.value.width)
.attr('height', d.value.height);
}
shape.attr('fill', fillColor(d));
node.selectAll('text').remove();
var text = node.append('text')
.attr('class', 'nodeText')
.attr('x', pad)
.attr('dy', function(d) {return d.value.height - pad - 5;})
.text(function(d) {return d.value.label;});
if (d.value.hasChilds) {
node.style('cursor', 'pointer');
}
}
function updateNodes() {
nodes.each(function(d) {
var node = d3.select(this);
updateNode(d, node);
});
}
function hideNodeDiv() {
nodeDiv.transition()
.duration(200)
.style('opacity', 0);
}
function setNodeSize(node) {
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
}
function editNode(elm, d) {
var node = d3.select(elm);
var pos = elm.getBBox();
if (d3.event.defaultPrevented) return;
isEditNode = true;
hideNodeDiv();
var form = node.append('foreignObject')
.attr('x', pos.x)
.attr('y', pos.y)
.attr('width', d.value.width)
.attr('height', 25);
var input = form.append('xhtml:form').append('input')
.attr('style', 'width: ' + d.value.width + 'px')
.attr('value', function() {
this.focus();
return d.value.label;
})
.on('blur', function() {
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
})
.on('keypress', function() {
if (!d3.event) {
d3.event = window.event;
}
var event = d3.event;
if (event.keyCode == 13) {
if (typeof(event.cancelBubble)) {
event.cancelBubble = true;
}
if (event.stopPropagation) {
event.stopPropagation();
}
event.preventDefault();
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
}
});
}
function releaseNode(d) {
d.fixed = false;
layout.start();
}
function releaseNodes() {
graph['nodes'].forEach (function (d) {
d.fixed = false;
});
layout.start();
}
function resetNodes() {
layout.stop();
var nodes = graph['nodes'];
nodes.forEach(function (node, i){
nodes[i].x = scaleDotX(node.value.pos[0]);
nodes[i].y = scaleDotY(dotGraph.values.height - (node.value.pos[1] + node.value.height));
nodes[i].px = nodes[i].x;
nodes[i].py = nodes[i].y;
nodes[i].fixed = true;
});
updateGraph();
layout.start();
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="d3-context-menu.css"/>
<link rel="stylesheet" href="d3theano.css"/>
<script type="text/javascript" src="d3.v3.min.js"></script>
<script type='text/javascript' src="dagre-d3.js"></script>
<script type='text/javascript' src="graphlib-dot.js"></script>
<script src="d3-context-menu.js"></script>
<script src="d3theano.js"></script>
</head>
<body>
<div id='menu'>
<input name="resetNodes"
type="button"
value="Reset nodes"
onclick="resetNodes()"/>
<input name="releaseNodes"
type="button"
value="Release nodes"
onclick="releaseNodes()"/>
</div>
<script type="text/javascript">
var path = 'graph.dot'; // '%% DOT_FILE %%';
var dotGraph;
var graph = {};
var nodes = [];
var edges = [];
var isProfiled = false;
var colorProfile = false;
var fixedDefault = true;
var maxProfilePer = 0;
var profileColors = ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15"];
var pad = 10;
var isEditNode = false;
var menuItems = [
{
title: 'Edit',
action: function(elm, d, i) {
editNode(elm, d);
}
},
{
title: 'Release',
action: function(elm, d, i) {
releaseNode(d);
}
}
];
var layout;
var scaleDotX;
var scaleDotY;
d3.select('body').select('svg').remove();
var svg = d3.select('body').append('svg')
.attr('width', '100%')
.attr('height', '95%');
var pane = svg.append('g');
var edgeDiv = d3.select('body').append('div')
.attr('class', 'edgeTooltip')
.style('opacity', 0.0);
var nodeDiv = d3.select('body').append('div')
.attr('class', 'nodeTooltip')
.style('opacity', 0.0);
// Definition head of edges
var markerData = [
{'id': 'n', 'color': 'black'},
{'id': 'r', 'color': 'red'},
{'id': 'b', 'color': 'dodgerblue'}];
svg.append("defs").selectAll('marker').data(markerData).enter().append("marker")
.attr("id", function(d) { return 'edgeArrow_' + d.id;})
.attr("markerWidth", 4)
.attr("markerHeight", 4)
.attr("refX", 2)
.attr("refY", 2)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,0 L4,2 L0,4 Z")
.attr('fill', function(d) { return d.color;});
// Zoom behaviour
function zoom(d) {
var trans = d3.event.translate;
trans[0] += 300;
trans[1] += 100;
pane.attr('transform', 'translate(' + trans + ') scale(' + d3.event.scale + ')');
}
var bZoom = d3.behavior.zoom()
.scaleExtent([0.2, 8])
.on('zoom', zoom);
svg.call(bZoom);
bZoom.event(svg);
svg.on("dblclick.zoom", null);
var curve = d3.svg.line()
.interpolate("cardinal-closed")
.tension(.85);
// Read and initialize graph
d3.text(path, function(data) {
dotGraph = graphlibDot.read(data);
processDotGraph(dotGraph);
graph = forceGraph(dotGraph);
setupGraph();
});
</script>
</body>
</html>
digraph G {
graph [bb="0,0,1075,476"];
node [label="\N"];
n1 [height=0.5,
label="InplaceDimShuffle{x}",
pos="915,194",
width=2.5686];
n14 [fillcolor="#FFAABB",
height=0.5,
label="Elemwise{Composite{GT(scalar_sigmoid((-((-i0) - i1))), i2)}}",
pos="616,106",
style=filled,
type=colored,
width=6.6733];
n1 -> n14 [label="1 TensorType(float32, (True,))",
lp="924.5,150",
pos="e,712.86,122.51 882.01,177.08 857.83,165.94 823.97,151.43 793,142 770.58,135.17 746.15,129.35 722.8,124.52"];
n2 [dtype="TensorType(float32, scalar)",
fillcolor=limegreen,
height=0.5,
label=b,
pos="921,282",
shape=ellipse,
style=filled,
tag="('sharedvalue.py', 212, 'utils.add_tag_trace(var)')",
width=0.75];
n2 -> n1 [color=dodgerblue,
label="TensorType(float32, scalar)",
lp="997,238",
pos="e,916.2,212.25 919.81,264.01 918.99,252.19 917.87,236.17 916.92,222.54"];
n4 [fillcolor=cyan,
height=0.5,
label="Shape_i{0}",
pos="122,370",
style=filled,
type=colored,
width=1.4763];
n7 [fillcolor="#FFAA22",
height=0.5,
label="AllocEmpty{dtype='float32'}",
pos="117,282",
style=filled,
type=colored,
width=3.2589];
n4 -> n7 [label="TensorType(int64, scalar)",
lp="193,326",
pos="e,117.99,300.08 120.99,351.6 120.3,339.75 119.37,323.82 118.59,310.29"];
n5 [dtype="TensorType(float32, matrix)",
fillcolor=limegreen,
height=0.5,
label=x,
pos="212,458",
shape=ellipse,
style=filled,
tag="('<ipython-input-199-20e727d2876b>', 8, 'x = T.matrix(x)')",
width=0.75];
n5 -> n4 [label="TensorType(float32, matrix)",
lp="206,414",
pos="e,119.07,388.16 185.7,453.69 165.91,449.71 139.89,441 126,422 121.06,415.24 119.22,406.55 118.86,398.27"];
n9 [height=0.5,
label="CGemv{inplace}",
pos="355,194",
width=2.0569];
n5 -> n9 [label="2 TensorType(float32, matrix)",
lp="395,326",
pos="e,344.45,211.98 237.29,451.26 253.6,446.24 273.95,437.29 286,422 330.4,365.66 294.85,331.55 319,264 324.29,249.2 332.21,233.6 339.27,\
220.98"];
n7 -> n9 [color=red,
label="0 TensorType(float32, vector)",
lp="201.5,238",
pos="e,281.17,195.67 111.81,263.89 109.62,252.94 109.13,239.11 117,230 136.81,207.07 210.62,198.89 270.86,196.1"];
n9 -> n14 [label="0 TensorType(float32, vector)",
lp="527.5,150",
pos="e,511.99,122.33 378.23,176.72 395.39,165.4 419.72,150.83 443,142 461.71,134.9 482.14,129.15 502.18,124.52"];
n10 [dtype="TensorType(float32, scalar)",
fillcolor=limegreen,
height=0.5,
label="val=1.0",
pos="366,282",
shape=ellipse,
style=filled,
width=1.0604];
n10 -> n9 [label="1 TensorType(float32, scalar)",
lp="433.5,238",
pos="e,350.68,212.15 356.66,264.42 353.96,258.76 351.36,252.27 350,246 348.33,238.35 348.4,229.93 349.21,222.18"];
n11 [dtype="TensorType(float32, vector)",
fillcolor=limegreen,
height=0.5,
label=w,
pos="539,282",
shape=ellipse,
style=filled,
tag="('sharedvalue.py', 212, 'utils.add_tag_trace(var)')",
width=0.75];
n11 -> n9 [label="3 TensorType(float32, vector)",
lp="613.5,238",
pos="e,419.74,202.86 535.84,263.87 532.87,252.61 527.28,238.45 517,230 503.34,218.77 465.44,210.25 429.73,204.43"];
n12 [dtype="TensorType(float32, scalar)",
fillcolor=limegreen,
height=0.5,
label="val=0.0",
pos="731,282",
shape=ellipse,
style=filled,
width=1.0604];
n12 -> n9 [label="4 TensorType(float32, scalar)",
lp="801.5,238",
pos="e,423.36,201.1 725.89,263.87 721.5,252.3 713.95,237.78 702,230 696.41,226.36 534.13,211.15 433.51,202.02"];
n16 [dtype="TensorType(int8, vector)",
fillcolor=dodgerblue,
height=0.5,
label="TensorType(int8, vector)",
pos="616,18",
shape=box,
style=filled,
width=2.1736];
n14 -> n16 [label="TensorType(int8, vector)",
lp="686.5,62",
pos="e,616,36.084 616,87.597 616,75.746 616,59.817 616,46.292"];
n15 [dtype="TensorType(float32, (True,))",
fillcolor=limegreen,
height=0.5,
label="val=[ 0.5]",
pos="616,194",
shape=ellipse,
style=filled,
width=1.2888];
n15 -> n14 [label="2 TensorType(float32, (True,))",
lp="702.5,150",
pos="e,616,124.08 616,175.6 616,163.75 616,147.82 616,134.29"];
}
This source diff could not be displayed because it is too large. You can view the blob instead.
digraph G {
graph [bb="0,0,1998,340"];
node [label="\N"];
subgraph cluster_n1 {
graph [bb="773,8,1990,332"];
subgraph cluster_n11 {
graph [bb="1505,96,1982,324"];
n111 [fillcolor="#FFAABB",
height=0.5,
label="Elemwise{mul,no_inplace}",
pos="1717,210",
shape=ellipse,
style=filled,
type=colored,
width=3.0943];
n114 [fillcolor=dodgerblue,
height=0.5,
label="TensorType(float32, scalar)",
pos="1717,122",
shape=box,
style=filled,
width=2.3889];
n111 -> n114 [label="TensorType(float32, scalar)",
lp="1795,166",
pos="e,1717,140.08 1717,191.6 1717,179.75 1717,163.82 1717,150.29"];
n112 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="1863,298",
shape=box,
style=filled,
width=3.0625];
n112 -> n111 [label="0 TensorType(float32, scalar)",
lp="1892.5,254",
pos="e,1750.2,227.23 1838.1,279.79 1823,269.57 1803.2,256.58 1785,246 1776.8,241.24 1767.9,236.42 1759.4,231.94"];
n113 [fillcolor=limegreen,
height=0.5,
label="name=y TensorType(float32, scalar)",
pos="1624,298",
shape=box,
style=filled,
width=3.0625];
n113 -> n111 [label="1 TensorType(float32, scalar)",
lp="1701.5,254",
pos="e,1645.8,223.99 1616.5,279.94 1613.1,269.27 1611.1,255.75 1618,246 1623,238.94 1629.5,233.29 1636.9,228.78"];
}
n11 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x1105b0c50",
pos="1258,210",
shape=ellipse,
subg=cluster_n11,
subg_map_inputs="[['n12', 'n112'], ['n13', 'n113']]",
subg_map_outputs="[['n114', 'n15']]",
width=6.6414];
n15 [fillcolor="#FFAABB",
height=0.5,
label="Elemwise{Add}[(0, 0)]",
pos="1030,122",
shape=ellipse,
style=filled,
type=colored,
width=2.6784];
n11 -> n15 [color=red,
label="0 TensorType(float32, scalar)",
lp="1266.5,166",
pos="e,1081.2,137.27 1223.3,192.13 1200.9,181.61 1171.1,168.18 1144,158 1127.1,151.64 1108.4,145.55 1091.2,140.28"];
n12 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="1307,298",
shape=box,
style=filled,
width=3.0625];
n12 -> n11 [label="0 TensorType(float32, scalar)",
lp="1370.5,254",
pos="e,1267.7,228.08 1297.1,279.6 1290.1,267.39 1280.7,250.87 1272.9,237.09"];
n13 [fillcolor=limegreen,
height=0.5,
label="name=y TensorType(float32, scalar)",
pos="1068,298",
shape=box,
style=filled,
width=3.0625];
n13 -> n11 [label="1 TensorType(float32, scalar)",
lp="1191.5,254",
pos="e,1151.9,226.21 1077.3,279.8 1084.3,268.51 1094.9,254.35 1108,246 1118.5,239.31 1130.1,233.89 1142.2,229.51"];
n17 [fillcolor=dodgerblue,
height=0.5,
label="TensorType(float32, scalar) id=4",
pos="1030,34",
shape=box,
style=filled,
width=2.7847];
n15 -> n17 [label="TensorType(float32, scalar)",
lp="1108,78",
pos="e,1030,52.084 1030,103.6 1030,91.746 1030,75.817 1030,62.292"];
n16 [fillcolor=limegreen,
height=0.5,
label="name=z TensorType(float32, scalar)",
pos="891,210",
shape=box,
style=filled,
width=3.0556];
n16 -> n15 [label="1 TensorType(float32, scalar)",
lp="1056.5,166",
pos="e,1003.2,139.58 918.79,191.8 940.57,178.33 971.02,159.49 994.55,144.93"];
}
n1 [height=0.5,
label="theano.compile.builders.OpFromGraph object at 0x1105a91d0",
pos="524,210",
shape=ellipse,
subg=cluster_n1,
subg_map_inputs="[['n2', 'n12'], ['n3', 'n13'], ['n4', 'n16']]",
subg_map_outputs="[['n17', 'n6']]",
width=6.6414];
n6 [fillcolor="#FFAABB",
height=0.5,
label="Elemwise{Add}[(0, 0)]",
pos="214,122",
shape=ellipse,
style=filled,
type=colored,
width=2.6784];
n1 -> n6 [color=red,
label="0 TensorType(float32, scalar)",
lp="480.5,166",
pos="e,265.49,137.28 464.6,192.52 410.31,177.46 330.36,155.28 275.44,140.04"];
n2 [fillcolor=limegreen,
height=0.5,
label="name=x TensorType(float32, scalar)",
pos="354,298",
shape=box,
style=filled,
width=3.0625];
n2 -> n1 [label="0 TensorType(float32, scalar)",
lp="465.5,254",
pos="e,418.96,226.25 359.32,279.9 363.67,268.65 370.95,254.49 382,246 390.32,239.61 399.64,234.37 409.44,230.08"];
n3 [fillcolor=limegreen,
height=0.5,
label="name=y TensorType(float32, scalar)",
pos="593,298",
shape=box,
style=filled,
width=3.0625];
n3 -> n1 [label="1 TensorType(float32, scalar)",
lp="648.5,254",
pos="e,537.71,228.08 579.04,279.6 568.96,267.04 555.22,249.91 543.98,235.91"];
n4 [fillcolor=limegreen,
height=0.5,
label="name=z TensorType(float32, scalar)",
pos="110,298",
shape=box,
style=filled,
width=3.0556];
n4 -> n1 [label="2 TensorType(float32, scalar)",
lp="281.5,254",
pos="e,355.01,222.75 133.36,279.81 150.39,268.22 174.5,253.68 198,246 226.06,236.82 284.9,229.34 344.97,223.68"];
n4 -> n6 [label="1 TensorType(float32, scalar)",
lp="192.5,210",
pos="e,173.05,138.3 105.03,279.8 99.747,257.95 94.027,219.76 109,192 120.82,170.09 142.96,154.01 163.88,142.9"];
n7 [fillcolor=dodgerblue,
height=0.5,
label="TensorType(float32, scalar) id=4",
pos="214,34",
shape=box,
style=filled,
width=2.7847];
n6 -> n7 [label="TensorType(float32, scalar)",
lp="292,78",
pos="e,214,52.084 214,103.6 214,91.746 214,75.817 214,62.292"];
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Couldn't import dot_parser, loading of dot files will not be possible.\n"
]
}
],
"source": [
"import pydot as pd\n",
"from IPython.display import SVG"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"g = pd.Dot(graph_type='digraph')\n",
"g.add_node(pd.Node('A', fillcolor='blue', style='filled', shape='box', label='A Label', time=''))\n",
"g.add_node(pd.Node('B', fillcolor='green', shape='ellipse'))\n",
"g.add_edge(pd.Edge('A', 'B', labels='A -> B'))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"116pt\" viewBox=\"0.00 0.00 70.00 116.00\" width=\"70pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 112)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-112 66,-112 66,4 -4,4\" stroke=\"none\"/>\n",
"<!-- A -->\n",
"<g class=\"node\" id=\"node1\"><title>A</title>\n",
"<polygon fill=\"blue\" points=\"62,-108 0,-108 0,-72 62,-72 62,-108\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"31\" y=\"-86.3\">A Label</text>\n",
"</g>\n",
"<!-- B -->\n",
"<g class=\"node\" id=\"node2\"><title>B</title>\n",
"<ellipse cx=\"31\" cy=\"-18\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"31\" y=\"-14.3\">B</text>\n",
"</g>\n",
"<!-- A&#45;&gt;B -->\n",
"<g class=\"edge\" id=\"edge1\"><title>A-&gt;B</title>\n",
"<path d=\"M31,-71.6966C31,-63.9827 31,-54.7125 31,-46.1124\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"34.5001,-46.1043 31,-36.1043 27.5001,-46.1044 34.5001,-46.1043\" stroke=\"black\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"g = pd.Dot(graph_type='digraph')\n",
"\n",
"c1 = pd.Cluster('c1')\n",
"c1.add_node(pd.Node('A'))\n",
"c1.add_node(pd.Node('B'))\n",
"c1.add_edge(pd.Edge('A', 'B'))\n",
"g.add_subgraph(c1)\n",
"\n",
"c2 = pd.Cluster('c2')\n",
"c2.add_node(pd.Node('C'))\n",
"c2.add_node(pd.Node('D'))\n",
"c2.add_edge(pd.Edge('C', 'D'))\n",
"g.add_subgraph(c2)\n",
"\n",
"g.add_edge(pd.Edge('A', 'C'))"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"220pt\" viewBox=\"0.00 0.00 172.00 220.00\" width=\"172pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 216)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-216 168,-216 168,4 -4,4\" stroke=\"none\"/>\n",
"<g class=\"cluster\" id=\"clust1\"><title>cluster_c1</title>\n",
"<polygon fill=\"none\" points=\"8,-80 8,-204 78,-204 78,-80 8,-80\" stroke=\"black\"/>\n",
"</g>\n",
"<g class=\"cluster\" id=\"clust2\"><title>cluster_c2</title>\n",
"<polygon fill=\"none\" points=\"86,-8 86,-132 156,-132 156,-8 86,-8\" stroke=\"black\"/>\n",
"</g>\n",
"<!-- A -->\n",
"<g class=\"node\" id=\"node1\"><title>A</title>\n",
"<ellipse cx=\"43\" cy=\"-178\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"43\" y=\"-174.3\">A</text>\n",
"</g>\n",
"<!-- B -->\n",
"<g class=\"node\" id=\"node2\"><title>B</title>\n",
"<ellipse cx=\"43\" cy=\"-106\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"43\" y=\"-102.3\">B</text>\n",
"</g>\n",
"<!-- A&#45;&gt;B -->\n",
"<g class=\"edge\" id=\"edge1\"><title>A-&gt;B</title>\n",
"<path d=\"M43,-159.697C43,-151.983 43,-142.712 43,-134.112\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"46.5001,-134.104 43,-124.104 39.5001,-134.104 46.5001,-134.104\" stroke=\"black\"/>\n",
"</g>\n",
"<!-- C -->\n",
"<g class=\"node\" id=\"node3\"><title>C</title>\n",
"<ellipse cx=\"121\" cy=\"-106\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"121\" y=\"-102.3\">C</text>\n",
"</g>\n",
"<!-- A&#45;&gt;C -->\n",
"<g class=\"edge\" id=\"edge3\"><title>A-&gt;C</title>\n",
"<path d=\"M58.4103,-163.17C69.7345,-153.008 85.309,-139.03 98.0887,-127.561\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"100.517,-130.085 105.622,-120.801 95.8416,-124.875 100.517,-130.085\" stroke=\"black\"/>\n",
"</g>\n",
"<!-- D -->\n",
"<g class=\"node\" id=\"node4\"><title>D</title>\n",
"<ellipse cx=\"121\" cy=\"-34\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"121\" y=\"-30.3\">D</text>\n",
"</g>\n",
"<!-- C&#45;&gt;D -->\n",
"<g class=\"edge\" id=\"edge2\"><title>C-&gt;D</title>\n",
"<path d=\"M121,-87.6966C121,-79.9827 121,-70.7125 121,-62.1124\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"124.5,-62.1043 121,-52.1043 117.5,-62.1044 124.5,-62.1043\" stroke=\"black\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"g = pd.Dot(graph_type='digraph')\n",
"\n",
"c1 = pd.Cluster('c1')\n",
"c1.add_node(pd.Node('A'))\n",
"c1.add_node(pd.Node('B'))\n",
"c1.add_edge(pd.Edge('A', 'B'))\n",
"g.add_subgraph(c1)\n",
"\n",
"c2 = pd.Cluster('c2')\n",
"c2.add_node(pd.Node('AA'))\n",
"c2.add_node(pd.Node('BB'))\n",
"c2.add_edge(pd.Edge('AA', 'BB'))\n",
"g.add_subgraph(c2)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"digraph G {\n",
"\tgraph [bb=\"0,0,164,140\"];\n",
"\tnode [label=\"\\N\"];\n",
"\tsubgraph cluster_c1 {\n",
"\t\tgraph [bb=\"8,8,78,132\"];\n",
"\t\tA\t\t [height=0.5,\n",
"\t\t\tpos=\"43,106\",\n",
"\t\t\twidth=0.75];\n",
"\t\tB\t\t [height=0.5,\n",
"\t\t\tpos=\"43,34\",\n",
"\t\t\twidth=0.75];\n",
"\t\tA -> B\t\t [pos=\"e,43,52.104 43,87.697 43,79.983 43,70.712 43,62.112\"];\n",
"\t}\n",
"\tsubgraph cluster_c2 {\n",
"\t\tgraph [bb=\"86,8,156,132\"];\n",
"\t\tAA\t\t [height=0.5,\n",
"\t\t\tpos=\"121,106\",\n",
"\t\t\twidth=0.75];\n",
"\t\tBB\t\t [height=0.5,\n",
"\t\t\tpos=\"121,34\",\n",
"\t\t\twidth=0.75];\n",
"\t\tAA -> BB\t\t [pos=\"e,121,52.104 121,87.697 121,79.983 121,70.712 121,62.112\"];\n",
"\t}\n",
"}\n",
"\n"
]
}
],
"source": [
"print(g.create_dot())"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'cluster_c1'"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c1.get_name()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "NameError",
"evalue": "global name 'sgraph' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-9-04d3aa97a139>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_subgraph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'c1'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/Users/angermue/python/venv/theano/lib/python2.7/site-packages/pydot.pyc\u001b[0m in \u001b[0;36mget_subgraph\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 1328\u001b[0m \u001b[0mmatch\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1329\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1330\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mobj_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'subgraphs'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhas_key\u001b[0m\u001b[0;34m(\u001b[0m \u001b[0msgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1331\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1332\u001b[0m \u001b[0msgraphs_obj_dict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mobj_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'subgraphs'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m \u001b[0msgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: global name 'sgraph' is not defined"
]
}
],
"source": [
"g.get_subgraph('c1')"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n = pd.Node('a', param1='p1')"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"n.get_attributes()['p2'] = 10"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g.write_dot('nested.dot')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"220pt\" viewBox=\"0.00 0.00 172.00 220.00\" width=\"172pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 216)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-216 168,-216 168,4 -4,4\" stroke=\"none\"/>\n",
"<g class=\"cluster\" id=\"clust1\"><title>cluster_c1</title>\n",
"<polygon fill=\"none\" points=\"8,-80 8,-204 78,-204 78,-80 8,-80\" stroke=\"black\"/>\n",
"</g>\n",
"<g class=\"cluster\" id=\"clust2\"><title>cluster_c2</title>\n",
"<polygon fill=\"none\" points=\"86,-8 86,-132 156,-132 156,-8 86,-8\" stroke=\"black\"/>\n",
"</g>\n",
"<!-- A -->\n",
"<g class=\"node\" id=\"node1\"><title>A</title>\n",
"<ellipse cx=\"43\" cy=\"-178\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"43\" y=\"-174.3\">A</text>\n",
"</g>\n",
"<!-- B -->\n",
"<g class=\"node\" id=\"node2\"><title>B</title>\n",
"<ellipse cx=\"43\" cy=\"-106\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"43\" y=\"-102.3\">B</text>\n",
"</g>\n",
"<!-- A&#45;&gt;B -->\n",
"<g class=\"edge\" id=\"edge1\"><title>A-&gt;B</title>\n",
"<path d=\"M43,-159.697C43,-151.983 43,-142.712 43,-134.112\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"46.5001,-134.104 43,-124.104 39.5001,-134.104 46.5001,-134.104\" stroke=\"black\"/>\n",
"</g>\n",
"<!-- C -->\n",
"<g class=\"node\" id=\"node3\"><title>C</title>\n",
"<ellipse cx=\"121\" cy=\"-106\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"121\" y=\"-102.3\">C</text>\n",
"</g>\n",
"<!-- A&#45;&gt;C -->\n",
"<g class=\"edge\" id=\"edge3\"><title>A-&gt;C</title>\n",
"<path d=\"M58.4103,-163.17C69.7345,-153.008 85.309,-139.03 98.0887,-127.561\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"100.517,-130.085 105.622,-120.801 95.8416,-124.875 100.517,-130.085\" stroke=\"black\"/>\n",
"</g>\n",
"<!-- D -->\n",
"<g class=\"node\" id=\"node4\"><title>D</title>\n",
"<ellipse cx=\"121\" cy=\"-34\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"121\" y=\"-30.3\">D</text>\n",
"</g>\n",
"<!-- C&#45;&gt;D -->\n",
"<g class=\"edge\" id=\"edge2\"><title>C-&gt;D</title>\n",
"<path d=\"M121,-87.6966C121,-79.9827 121,-70.7125 121,-62.1124\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"124.5,-62.1043 121,-52.1043 117.5,-62.1044 124.5,-62.1043\" stroke=\"black\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"g = pd.Dot(graph_type='digraph')\n",
"g.add_node(pd.Node('A', fillcolor='lightblue', style='filled', shape='box', label='A Label', foo='1'))\n",
"g.add_node(pd.Node('B', fillcolor='green', shape='ellipse'))\n",
"g.add_edge(pd.Edge('A', 'B', labels='A -> B'))"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"116pt\" viewBox=\"0.00 0.00 70.00 116.00\" width=\"70pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 112)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-112 66,-112 66,4 -4,4\" stroke=\"none\"/>\n",
"<!-- A -->\n",
"<g class=\"node\" id=\"node1\"><title>A</title>\n",
"<polygon fill=\"lightblue\" points=\"62,-108 0,-108 0,-72 62,-72 62,-108\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"31\" y=\"-86.3\">A Label</text>\n",
"</g>\n",
"<!-- B -->\n",
"<g class=\"node\" id=\"node2\"><title>B</title>\n",
"<ellipse cx=\"31\" cy=\"-18\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"31\" y=\"-14.3\">B</text>\n",
"</g>\n",
"<!-- A&#45;&gt;B -->\n",
"<g class=\"edge\" id=\"edge1\"><title>A-&gt;B</title>\n",
"<path d=\"M31,-71.6966C31,-63.9827 31,-54.7125 31,-46.1124\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"34.5001,-46.1043 31,-36.1043 27.5001,-46.1044 34.5001,-46.1043\" stroke=\"black\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"digraph G {\n",
"\tgraph [bb=\"0,0,62,108\"];\n",
"\tnode [label=\"\\N\"];\n",
"\tA\t [fillcolor=lightblue,\n",
"\t\tfoo=1,\n",
"\t\theight=0.5,\n",
"\t\tlabel=\"A Label\",\n",
"\t\tpos=\"31,90\",\n",
"\t\tshape=box,\n",
"\t\tstyle=filled,\n",
"\t\twidth=0.86111];\n",
"\tB\t [fillcolor=green,\n",
"\t\theight=0.5,\n",
"\t\tpos=\"31,18\",\n",
"\t\tshape=ellipse,\n",
"\t\twidth=0.75];\n",
"\tA -> B\t [labels=\"A -> B\",\n",
"\t\tpos=\"e,31,36.104 31,71.697 31,63.983 31,54.712 31,46.112\"];\n",
"}\n",
"\n"
]
}
],
"source": [
"print(g.create_dot())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 196,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy\n",
"import numpy.random as rng\n",
"from IPython.display import SVG\n",
"import pydot as pd"
]
},
{
"cell_type": "code",
"execution_count": 197,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 198,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import theano\n",
"import theano.tensor as T\n",
"import theano.d3printing as d3p"
]
},
{
"cell_type": "code",
"execution_count": 199,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Training data\n",
"N = 400\n",
"feats = 784\n",
"D = (rng.randn(N, feats).astype(theano.config.floatX), rng.randint(size=N,low=0, high=2).astype(theano.config.floatX))\n",
"training_steps = 10000\n",
"\n",
"# Declare Theano symbolic variables\n",
"x = T.matrix(\"x\")\n",
"y = T.vector(\"y\")\n",
"w = theano.shared(rng.randn(feats).astype(theano.config.floatX), name=\"w\")\n",
"b = theano.shared(numpy.asarray(0., dtype=theano.config.floatX), name=\"b\")\n",
"x.tag.test_value = D[0]\n",
"y.tag.test_value = D[1]\n",
"\n",
"# Construct Theano expression graph\n",
"p_1 = 1 / (1 + T.exp(-T.dot(x, w)-b)) # Probability of having a one\n",
"prediction = p_1 > 0.5 # The prediction that is done: 0 or 1\n",
"\n",
"# Compute gradients\n",
"xent = -y*T.log(p_1) - (1-y)*T.log(1-p_1) # Cross-entropy\n",
"cost = xent.mean() + 0.01*(w**2).sum() # The cost to optimize\n",
"gw,gb = T.grad(cost, [w,b])\n",
"\n",
"# Training and prediction function\n",
"train = theano.function(inputs=[x,y], outputs=[prediction, xent],\n",
" updates=[[w, w-0.01*gw], [b, b-0.01*gb]],\n",
" name = \"train\", profile=False)\n",
"predict = theano.function(inputs=[x], outputs=prediction,\n",
" name = \"predict\", profile=False)"
]
},
{
"cell_type": "code",
"execution_count": 200,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"gf = d3p.GraphFormatter()\n",
"g = gf.to_pydot(predict)"
]
},
{
"cell_type": "code",
"execution_count": 201,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"484pt\" viewBox=\"0.00 0.00 1083.00 484.00\" width=\"1083pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 480)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-480 1079,-480 1079,4 -4,4\" stroke=\"none\"/>\n",
"<!-- n1 -->\n",
"<g class=\"node\" id=\"node1\"><title>n1</title>\n",
"<ellipse cx=\"915\" cy=\"-194\" fill=\"none\" rx=\"92.413\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"915\" y=\"-190.3\">InplaceDimShuffle{x}</text>\n",
"</g>\n",
"<!-- n14 -->\n",
"<g class=\"node\" id=\"node10\"><title>n14</title>\n",
"<ellipse cx=\"616\" cy=\"-106\" fill=\"#ffaabb\" rx=\"240.218\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"616\" y=\"-102.3\">Elemwise{Composite{GT(scalar_sigmoid((-((-i0) - i1))), i2)}}</text>\n",
"</g>\n",
"<!-- n1&#45;&gt;n14 -->\n",
"<g class=\"edge\" id=\"edge10\"><title>n1-&gt;n14</title>\n",
"<path d=\"M882.007,-177.08C857.83,-165.943 823.965,-151.429 793,-142 770.582,-135.174 746.15,-129.348 722.797,-124.521\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"723.358,-121.064 712.863,-122.514 721.972,-127.925 723.358,-121.064\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"924.5\" y=\"-146.3\">1 TensorType(float32, (True,))</text>\n",
"</g>\n",
"<!-- n2 -->\n",
"<g class=\"node\" id=\"node2\"><title>n2</title>\n",
"<ellipse cx=\"921\" cy=\"-282\" fill=\"limegreen\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"921\" y=\"-278.3\">b</text>\n",
"</g>\n",
"<!-- n2&#45;&gt;n1 -->\n",
"<g class=\"edge\" id=\"edge1\"><title>n2-&gt;n1</title>\n",
"<path d=\"M919.815,-264.009C918.99,-252.19 917.872,-236.171 916.922,-222.542\" fill=\"none\" stroke=\"dodgerblue\"/>\n",
"<polygon fill=\"dodgerblue\" points=\"920.391,-221.982 916.203,-212.25 913.408,-222.469 920.391,-221.982\" stroke=\"dodgerblue\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"997\" y=\"-234.3\">TensorType(float32, scalar)</text>\n",
"</g>\n",
"<!-- n4 -->\n",
"<g class=\"node\" id=\"node3\"><title>n4</title>\n",
"<ellipse cx=\"122\" cy=\"-370\" fill=\"cyan\" rx=\"52.9443\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"122\" y=\"-366.3\">Shape_i{0}</text>\n",
"</g>\n",
"<!-- n7 -->\n",
"<g class=\"node\" id=\"node5\"><title>n7</title>\n",
"<ellipse cx=\"117\" cy=\"-282\" fill=\"#ffaa22\" rx=\"117.459\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"117\" y=\"-278.3\">AllocEmpty{dtype='float32'}</text>\n",
"</g>\n",
"<!-- n4&#45;&gt;n7 -->\n",
"<g class=\"edge\" id=\"edge3\"><title>n4-&gt;n7</title>\n",
"<path d=\"M120.988,-351.597C120.299,-339.746 119.373,-323.817 118.587,-310.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"122.068,-309.864 117.993,-300.084 115.08,-310.27 122.068,-309.864\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"193\" y=\"-322.3\">TensorType(int64, scalar)</text>\n",
"</g>\n",
"<!-- n5 -->\n",
"<g class=\"node\" id=\"node4\"><title>n5</title>\n",
"<ellipse cx=\"212\" cy=\"-458\" fill=\"limegreen\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"212\" y=\"-454.3\">x</text>\n",
"</g>\n",
"<!-- n5&#45;&gt;n4 -->\n",
"<g class=\"edge\" id=\"edge2\"><title>n5-&gt;n4</title>\n",
"<path d=\"M185.704,-453.69C165.909,-449.711 139.89,-440.999 126,-422 121.061,-415.245 119.216,-406.554 118.856,-398.267\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"122.358,-398.236 119.074,-388.163 115.359,-398.085 122.358,-398.236\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"206\" y=\"-410.3\">TensorType(float32, matrix)</text>\n",
"</g>\n",
"<!-- n9 -->\n",
"<g class=\"node\" id=\"node6\"><title>n9</title>\n",
"<ellipse cx=\"355\" cy=\"-194\" fill=\"none\" rx=\"74.1402\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355\" y=\"-190.3\">CGemv{inplace}</text>\n",
"</g>\n",
"<!-- n5&#45;&gt;n9 -->\n",
"<g class=\"edge\" id=\"edge6\"><title>n5-&gt;n9</title>\n",
"<path d=\"M237.292,-451.255C253.603,-446.24 273.948,-437.292 286,-422 330.405,-365.657 294.847,-331.549 319,-264 324.293,-249.198 332.21,-233.599 339.273,-220.984\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"342.499,-222.395 344.451,-211.982 336.431,-218.906 342.499,-222.395\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"395\" y=\"-322.3\">2 TensorType(float32, matrix)</text>\n",
"</g>\n",
"<!-- n7&#45;&gt;n9 -->\n",
"<g class=\"edge\" id=\"edge4\"><title>n7-&gt;n9</title>\n",
"<path d=\"M111.812,-263.895C109.621,-252.937 109.129,-239.113 117,-230 136.806,-207.068 210.625,-198.888 270.862,-196.104\" fill=\"none\" stroke=\"red\"/>\n",
"<polygon fill=\"red\" points=\"271.322,-199.588 281.167,-195.673 271.029,-192.594 271.322,-199.588\" stroke=\"red\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"201.5\" y=\"-234.3\">0 TensorType(float32, vector)</text>\n",
"</g>\n",
"<!-- n9&#45;&gt;n14 -->\n",
"<g class=\"edge\" id=\"edge9\"><title>n9-&gt;n14</title>\n",
"<path d=\"M378.226,-176.716C395.388,-165.402 419.72,-150.827 443,-142 461.714,-134.904 482.139,-129.151 502.185,-124.517\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"502.988,-127.924 511.986,-122.331 501.464,-121.092 502.988,-127.924\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"527.5\" y=\"-146.3\">0 TensorType(float32, vector)</text>\n",
"</g>\n",
"<!-- n10 -->\n",
"<g class=\"node\" id=\"node7\"><title>n10</title>\n",
"<ellipse cx=\"366\" cy=\"-282\" fill=\"limegreen\" rx=\"38.0212\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"366\" y=\"-278.3\">val=1.0</text>\n",
"</g>\n",
"<!-- n10&#45;&gt;n9 -->\n",
"<g class=\"edge\" id=\"edge5\"><title>n10-&gt;n9</title>\n",
"<path d=\"M356.662,-264.419C353.956,-258.756 351.365,-252.267 350,-246 348.334,-238.35 348.405,-229.933 349.214,-222.181\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"352.696,-222.557 350.683,-212.155 345.77,-221.542 352.696,-222.557\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"433.5\" y=\"-234.3\">1 TensorType(float32, scalar)</text>\n",
"</g>\n",
"<!-- n11 -->\n",
"<g class=\"node\" id=\"node8\"><title>n11</title>\n",
"<ellipse cx=\"539\" cy=\"-282\" fill=\"limegreen\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"539\" y=\"-278.3\">w</text>\n",
"</g>\n",
"<!-- n11&#45;&gt;n9 -->\n",
"<g class=\"edge\" id=\"edge7\"><title>n11-&gt;n9</title>\n",
"<path d=\"M535.838,-263.869C532.869,-252.611 527.279,-238.452 517,-230 503.338,-218.766 465.436,-210.25 429.727,-204.433\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"430.157,-200.957 419.735,-202.863 429.071,-207.873 430.157,-200.957\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"613.5\" y=\"-234.3\">3 TensorType(float32, vector)</text>\n",
"</g>\n",
"<!-- n12 -->\n",
"<g class=\"node\" id=\"node9\"><title>n12</title>\n",
"<ellipse cx=\"731\" cy=\"-282\" fill=\"limegreen\" rx=\"38.0212\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"731\" y=\"-278.3\">val=0.0</text>\n",
"</g>\n",
"<!-- n12&#45;&gt;n9 -->\n",
"<g class=\"edge\" id=\"edge8\"><title>n12-&gt;n9</title>\n",
"<path d=\"M725.894,-263.868C721.503,-252.304 713.95,-237.781 702,-230 696.412,-226.362 534.134,-211.151 433.505,-202.022\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"433.639,-198.52 423.364,-201.104 433.008,-205.491 433.639,-198.52\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"801.5\" y=\"-234.3\">4 TensorType(float32, scalar)</text>\n",
"</g>\n",
"<!-- n16 -->\n",
"<g class=\"node\" id=\"node12\"><title>n16</title>\n",
"<polygon fill=\"dodgerblue\" points=\"694.25,-36 537.75,-36 537.75,-0 694.25,-0 694.25,-36\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"616\" y=\"-14.3\">TensorType(int8, vector)</text>\n",
"</g>\n",
"<!-- n14&#45;&gt;n16 -->\n",
"<g class=\"edge\" id=\"edge12\"><title>n14-&gt;n16</title>\n",
"<path d=\"M616,-87.5966C616,-75.7459 616,-59.8169 616,-46.2917\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"619.5,-46.084 616,-36.084 612.5,-46.084 619.5,-46.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"686.5\" y=\"-58.3\">TensorType(int8, vector)</text>\n",
"</g>\n",
"<!-- n15 -->\n",
"<g class=\"node\" id=\"node11\"><title>n15</title>\n",
"<ellipse cx=\"616\" cy=\"-194\" fill=\"limegreen\" rx=\"46.1964\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"616\" y=\"-190.3\">val=[ 0.5]</text>\n",
"</g>\n",
"<!-- n15&#45;&gt;n14 -->\n",
"<g class=\"edge\" id=\"edge11\"><title>n15-&gt;n14</title>\n",
"<path d=\"M616,-175.597C616,-163.746 616,-147.817 616,-134.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"619.5,-134.084 616,-124.084 612.5,-134.084 619.5,-134.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"702.5\" y=\"-146.3\">2 TensorType(float32, (True,))</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 201,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
},
{
"cell_type": "code",
"execution_count": 202,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 202,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g.write_dot('./dev/graph.dot')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Model "
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"n = 100\n",
"m = 50\n",
"h = 10\n",
"\n",
"W = theano.shared(np.random.normal(0, 1, (m, h)).astype(theano.config.floatX), borrow=True)\n",
"X = T.dmatrix('X')\n",
"Z = T.nnet.sigmoid(T.dot(X, W) + 10)\n",
"zm = T.mean(Z)\n",
"\n",
"predict_profiled = theano.function([X], [Z, zm], profile=True)\n",
"data = rng.rand(n, m)\n",
"dZ, dzm = predict_profiled(data)\n",
"\n",
"predict_unprofiled = theano.function([X], [Z, zm], profile=False)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"f = predict_unprofiled"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"topo = f.maker.fgraph.toposort()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[Shape_i{1}(<TensorType(float32, matrix)>),\n",
" Shape_i{0}(X),\n",
" dot(X, <TensorType(float32, matrix)>),\n",
" MakeVector(Shape_i{0}.0, Shape_i{1}.0),\n",
" Elemwise{Composite{scalar_sigmoid((i0 + i1))}}[(0, 1)](TensorConstant{(1, 1) of 10.0}, dot.0),\n",
" Elemwise{Cast{float64}}(MakeVector.0),\n",
" Sum{acc_dtype=float64}(Elemwise{Composite{scalar_sigmoid((i0 + i1))}}[(0, 1)].0),\n",
" Subtensor{int64}(Elemwise{Cast{float64}}.0, Constant{1}),\n",
" Subtensor{int64}(Elemwise{Cast{float64}}.0, Constant{0}),\n",
" Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)](Sum{acc_dtype=float64}.0, Subtensor{int64}.0, Subtensor{int64}.0)]"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"topo"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"h = topo[2]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'dot'"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"str(h.op)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"gf = d3p.GraphFormatter()"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'predict_profiled' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-50-c56abb762f9b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_pydot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpredict_profiled\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'predict_profiled' is not defined"
]
}
],
"source": [
"g = gf.to_pydot(predict_profiled)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"TensorType(float64, matrix)"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X.type"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"592pt\" viewBox=\"0.00 0.00 934.00 592.00\" width=\"934pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 588)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-588 930,-588 930,4 -4,4\" stroke=\"none\"/>\n",
"<!-- n1 -->\n",
"<g class=\"node\" id=\"node1\"><title>n1</title>\n",
"<ellipse cx=\"573\" cy=\"-478\" fill=\"cyan\" rx=\"52.9443\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"573\" y=\"-474.3\">Shape_i{1}</text>\n",
"</g>\n",
"<!-- n9 -->\n",
"<g class=\"node\" id=\"node6\"><title>n9</title>\n",
"<ellipse cx=\"648\" cy=\"-390\" fill=\"none\" rx=\"55.3436\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"648\" y=\"-386.3\">MakeVector</text>\n",
"</g>\n",
"<!-- n1&#45;&gt;n9 -->\n",
"<g class=\"edge\" id=\"edge6\"><title>n1-&gt;n9</title>\n",
"<path d=\"M572.355,-459.93C572.779,-449.259 574.912,-435.743 582,-426 587.155,-418.914 594.186,-413.13 601.744,-408.455\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"603.717,-411.364 610.777,-403.465 600.332,-405.237 603.717,-411.364\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"660\" y=\"-430.3\">1 TensorType(int64, scalar)</text>\n",
"</g>\n",
"<!-- n2 -->\n",
"<g class=\"node\" id=\"node2\"><title>n2</title>\n",
"<polygon fill=\"limegreen\" points=\"401,-584 225,-584 225,-548 401,-548 401,-584\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"313\" y=\"-562.3\">TensorType(float32, matrix)</text>\n",
"</g>\n",
"<!-- n2&#45;&gt;n1 -->\n",
"<g class=\"edge\" id=\"edge1\"><title>n2-&gt;n1</title>\n",
"<path d=\"M330.813,-547.903C344.906,-534.761 363.707,-518.168 373,-514 425.821,-490.312 445.119,-506.752 502,-496 508.527,-494.766 515.357,-493.325 522.092,-491.813\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"522.889,-495.222 531.847,-489.564 521.316,-488.401 522.889,-495.222\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"453\" y=\"-518.3\">TensorType(float32, matrix)</text>\n",
"</g>\n",
"<!-- n7 -->\n",
"<g class=\"node\" id=\"node5\"><title>n7</title>\n",
"<ellipse cx=\"171\" cy=\"-478\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"171\" y=\"-474.3\">dot</text>\n",
"</g>\n",
"<!-- n2&#45;&gt;n7 -->\n",
"<g class=\"edge\" id=\"edge4\"><title>n2-&gt;n7</title>\n",
"<path d=\"M224.787,-549.7C204.15,-544.432 186.098,-537.845 179,-530 173.186,-523.574 170.623,-514.727 169.684,-506.205\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"173.178,-505.988 169.235,-496.155 166.185,-506.301 173.178,-505.988\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"264\" y=\"-518.3\">1 TensorType(float32, matrix)</text>\n",
"</g>\n",
"<!-- n4 -->\n",
"<g class=\"node\" id=\"node3\"><title>n4</title>\n",
"<ellipse cx=\"759\" cy=\"-478\" fill=\"cyan\" rx=\"52.9443\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"759\" y=\"-474.3\">Shape_i{0}</text>\n",
"</g>\n",
"<!-- n4&#45;&gt;n9 -->\n",
"<g class=\"edge\" id=\"edge5\"><title>n4-&gt;n9</title>\n",
"<path d=\"M755.613,-459.897C752.644,-448.941 747.299,-435.117 738,-426 728.175,-416.366 715.398,-409.312 702.572,-404.174\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"703.397,-400.749 692.803,-400.607 700.996,-407.325 703.397,-400.749\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"827\" y=\"-430.3\">0 TensorType(int64, scalar)</text>\n",
"</g>\n",
"<!-- n5 -->\n",
"<g class=\"node\" id=\"node4\"><title>n5</title>\n",
"<polygon fill=\"limegreen\" points=\"726,-584 498,-584 498,-548 726,-548 726,-584\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"612\" y=\"-562.3\">name=X TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- n5&#45;&gt;n4 -->\n",
"<g class=\"edge\" id=\"edge2\"><title>n5-&gt;n4</title>\n",
"<path d=\"M694.414,-547.891C706.032,-543.272 717.303,-537.417 727,-530 735.504,-523.496 742.325,-514.033 747.449,-505.019\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"750.666,-506.419 752.174,-495.932 744.456,-503.19 750.666,-506.419\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"822\" y=\"-518.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- n5&#45;&gt;n7 -->\n",
"<g class=\"edge\" id=\"edge3\"><title>n5-&gt;n7</title>\n",
"<path d=\"M581.478,-547.985C572.166,-542.506 562.012,-536.233 553,-530 543.638,-523.525 543.634,-518.063 533,-514 465.224,-488.105 277.332,-513.822 207,-496 204.822,-495.448 202.618,-494.763 200.427,-493.986\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"201.63,-490.696 191.05,-490.131 198.968,-497.17 201.63,-490.696\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"638\" y=\"-518.3\">0 TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- n11 -->\n",
"<g class=\"node\" id=\"node7\"><title>n11</title>\n",
"<ellipse cx=\"220\" cy=\"-390\" fill=\"#ffaabb\" rx=\"219.996\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"220\" y=\"-386.3\">Elemwise{Composite{scalar_sigmoid((i0 + i1))}}[(0, 1)]</text>\n",
"</g>\n",
"<!-- n7&#45;&gt;n11 -->\n",
"<g class=\"edge\" id=\"edge8\"><title>n7-&gt;n11</title>\n",
"<path d=\"M163.286,-460.433C159.603,-449.963 157.137,-436.481 163,-426 165.522,-421.492 168.889,-417.493 172.73,-413.964\" fill=\"none\" stroke=\"red\"/>\n",
"<polygon fill=\"red\" points=\"174.928,-416.688 180.606,-407.744 170.589,-411.195 174.928,-416.688\" stroke=\"red\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"248\" y=\"-430.3\">1 TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- n14 -->\n",
"<g class=\"node\" id=\"node10\"><title>n14</title>\n",
"<ellipse cx=\"648\" cy=\"-302\" fill=\"#ffaabb\" rx=\"104.937\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"648\" y=\"-298.3\">Elemwise{Cast{float64}}</text>\n",
"</g>\n",
"<!-- n9&#45;&gt;n14 -->\n",
"<g class=\"edge\" id=\"edge10\"><title>n9-&gt;n14</title>\n",
"<path d=\"M648,-371.597C648,-359.746 648,-343.817 648,-330.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"651.5,-330.084 648,-320.084 644.5,-330.084 651.5,-330.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"722\" y=\"-342.3\">TensorType(int64, vector)</text>\n",
"</g>\n",
"<!-- n13 -->\n",
"<g class=\"node\" id=\"node9\"><title>n13</title>\n",
"<polygon fill=\"dodgerblue\" points=\"380.25,-320 175.75,-320 175.75,-284 380.25,-284 380.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"278\" y=\"-298.3\">TensorType(float64, matrix) id=7</text>\n",
"</g>\n",
"<!-- n11&#45;&gt;n13 -->\n",
"<g class=\"edge\" id=\"edge9\"><title>n11-&gt;n13</title>\n",
"<path d=\"M240.539,-371.725C246.033,-366.426 251.647,-360.316 256,-354 261.057,-346.662 265.33,-337.975 268.726,-329.869\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"272.046,-330.989 272.427,-320.401 265.527,-328.44 272.046,-330.989\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"346\" y=\"-342.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- n16 -->\n",
"<g class=\"node\" id=\"node11\"><title>n16</title>\n",
"<ellipse cx=\"127\" cy=\"-248\" fill=\"none\" rx=\"103.012\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"127\" y=\"-244.3\">Sum{acc_dtype=float64}</text>\n",
"</g>\n",
"<!-- n11&#45;&gt;n16 -->\n",
"<g class=\"edge\" id=\"edge11\"><title>n11-&gt;n16</title>\n",
"<path d=\"M132.915,-373.431C114.048,-368.256 97.9406,-361.783 92,-354 73.9089,-330.298 90.6097,-296.751 106.571,-274.002\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"109.46,-275.981 112.578,-265.855 103.826,-271.827 109.46,-275.981\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"172\" y=\"-342.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- n12 -->\n",
"<g class=\"node\" id=\"node8\"><title>n12</title>\n",
"<polygon fill=\"limegreen\" points=\"493.25,-496 216.75,-496 216.75,-460 493.25,-460 493.25,-496\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355\" y=\"-474.3\">val=[[ 10.]] TensorType(float64, (True, True))</text>\n",
"</g>\n",
"<!-- n12&#45;&gt;n11 -->\n",
"<g class=\"edge\" id=\"edge7\"><title>n12-&gt;n11</title>\n",
"<path d=\"M351.46,-459.665C348.355,-448.61 342.755,-434.765 333,-426 326.396,-420.066 318.799,-415.139 310.735,-411.046\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"312.005,-407.778 301.458,-406.772 309.075,-414.136 312.005,-407.778\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"446.5\" y=\"-430.3\">0 TensorType(float64, (True, True))</text>\n",
"</g>\n",
"<!-- n18 -->\n",
"<g class=\"node\" id=\"node12\"><title>n18</title>\n",
"<ellipse cx=\"694\" cy=\"-194\" fill=\"#ffaaff\" rx=\"74.6146\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"694\" y=\"-190.3\">Subtensor{int64}</text>\n",
"</g>\n",
"<!-- n14&#45;&gt;n18 -->\n",
"<g class=\"edge\" id=\"edge12\"><title>n14-&gt;n18</title>\n",
"<path d=\"M661.293,-283.824C665.117,-278.337 669.047,-272.101 672,-266 678.765,-252.023 684.031,-235.5 687.712,-221.911\" fill=\"none\" stroke=\"dodgerblue\"/>\n",
"<polygon fill=\"dodgerblue\" points=\"691.113,-222.74 690.217,-212.183 684.334,-220.994 691.113,-222.74\" stroke=\"dodgerblue\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"770.5\" y=\"-244.3\">0 TensorType(float64, vector)</text>\n",
"</g>\n",
"<!-- n21 -->\n",
"<g class=\"node\" id=\"node14\"><title>n21</title>\n",
"<ellipse cx=\"486\" cy=\"-194\" fill=\"#ffaaff\" rx=\"93.3873\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"486\" y=\"-190.3\">Subtensor{int64} id=8</text>\n",
"</g>\n",
"<!-- n14&#45;&gt;n21 -->\n",
"<g class=\"edge\" id=\"edge14\"><title>n14-&gt;n21</title>\n",
"<path d=\"M568.124,-290.24C538.265,-284.611 509.12,-276.635 499,-266 488.087,-254.531 484.779,-237.091 484.227,-222.365\" fill=\"none\" stroke=\"dodgerblue\"/>\n",
"<polygon fill=\"dodgerblue\" points=\"487.728,-222.253 484.244,-212.247 480.728,-222.242 487.728,-222.253\" stroke=\"dodgerblue\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"583.5\" y=\"-244.3\">0 TensorType(float64, vector)</text>\n",
"</g>\n",
"<!-- n24 -->\n",
"<g class=\"node\" id=\"node16\"><title>n24</title>\n",
"<ellipse cx=\"486\" cy=\"-106\" fill=\"#ffaabb\" rx=\"176.177\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"486\" y=\"-102.3\">Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</text>\n",
"</g>\n",
"<!-- n16&#45;&gt;n24 -->\n",
"<g class=\"edge\" id=\"edge16\"><title>n16-&gt;n24</title>\n",
"<path d=\"M143.532,-230.175C160.346,-214 187.864,-190.002 216,-176 267.475,-150.382 329.343,-133.68 380.863,-123.136\" fill=\"none\" stroke=\"red\"/>\n",
"<polygon fill=\"red\" points=\"381.569,-126.564 390.69,-121.173 380.198,-119.699 381.569,-126.564\" stroke=\"red\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"299.5\" y=\"-190.3\">0 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- n18&#45;&gt;n24 -->\n",
"<g class=\"edge\" id=\"edge18\"><title>n18-&gt;n24</title>\n",
"<path d=\"M685.082,-175.699C678.339,-164.365 668.024,-150.185 655,-142 641.889,-133.761 627.185,-127.421 612.064,-122.551\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"612.664,-119.077 602.08,-119.557 610.654,-125.782 612.664,-119.077\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"755.5\" y=\"-146.3\">2 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- n19 -->\n",
"<g class=\"node\" id=\"node13\"><title>n19</title>\n",
"<polygon fill=\"limegreen\" points=\"926.25,-320 845.75,-320 845.75,-284 926.25,-284 926.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"886\" y=\"-298.3\">val=1 int64</text>\n",
"</g>\n",
"<!-- n19&#45;&gt;n18 -->\n",
"<g class=\"edge\" id=\"edge13\"><title>n19-&gt;n18</title>\n",
"<path d=\"M884.117,-283.711C881.401,-267.422 874.826,-243.554 859,-230 845.277,-218.247 806.446,-209.693 769.902,-203.984\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"770.086,-200.472 759.677,-202.449 769.047,-207.395 770.086,-200.472\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"900\" y=\"-244.3\">1 int64</text>\n",
"</g>\n",
"<!-- n21&#45;&gt;n24 -->\n",
"<g class=\"edge\" id=\"edge17\"><title>n21-&gt;n24</title>\n",
"<path d=\"M486,-175.597C486,-163.746 486,-147.817 486,-134.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"489.5,-134.084 486,-124.084 482.5,-134.084 489.5,-134.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"569.5\" y=\"-146.3\">1 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- n22 -->\n",
"<g class=\"node\" id=\"node15\"><title>n22</title>\n",
"<polygon fill=\"limegreen\" points=\"479.25,-320 398.75,-320 398.75,-284 479.25,-284 479.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"439\" y=\"-298.3\">val=0 int64</text>\n",
"</g>\n",
"<!-- n22&#45;&gt;n21 -->\n",
"<g class=\"edge\" id=\"edge15\"><title>n22-&gt;n21</title>\n",
"<path d=\"M435.23,-283.946C432.807,-268.911 431.505,-246.84 440,-230 442.201,-225.638 445.228,-221.669 448.688,-218.102\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"451.133,-220.611 456.272,-211.345 446.477,-215.384 451.133,-220.611\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"460\" y=\"-244.3\">1 int64</text>\n",
"</g>\n",
"<!-- n25 -->\n",
"<g class=\"node\" id=\"node17\"><title>n25</title>\n",
"<polygon fill=\"dodgerblue\" points=\"590,-36 382,-36 382,-0 590,-0 590,-36\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"486\" y=\"-14.3\">TensorType(float64, scalar) id=14</text>\n",
"</g>\n",
"<!-- n24&#45;&gt;n25 -->\n",
"<g class=\"edge\" id=\"edge19\"><title>n24-&gt;n25</title>\n",
"<path d=\"M486,-87.5966C486,-75.7459 486,-59.8169 486,-46.2917\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"489.5,-46.084 486,-36.084 482.5,-46.084 489.5,-46.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"564\" y=\"-58.3\">TensorType(float64, scalar)</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Profiled graphed "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "OSError",
"evalue": "[Errno 2] No such file or directory: ''",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-a7148915a619>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_pydot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpredict_profiled\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0md3p\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0md3print\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpredict_profiled\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'predict_profiled.html'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/Users/angermue/python/projects/theano/theano/theano/d3printing/d3printing.pyc\u001b[0m in \u001b[0;36md3print\u001b[0;34m(fct, outfile, *args, **kwargs)\u001b[0m\n\u001b[1;32m 52\u001b[0m \u001b[0moutdir\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdirname\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutfile\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexists\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutdir\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 54\u001b[0;31m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmakedirs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutdir\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 55\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[0;31m# Create dot file\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/Users/angermue/python/venv/theano/lib/python2.7/os.pyc\u001b[0m in \u001b[0;36mmakedirs\u001b[0;34m(name, mode)\u001b[0m\n\u001b[1;32m 155\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtail\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mcurdir\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# xxx/newdir/. exists if xxx/newdir exists\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 156\u001b[0m \u001b[0;32mreturn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 157\u001b[0;31m \u001b[0mmkdir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 158\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mremovedirs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mOSError\u001b[0m: [Errno 2] No such file or directory: ''"
]
}
],
"source": [
"g = gf.to_pydot(predict_profiled)\n",
"d3p.d3print(predict_profiled, 'predict_profiled.html')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[open](./predict_profiled.html) "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"592pt\" viewBox=\"0.00 0.00 931.00 592.00\" width=\"931pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 588)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-588 927,-588 927,4 -4,4\" stroke=\"none\"/>\n",
"<!-- Shape_i{1} -->\n",
"<g class=\"node\" id=\"node1\"><title>Shape_i{1}</title>\n",
"<ellipse cx=\"763\" cy=\"-478\" fill=\"cyan\" rx=\"52.9443\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"763\" y=\"-474.3\">Shape_i{1}</text>\n",
"</g>\n",
"<!-- MakeVector -->\n",
"<g class=\"node\" id=\"node6\"><title>MakeVector</title>\n",
"<ellipse cx=\"602\" cy=\"-390\" fill=\"none\" rx=\"55.3436\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"602\" y=\"-386.3\">MakeVector</text>\n",
"</g>\n",
"<!-- Shape_i{1}&#45;&gt;MakeVector -->\n",
"<g class=\"edge\" id=\"edge6\"><title>Shape_i{1}-&gt;MakeVector</title>\n",
"<path d=\"M735.689,-462.411C708.974,-448.141 668.114,-426.315 638.598,-410.549\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"639.915,-407.285 629.445,-405.66 636.617,-413.459 639.915,-407.285\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"775\" y=\"-430.3\">1 TensorType(int64, scalar)</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix) -->\n",
"<g class=\"node\" id=\"node2\"><title>TensorType(float64, matrix)</title>\n",
"<polygon fill=\"limegreen\" points=\"728,-584 552,-584 552,-548 728,-548 728,-584\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"640\" y=\"-562.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix)&#45;&gt;Shape_i{1} -->\n",
"<g class=\"edge\" id=\"edge1\"><title>TensorType(float64, matrix)-&gt;Shape_i{1}</title>\n",
"<path d=\"M728.218,-549.113C737.934,-544.301 746.871,-538.067 754,-530 759.757,-523.486 762.449,-514.618 763.57,-506.103\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"767.066,-506.289 764.259,-496.073 760.082,-505.81 767.066,-506.289\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"843\" y=\"-518.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Dot22 -->\n",
"<g class=\"node\" id=\"node5\"><title>Dot22</title>\n",
"<ellipse cx=\"242\" cy=\"-478\" fill=\"none\" rx=\"33.1991\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"242\" y=\"-474.3\">Dot22</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix)&#45;&gt;Dot22 -->\n",
"<g class=\"edge\" id=\"edge4\"><title>TensorType(float64, matrix)-&gt;Dot22</title>\n",
"<path d=\"M610.316,-547.87C600.623,-542.227 589.827,-535.889 580,-530 568.361,-523.026 566.88,-518.266 554,-514 467.597,-485.383 440.342,-507.083 350,-496 328.021,-493.304 303.645,-489.534 283.621,-486.23\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"284.023,-482.749 273.583,-484.552 282.869,-489.653 284.023,-482.749\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"665\" y=\"-518.3\">1 TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Shape_i{0} -->\n",
"<g class=\"node\" id=\"node3\"><title>Shape_i{0}</title>\n",
"<ellipse cx=\"412\" cy=\"-478\" fill=\"cyan\" rx=\"52.9443\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"412\" y=\"-474.3\">Shape_i{0}</text>\n",
"</g>\n",
"<!-- Shape_i{0}&#45;&gt;MakeVector -->\n",
"<g class=\"edge\" id=\"edge5\"><title>Shape_i{0}-&gt;MakeVector</title>\n",
"<path d=\"M437.912,-462.25C457.204,-451.547 484.353,-437.066 509,-426 523.976,-419.276 540.668,-412.715 555.731,-407.125\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"557.173,-410.324 565.36,-403.6 554.766,-403.751 557.173,-410.324\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"587\" y=\"-430.3\">0 TensorType(int64, scalar)</text>\n",
"</g>\n",
"<!-- name=X TensorType(float64, matrix) -->\n",
"<g class=\"node\" id=\"node4\"><title>name=X TensorType(float64, matrix)</title>\n",
"<polygon fill=\"limegreen\" points=\"456,-584 228,-584 228,-548 456,-548 456,-584\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"342\" y=\"-562.3\">name=X TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- name=X TensorType(float64, matrix)&#45;&gt;Shape_i{0} -->\n",
"<g class=\"edge\" id=\"edge2\"><title>name=X TensorType(float64, matrix)-&gt;Shape_i{0}</title>\n",
"<path d=\"M361.08,-547.903C366.78,-542.42 372.872,-536.166 378,-530 384.666,-521.984 391.209,-512.635 396.748,-504.146\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"399.704,-506.02 402.118,-495.704 393.798,-502.262 399.704,-506.02\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"470\" y=\"-518.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- name=X TensorType(float64, matrix)&#45;&gt;Dot22 -->\n",
"<g class=\"edge\" id=\"edge3\"><title>name=X TensorType(float64, matrix)-&gt;Dot22</title>\n",
"<path d=\"M240.099,-547.929C223.328,-543.107 209.578,-537.169 204,-530 196.089,-519.832 203.283,-508.338 213.457,-498.839\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"215.81,-501.433 221.218,-492.323 211.309,-496.073 215.81,-501.433\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"289\" y=\"-518.3\">0 TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Elemwise{ScalarSigmoid}[(0, 0)] -->\n",
"<g class=\"node\" id=\"node7\"><title>Elemwise{ScalarSigmoid}[(0, 0)]</title>\n",
"<ellipse cx=\"242\" cy=\"-390\" fill=\"#ffaabb\" rx=\"134.307\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"242\" y=\"-386.3\">Elemwise{ScalarSigmoid}[(0, 0)]</text>\n",
"</g>\n",
"<!-- Dot22&#45;&gt;Elemwise{ScalarSigmoid}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge7\"><title>Dot22-&gt;Elemwise{ScalarSigmoid}[(0, 0)]</title>\n",
"<path d=\"M242,-459.597C242,-447.746 242,-431.817 242,-418.292\" fill=\"none\" stroke=\"red\"/>\n",
"<polygon fill=\"red\" points=\"245.5,-418.084 242,-408.084 238.5,-418.084 245.5,-418.084\" stroke=\"red\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"322\" y=\"-430.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Elemwise{Cast{float64}} -->\n",
"<g class=\"node\" id=\"node9\"><title>Elemwise{Cast{float64}}</title>\n",
"<ellipse cx=\"602\" cy=\"-302\" fill=\"#ffaabb\" rx=\"104.937\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"602\" y=\"-298.3\">Elemwise{Cast{float64}}</text>\n",
"</g>\n",
"<!-- MakeVector&#45;&gt;Elemwise{Cast{float64}} -->\n",
"<g class=\"edge\" id=\"edge9\"><title>MakeVector-&gt;Elemwise{Cast{float64}}</title>\n",
"<path d=\"M602,-371.597C602,-359.746 602,-343.817 602,-330.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"605.5,-330.084 602,-320.084 598.5,-330.084 605.5,-330.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"676\" y=\"-342.3\">TensorType(int64, vector)</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix) id=6 -->\n",
"<g class=\"node\" id=\"node8\"><title>TensorType(float64, matrix) id=6</title>\n",
"<polygon fill=\"dodgerblue\" points=\"356.25,-320 151.75,-320 151.75,-284 356.25,-284 356.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"254\" y=\"-298.3\">TensorType(float64, matrix) id=6</text>\n",
"</g>\n",
"<!-- Elemwise{ScalarSigmoid}[(0, 0)]&#45;&gt;TensorType(float64, matrix) id=6 -->\n",
"<g class=\"edge\" id=\"edge8\"><title>Elemwise{ScalarSigmoid}[(0, 0)]-&gt;TensorType(float64, matrix) id=6</title>\n",
"<path d=\"M244.428,-371.597C246.082,-359.746 248.305,-343.817 250.192,-330.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"253.701,-330.472 251.616,-320.084 246.768,-329.504 253.701,-330.472\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"330\" y=\"-342.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Sum{acc_dtype=float64} -->\n",
"<g class=\"node\" id=\"node10\"><title>Sum{acc_dtype=float64}</title>\n",
"<ellipse cx=\"103\" cy=\"-248\" fill=\"none\" rx=\"103.012\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103\" y=\"-244.3\">Sum{acc_dtype=float64}</text>\n",
"</g>\n",
"<!-- Elemwise{ScalarSigmoid}[(0, 0)]&#45;&gt;Sum{acc_dtype=float64} -->\n",
"<g class=\"edge\" id=\"edge10\"><title>Elemwise{ScalarSigmoid}[(0, 0)]-&gt;Sum{acc_dtype=float64}</title>\n",
"<path d=\"M144.123,-377.632C116.496,-372.297 91.5885,-364.685 83,-354 65.1182,-331.754 75.9432,-298.337 87.4351,-275.202\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"90.5714,-276.758 92.1497,-266.282 84.3826,-273.487 90.5714,-276.758\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"163\" y=\"-342.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Subtensor{int64} -->\n",
"<g class=\"node\" id=\"node11\"><title>Subtensor{int64}</title>\n",
"<ellipse cx=\"670\" cy=\"-194\" fill=\"#ffaaff\" rx=\"74.6146\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"670\" y=\"-190.3\">Subtensor{int64}</text>\n",
"</g>\n",
"<!-- Elemwise{Cast{float64}}&#45;&gt;Subtensor{int64} -->\n",
"<g class=\"edge\" id=\"edge11\"><title>Elemwise{Cast{float64}}-&gt;Subtensor{int64}</title>\n",
"<path d=\"M629.37,-284.551C636.239,-279.342 643.053,-273.072 648,-266 657.078,-253.024 662.508,-236.173 665.701,-222.144\" fill=\"none\" stroke=\"dodgerblue\"/>\n",
"<polygon fill=\"dodgerblue\" points=\"669.185,-222.571 667.731,-212.077 662.323,-221.188 669.185,-222.571\" stroke=\"dodgerblue\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"748.5\" y=\"-244.3\">0 TensorType(float64, vector)</text>\n",
"</g>\n",
"<!-- Subtensor{int64} id=8 -->\n",
"<g class=\"node\" id=\"node13\"><title>Subtensor{int64} id=8</title>\n",
"<ellipse cx=\"462\" cy=\"-194\" fill=\"#ffaaff\" rx=\"93.3873\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"462\" y=\"-190.3\">Subtensor{int64} id=8</text>\n",
"</g>\n",
"<!-- Elemwise{Cast{float64}}&#45;&gt;Subtensor{int64} id=8 -->\n",
"<g class=\"edge\" id=\"edge13\"><title>Elemwise{Cast{float64}}-&gt;Subtensor{int64} id=8</title>\n",
"<path d=\"M516.396,-291.457C500.826,-286.113 486.044,-278.059 475,-266 464.308,-254.325 461.003,-236.882 460.398,-222.207\" fill=\"none\" stroke=\"dodgerblue\"/>\n",
"<polygon fill=\"dodgerblue\" points=\"463.897,-222.122 460.367,-212.132 456.897,-222.143 463.897,-222.122\" stroke=\"dodgerblue\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"559.5\" y=\"-244.3\">0 TensorType(float64, vector)</text>\n",
"</g>\n",
"<!-- Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"node\" id=\"node15\"><title>Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<ellipse cx=\"462\" cy=\"-106\" fill=\"#ffaabb\" rx=\"176.177\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"462\" y=\"-102.3\">Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</text>\n",
"</g>\n",
"<!-- Sum{acc_dtype=float64}&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge15\"><title>Sum{acc_dtype=float64}-&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<path d=\"M119.532,-230.175C136.346,-214 163.864,-190.002 192,-176 243.475,-150.382 305.343,-133.68 356.863,-123.136\" fill=\"none\" stroke=\"red\"/>\n",
"<polygon fill=\"red\" points=\"357.569,-126.564 366.69,-121.173 356.198,-119.699 357.569,-126.564\" stroke=\"red\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"275.5\" y=\"-190.3\">0 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- Subtensor{int64}&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge17\"><title>Subtensor{int64}-&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<path d=\"M661.082,-175.699C654.339,-164.365 644.024,-150.185 631,-142 617.889,-133.761 603.185,-127.421 588.064,-122.551\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"588.664,-119.077 578.08,-119.557 586.654,-125.782 588.664,-119.077\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"731.5\" y=\"-146.3\">2 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- val=1 int64 -->\n",
"<g class=\"node\" id=\"node12\"><title>val=1 int64</title>\n",
"<polygon fill=\"limegreen\" points=\"902.25,-320 821.75,-320 821.75,-284 902.25,-284 902.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"862\" y=\"-298.3\">val=1 int64</text>\n",
"</g>\n",
"<!-- val=1 int64&#45;&gt;Subtensor{int64} -->\n",
"<g class=\"edge\" id=\"edge12\"><title>val=1 int64-&gt;Subtensor{int64}</title>\n",
"<path d=\"M860.642,-283.734C858.414,-267.462 852.531,-243.606 837,-230 823.252,-217.956 783.956,-209.391 746.935,-203.749\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"746.978,-200.219 736.577,-202.235 745.965,-207.145 746.978,-200.219\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"877\" y=\"-244.3\">1 int64</text>\n",
"</g>\n",
"<!-- Subtensor{int64} id=8&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge16\"><title>Subtensor{int64} id=8-&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<path d=\"M462,-175.597C462,-163.746 462,-147.817 462,-134.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"465.5,-134.084 462,-124.084 458.5,-134.084 465.5,-134.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"545.5\" y=\"-146.3\">1 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- val=0 int64 -->\n",
"<g class=\"node\" id=\"node14\"><title>val=0 int64</title>\n",
"<polygon fill=\"limegreen\" points=\"455.25,-320 374.75,-320 374.75,-284 455.25,-284 455.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"415\" y=\"-298.3\">val=0 int64</text>\n",
"</g>\n",
"<!-- val=0 int64&#45;&gt;Subtensor{int64} id=8 -->\n",
"<g class=\"edge\" id=\"edge14\"><title>val=0 int64-&gt;Subtensor{int64} id=8</title>\n",
"<path d=\"M411.23,-283.946C408.807,-268.911 407.505,-246.84 416,-230 418.201,-225.638 421.228,-221.669 424.688,-218.102\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"427.133,-220.611 432.272,-211.345 422.477,-215.384 427.133,-220.611\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"436\" y=\"-244.3\">1 int64</text>\n",
"</g>\n",
"<!-- TensorType(float64, scalar) id=13 -->\n",
"<g class=\"node\" id=\"node16\"><title>TensorType(float64, scalar) id=13</title>\n",
"<polygon fill=\"dodgerblue\" points=\"566,-36 358,-36 358,-0 566,-0 566,-36\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"462\" y=\"-14.3\">TensorType(float64, scalar) id=13</text>\n",
"</g>\n",
"<!-- Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]&#45;&gt;TensorType(float64, scalar) id=13 -->\n",
"<g class=\"edge\" id=\"edge18\"><title>Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]-&gt;TensorType(float64, scalar) id=13</title>\n",
"<path d=\"M462,-87.5966C462,-75.7459 462,-59.8169 462,-46.2917\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"465.5,-46.084 462,-36.084 458.5,-46.084 465.5,-46.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"540\" y=\"-58.3\">TensorType(float64, scalar)</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unprofiled graph"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The output file is available at predict_unprofiled.html\n"
]
}
],
"source": [
"g = gf.to_pydot(predict_unprofiled)\n",
"d3p.d3print(predict_unprofiled, 'predict_unprofiled.html')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[open](./predict_unprofiled.html) "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"592pt\" viewBox=\"0.00 0.00 931.00 592.00\" width=\"931pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 588)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" points=\"-4,4 -4,-588 927,-588 927,4 -4,4\" stroke=\"none\"/>\n",
"<!-- Shape_i{1} -->\n",
"<g class=\"node\" id=\"node1\"><title>Shape_i{1}</title>\n",
"<ellipse cx=\"763\" cy=\"-478\" fill=\"cyan\" rx=\"52.9443\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"763\" y=\"-474.3\">Shape_i{1}</text>\n",
"</g>\n",
"<!-- MakeVector -->\n",
"<g class=\"node\" id=\"node6\"><title>MakeVector</title>\n",
"<ellipse cx=\"602\" cy=\"-390\" fill=\"none\" rx=\"55.3436\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"602\" y=\"-386.3\">MakeVector</text>\n",
"</g>\n",
"<!-- Shape_i{1}&#45;&gt;MakeVector -->\n",
"<g class=\"edge\" id=\"edge6\"><title>Shape_i{1}-&gt;MakeVector</title>\n",
"<path d=\"M735.689,-462.411C708.974,-448.141 668.114,-426.315 638.598,-410.549\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"639.915,-407.285 629.445,-405.66 636.617,-413.459 639.915,-407.285\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"775\" y=\"-430.3\">1 TensorType(int64, scalar)</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix) -->\n",
"<g class=\"node\" id=\"node2\"><title>TensorType(float64, matrix)</title>\n",
"<polygon fill=\"limegreen\" points=\"728,-584 552,-584 552,-548 728,-548 728,-584\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"640\" y=\"-562.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix)&#45;&gt;Shape_i{1} -->\n",
"<g class=\"edge\" id=\"edge1\"><title>TensorType(float64, matrix)-&gt;Shape_i{1}</title>\n",
"<path d=\"M728.218,-549.113C737.934,-544.301 746.871,-538.067 754,-530 759.757,-523.486 762.449,-514.618 763.57,-506.103\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"767.066,-506.289 764.259,-496.073 760.082,-505.81 767.066,-506.289\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"843\" y=\"-518.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Dot22 -->\n",
"<g class=\"node\" id=\"node5\"><title>Dot22</title>\n",
"<ellipse cx=\"242\" cy=\"-478\" fill=\"none\" rx=\"33.1991\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"242\" y=\"-474.3\">Dot22</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix)&#45;&gt;Dot22 -->\n",
"<g class=\"edge\" id=\"edge4\"><title>TensorType(float64, matrix)-&gt;Dot22</title>\n",
"<path d=\"M610.316,-547.87C600.623,-542.227 589.827,-535.889 580,-530 568.361,-523.026 566.88,-518.266 554,-514 467.597,-485.383 440.342,-507.083 350,-496 328.021,-493.304 303.645,-489.534 283.621,-486.23\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"284.023,-482.749 273.583,-484.552 282.869,-489.653 284.023,-482.749\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"665\" y=\"-518.3\">1 TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Shape_i{0} -->\n",
"<g class=\"node\" id=\"node3\"><title>Shape_i{0}</title>\n",
"<ellipse cx=\"412\" cy=\"-478\" fill=\"cyan\" rx=\"52.9443\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"412\" y=\"-474.3\">Shape_i{0}</text>\n",
"</g>\n",
"<!-- Shape_i{0}&#45;&gt;MakeVector -->\n",
"<g class=\"edge\" id=\"edge5\"><title>Shape_i{0}-&gt;MakeVector</title>\n",
"<path d=\"M437.912,-462.25C457.204,-451.547 484.353,-437.066 509,-426 523.976,-419.276 540.668,-412.715 555.731,-407.125\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"557.173,-410.324 565.36,-403.6 554.766,-403.751 557.173,-410.324\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"587\" y=\"-430.3\">0 TensorType(int64, scalar)</text>\n",
"</g>\n",
"<!-- name=X TensorType(float64, matrix) -->\n",
"<g class=\"node\" id=\"node4\"><title>name=X TensorType(float64, matrix)</title>\n",
"<polygon fill=\"limegreen\" points=\"456,-584 228,-584 228,-548 456,-548 456,-584\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"342\" y=\"-562.3\">name=X TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- name=X TensorType(float64, matrix)&#45;&gt;Shape_i{0} -->\n",
"<g class=\"edge\" id=\"edge2\"><title>name=X TensorType(float64, matrix)-&gt;Shape_i{0}</title>\n",
"<path d=\"M361.08,-547.903C366.78,-542.42 372.872,-536.166 378,-530 384.666,-521.984 391.209,-512.635 396.748,-504.146\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"399.704,-506.02 402.118,-495.704 393.798,-502.262 399.704,-506.02\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"470\" y=\"-518.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- name=X TensorType(float64, matrix)&#45;&gt;Dot22 -->\n",
"<g class=\"edge\" id=\"edge3\"><title>name=X TensorType(float64, matrix)-&gt;Dot22</title>\n",
"<path d=\"M240.099,-547.929C223.328,-543.107 209.578,-537.169 204,-530 196.089,-519.832 203.283,-508.338 213.457,-498.839\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"215.81,-501.433 221.218,-492.323 211.309,-496.073 215.81,-501.433\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"289\" y=\"-518.3\">0 TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Elemwise{ScalarSigmoid}[(0, 0)] -->\n",
"<g class=\"node\" id=\"node7\"><title>Elemwise{ScalarSigmoid}[(0, 0)]</title>\n",
"<ellipse cx=\"242\" cy=\"-390\" fill=\"#ffaabb\" rx=\"134.307\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"242\" y=\"-386.3\">Elemwise{ScalarSigmoid}[(0, 0)]</text>\n",
"</g>\n",
"<!-- Dot22&#45;&gt;Elemwise{ScalarSigmoid}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge7\"><title>Dot22-&gt;Elemwise{ScalarSigmoid}[(0, 0)]</title>\n",
"<path d=\"M242,-459.597C242,-447.746 242,-431.817 242,-418.292\" fill=\"none\" stroke=\"red\"/>\n",
"<polygon fill=\"red\" points=\"245.5,-418.084 242,-408.084 238.5,-418.084 245.5,-418.084\" stroke=\"red\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"322\" y=\"-430.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Elemwise{Cast{float64}} -->\n",
"<g class=\"node\" id=\"node9\"><title>Elemwise{Cast{float64}}</title>\n",
"<ellipse cx=\"602\" cy=\"-302\" fill=\"#ffaabb\" rx=\"104.937\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"602\" y=\"-298.3\">Elemwise{Cast{float64}}</text>\n",
"</g>\n",
"<!-- MakeVector&#45;&gt;Elemwise{Cast{float64}} -->\n",
"<g class=\"edge\" id=\"edge9\"><title>MakeVector-&gt;Elemwise{Cast{float64}}</title>\n",
"<path d=\"M602,-371.597C602,-359.746 602,-343.817 602,-330.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"605.5,-330.084 602,-320.084 598.5,-330.084 605.5,-330.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"676\" y=\"-342.3\">TensorType(int64, vector)</text>\n",
"</g>\n",
"<!-- TensorType(float64, matrix) id=6 -->\n",
"<g class=\"node\" id=\"node8\"><title>TensorType(float64, matrix) id=6</title>\n",
"<polygon fill=\"dodgerblue\" points=\"356.25,-320 151.75,-320 151.75,-284 356.25,-284 356.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"254\" y=\"-298.3\">TensorType(float64, matrix) id=6</text>\n",
"</g>\n",
"<!-- Elemwise{ScalarSigmoid}[(0, 0)]&#45;&gt;TensorType(float64, matrix) id=6 -->\n",
"<g class=\"edge\" id=\"edge8\"><title>Elemwise{ScalarSigmoid}[(0, 0)]-&gt;TensorType(float64, matrix) id=6</title>\n",
"<path d=\"M244.428,-371.597C246.082,-359.746 248.305,-343.817 250.192,-330.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"253.701,-330.472 251.616,-320.084 246.768,-329.504 253.701,-330.472\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"330\" y=\"-342.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Sum{acc_dtype=float64} -->\n",
"<g class=\"node\" id=\"node10\"><title>Sum{acc_dtype=float64}</title>\n",
"<ellipse cx=\"103\" cy=\"-248\" fill=\"none\" rx=\"103.012\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103\" y=\"-244.3\">Sum{acc_dtype=float64}</text>\n",
"</g>\n",
"<!-- Elemwise{ScalarSigmoid}[(0, 0)]&#45;&gt;Sum{acc_dtype=float64} -->\n",
"<g class=\"edge\" id=\"edge10\"><title>Elemwise{ScalarSigmoid}[(0, 0)]-&gt;Sum{acc_dtype=float64}</title>\n",
"<path d=\"M144.123,-377.632C116.496,-372.297 91.5885,-364.685 83,-354 65.1182,-331.754 75.9432,-298.337 87.4351,-275.202\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"90.5714,-276.758 92.1497,-266.282 84.3826,-273.487 90.5714,-276.758\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"163\" y=\"-342.3\">TensorType(float64, matrix)</text>\n",
"</g>\n",
"<!-- Subtensor{int64} -->\n",
"<g class=\"node\" id=\"node11\"><title>Subtensor{int64}</title>\n",
"<ellipse cx=\"670\" cy=\"-194\" fill=\"#ffaaff\" rx=\"74.6146\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"670\" y=\"-190.3\">Subtensor{int64}</text>\n",
"</g>\n",
"<!-- Elemwise{Cast{float64}}&#45;&gt;Subtensor{int64} -->\n",
"<g class=\"edge\" id=\"edge11\"><title>Elemwise{Cast{float64}}-&gt;Subtensor{int64}</title>\n",
"<path d=\"M629.37,-284.551C636.239,-279.342 643.053,-273.072 648,-266 657.078,-253.024 662.508,-236.173 665.701,-222.144\" fill=\"none\" stroke=\"dodgerblue\"/>\n",
"<polygon fill=\"dodgerblue\" points=\"669.185,-222.571 667.731,-212.077 662.323,-221.188 669.185,-222.571\" stroke=\"dodgerblue\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"748.5\" y=\"-244.3\">0 TensorType(float64, vector)</text>\n",
"</g>\n",
"<!-- Subtensor{int64} id=8 -->\n",
"<g class=\"node\" id=\"node13\"><title>Subtensor{int64} id=8</title>\n",
"<ellipse cx=\"462\" cy=\"-194\" fill=\"#ffaaff\" rx=\"93.3873\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"462\" y=\"-190.3\">Subtensor{int64} id=8</text>\n",
"</g>\n",
"<!-- Elemwise{Cast{float64}}&#45;&gt;Subtensor{int64} id=8 -->\n",
"<g class=\"edge\" id=\"edge13\"><title>Elemwise{Cast{float64}}-&gt;Subtensor{int64} id=8</title>\n",
"<path d=\"M516.396,-291.457C500.826,-286.113 486.044,-278.059 475,-266 464.308,-254.325 461.003,-236.882 460.398,-222.207\" fill=\"none\" stroke=\"dodgerblue\"/>\n",
"<polygon fill=\"dodgerblue\" points=\"463.897,-222.122 460.367,-212.132 456.897,-222.143 463.897,-222.122\" stroke=\"dodgerblue\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"559.5\" y=\"-244.3\">0 TensorType(float64, vector)</text>\n",
"</g>\n",
"<!-- Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"node\" id=\"node15\"><title>Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<ellipse cx=\"462\" cy=\"-106\" fill=\"#ffaabb\" rx=\"176.177\" ry=\"18\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"462\" y=\"-102.3\">Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</text>\n",
"</g>\n",
"<!-- Sum{acc_dtype=float64}&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge15\"><title>Sum{acc_dtype=float64}-&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<path d=\"M119.532,-230.175C136.346,-214 163.864,-190.002 192,-176 243.475,-150.382 305.343,-133.68 356.863,-123.136\" fill=\"none\" stroke=\"red\"/>\n",
"<polygon fill=\"red\" points=\"357.569,-126.564 366.69,-121.173 356.198,-119.699 357.569,-126.564\" stroke=\"red\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"275.5\" y=\"-190.3\">0 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- Subtensor{int64}&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge17\"><title>Subtensor{int64}-&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<path d=\"M661.082,-175.699C654.339,-164.365 644.024,-150.185 631,-142 617.889,-133.761 603.185,-127.421 588.064,-122.551\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"588.664,-119.077 578.08,-119.557 586.654,-125.782 588.664,-119.077\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"731.5\" y=\"-146.3\">2 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- val=1 int64 -->\n",
"<g class=\"node\" id=\"node12\"><title>val=1 int64</title>\n",
"<polygon fill=\"limegreen\" points=\"902.25,-320 821.75,-320 821.75,-284 902.25,-284 902.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"862\" y=\"-298.3\">val=1 int64</text>\n",
"</g>\n",
"<!-- val=1 int64&#45;&gt;Subtensor{int64} -->\n",
"<g class=\"edge\" id=\"edge12\"><title>val=1 int64-&gt;Subtensor{int64}</title>\n",
"<path d=\"M860.642,-283.734C858.414,-267.462 852.531,-243.606 837,-230 823.252,-217.956 783.956,-209.391 746.935,-203.749\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"746.978,-200.219 736.577,-202.235 745.965,-207.145 746.978,-200.219\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"877\" y=\"-244.3\">1 int64</text>\n",
"</g>\n",
"<!-- Subtensor{int64} id=8&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] -->\n",
"<g class=\"edge\" id=\"edge16\"><title>Subtensor{int64} id=8-&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]</title>\n",
"<path d=\"M462,-175.597C462,-163.746 462,-147.817 462,-134.292\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"465.5,-134.084 462,-124.084 458.5,-134.084 465.5,-134.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"545.5\" y=\"-146.3\">1 TensorType(float64, scalar)</text>\n",
"</g>\n",
"<!-- val=0 int64 -->\n",
"<g class=\"node\" id=\"node14\"><title>val=0 int64</title>\n",
"<polygon fill=\"limegreen\" points=\"455.25,-320 374.75,-320 374.75,-284 455.25,-284 455.25,-320\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"415\" y=\"-298.3\">val=0 int64</text>\n",
"</g>\n",
"<!-- val=0 int64&#45;&gt;Subtensor{int64} id=8 -->\n",
"<g class=\"edge\" id=\"edge14\"><title>val=0 int64-&gt;Subtensor{int64} id=8</title>\n",
"<path d=\"M411.23,-283.946C408.807,-268.911 407.505,-246.84 416,-230 418.201,-225.638 421.228,-221.669 424.688,-218.102\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"427.133,-220.611 432.272,-211.345 422.477,-215.384 427.133,-220.611\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"436\" y=\"-244.3\">1 int64</text>\n",
"</g>\n",
"<!-- TensorType(float64, scalar) id=13 -->\n",
"<g class=\"node\" id=\"node16\"><title>TensorType(float64, scalar) id=13</title>\n",
"<polygon fill=\"dodgerblue\" points=\"566,-36 358,-36 358,-0 566,-0 566,-36\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"462\" y=\"-14.3\">TensorType(float64, scalar) id=13</text>\n",
"</g>\n",
"<!-- Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]&#45;&gt;TensorType(float64, scalar) id=13 -->\n",
"<g class=\"edge\" id=\"edge18\"><title>Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]-&gt;TensorType(float64, scalar) id=13</title>\n",
"<path d=\"M462,-87.5966C462,-75.7459 462,-59.8169 462,-46.2917\" fill=\"none\" stroke=\"black\"/>\n",
"<polygon fill=\"black\" points=\"465.5,-46.084 462,-36.084 458.5,-46.084 465.5,-46.084\" stroke=\"black\"/>\n",
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"540\" y=\"-58.3\">TensorType(float64, scalar)</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"SVG(g.create_svg())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
import numpy as np
import logging
import re
import os.path as pt
try:
import pydot as pd
......@@ -84,17 +85,19 @@ class GraphFormatter(object):
self.all_strings = set()
self.apply_name_cache = {}
profile = None
if isinstance(fct, Function):
mode = fct.maker.mode
profile = getattr(fct, "profile", None)
if (not isinstance(mode, ProfileMode) or
fct not in mode.profile_stats):
fct not in mode.profile_stats):
mode = None
if mode:
profile = mode.profile_stats[fct]
else:
profile = getattr(fct, "profile", None)
outputs = fct.maker.fgraph.outputs
topo = fct.maker.fgraph.toposort()
elif isinstance(fct, gof.FunctionGraph):
mode = None
profile = None
outputs = fct.outputs
topo = fct.toposort()
else:
......@@ -106,8 +109,6 @@ class GraphFormatter(object):
assert all(isinstance(v, gof.Variable) for v in fct)
fct = gof.FunctionGraph(inputs=gof.graph.inputs(fct),
outputs=fct)
mode = None
profile = None
outputs = fct.outputs
topo = fct.toposort()
if not pydot_imported:
......@@ -125,29 +126,40 @@ class GraphFormatter(object):
if i.update is not None:
self.input_update[outputs.pop()] = i
apply_shape = 'ellipse'
var_shape = 'box'
for node in topo:
nparams = {}
node_id = self.node_id(node)
astr, aprof = self.apply_name(node, fct, topo, mode, profile)
nparams['name'] = node_id
nparams['label'] = self.apply_label(node)
nparams['profile'] = self.apply_profile(node, profile)
use_color = None
for opName, color in self.colorCodes.items():
if opName in node.op.__class__.__name__:
use_color = color
if use_color:
nparams['style'] = 'filled'
nparams['fillcolor'] = use_color
nparams['type'] = 'colored'
if use_color is None:
pd_node = pd.Node(node_id, label=astr, shape=apply_shape, profile=aprof)
else:
pd_node = pd.Node(node_id, label=astr, style='filled', fillcolor=use_color,
shape=apply_shape, type='colored', profile=aprof)
pd_node = self.dict_to_pdnode(nparams)
graph.add_node(pd_node)
def make_node(_id, label, **kwargs):
t = {k:v for k,v in kwargs.items() if v is not None}
return pd.Node(_id, label=label, **t)
for id, var in enumerate(node.inputs):
var_id = self.node_id(var.owner if var.owner else var)
if var.owner is None:
vparams = {}
vparams['name'] = var_id
vparams['label'] = self.var_label(var)
vparams['dtype'] = str(var.type)
vparams['tag'] = self.var_tag(var)
vparams['style'] = 'filled'
vparams['fillcolor'] = self.node_colors['input']
vparams['shape'] = 'ellipse'
vparams['profile'] = nparams['profile']
pd_var = self.dict_to_pdnode(vparams)
graph.add_node(pd_var)
edge_params = {}
if hasattr(node.op, 'view_map') and id in reduce(list.__add__, node.op.view_map.values(), []):
edge_params['color'] = self.node_colors['output']
......@@ -158,37 +170,32 @@ class GraphFormatter(object):
edge_label = str(var.type)
if len(node.inputs) > 1:
edge_label = str(id) + ' ' + edge_label
var_id = self.node_id(var.owner if var.owner else var)
if var.owner is None:
var_name = self.var_name(var)
n = make_node(var_id, var_name, style='filled',
fillcolor=self.node_colors['input'],
shape=var_shape, profile=aprof)
graph.add_node(n)
graph.add_edge(pd.Edge(var_id, node_id, label=edge_label, **edge_params))
pdedge = pd.Edge(var_id, node_id, label=edge_label,
**edge_params)
graph.add_edge(pdedge)
for id, var in enumerate(node.outputs):
var_id = self.node_id(var)
var_name = self.var_name(var)
edge_label = str(var.type)
if var in outputs:
n = make_node(var_id, var_name, style='filled',
fillcolor=self.node_colors['output'],
shape=var_shape, profile=aprof)
graph.add_node(n)
graph.add_edge(pd.Edge(node_id, var_id, label=edge_label))
elif len(var.clients) == 0:
n = make_node(var_id, var_name, style='filled',
fillcolor=self.node_colors['unused'],
shape=var_shape, profile=aprof)
graph.add_node(n)
graph.add_edge(pd.Edge(node_id, var_id, label=edge_label))
if var in outputs or len(var.clients) == 0:
vparams = {}
vparams['name'] = var_id
vparams['label'] = self.var_label(var)
vparams['dtype'] = str(var.type)
vparams['tag'] = self.var_tag(var)
vparams['style'] = 'filled'
if len(var.clients) == 0:
vparams['fillcolor'] = self.node_colors['unused']
else:
vparams['fillcolor'] = self.node_colors['output']
vparams['shape'] = 'box'
vparams['profile'] = nparams['profile']
pd_var = self.dict_to_pdnode(vparams)
graph.add_node(pd_var)
graph.add_edge(pd.Edge(node_id, var_id, label=str(var.type)))
elif var.name or not self.compact:
graph.add_edge(pd.Edge(node_id, var_id, label=edge_label))
graph.add_edge(pd.Edge(node_id, var_id, label=str(var.type)))
if isinstance(node.op, builders.OpFromGraph):
subgraph = pd.Cluster(node_id)
......@@ -223,7 +230,39 @@ class GraphFormatter(object):
return graph
def dict_to_pdnode(self, d):
e = dict()
for k, v in d.items():
if v is not None:
v = str(v)
v = v.replace('"', '')
e[k] = v
pynode = pd.Node(**e)
return pynode
def var_label(self, var):
if var.name is not None:
return var.name
elif isinstance(var, gof.Constant):
dstr = 'val=' + str(np.asarray(var.data))
if '\n' in dstr:
dstr = dstr[:dstr.index('\n')]
return dstr
elif (var in self.input_update and
self.input_update[var].variable.name is not None):
return self.input_update[var].variable.name + " UPDATE"
else:
return str(var.type)
def var_tag(self, var):
tag = var.tag
if hasattr(tag, 'trace') and len(tag.trace) and len(tag.trace[0]) == 4:
path, line, _, src = tag.trace[0]
path = pt.basename(path)
src = src.encode()
return (path, line, src)
else:
return None
def var_name(self, var):
if var in self.var_str:
......@@ -270,6 +309,19 @@ class GraphFormatter(object):
return varstr
def apply_label(self, node):
name = str(node.op).replace(':', '_')
name = re.sub('^<', '', name)
name = re.sub('>$', '', name)
return name
def apply_profile(self, node, profile):
if not profile:
return None
time = profile.apply_time.get(node, 0)
call_time = profile.fct_call_time
return [time, call_time]
def apply_name(self, node, fct, topo, mode=None, profile=None):
if node in self.apply_name_cache:
return self.apply_name_cache[node]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论