This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
# model parameters | |
x = tf.placeholder(tf.float32, [None, 784]) | |
W = tf.Variable(tf.zeros([784, 10])) | |
b = tf.Variable(tf.zeros([10])) | |
# model definition | |
y = tf.nn.softmax(tf.matmul(x, W) + b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<meta charset='utf-8'> | |
<style> | |
body { | |
background: rgb(200,200,200); | |
} | |
svg { | |
margin: auto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<meta charset='utf-8'> | |
<style> | |
body { | |
background: rgb(200,200,200); | |
} | |
svg { | |
margin: auto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<meta charset='utf-8'> | |
<style> | |
body { | |
background: rgb(200,200,200); | |
} | |
svg { | |
margin: auto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_erdos(n = 1000, p.or.m = (1:100/100)^3, wh = c(500, 1000, 2000, 4000, 8000), file = 'seg_mc_test.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Measuers execution times for given combinations of n, p.or.m and wh (image size) | |
test_erdos <- | |
function(n, p.or.m, wh, file) { | |
res = data.frame(game = 0, nodes = 0, edges = 0, side.px = 0, igraph = 0, seg = 0, seg.mc = 0, composite = 0)[-1, ] | |
for (i in n) { | |
for (j in p.or.m) { | |
g = erdos.renyi.game(n = i, p.or.m = j) | |
for (px in wh) { | |
cTest = test_times(g, px, px) | |
res = rbind(res, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fire all three functions on an igraph object and get the execution times: | |
test_times <- | |
function(g, width, height) { | |
return(list( | |
tig = system.time(plot_igraph(g, file = 'igraph.png', width = width, height = height)), | |
tse = system.time(png_segments(g, file = 'segments.png', width = width, height = height)), | |
tmc = system.time(plot_segments_mc(g, file = 'segments_mc.png', width = width, height = height)), | |
imt = as.numeric(.imTime) | |
)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wrappers: include opening and closing of graphical device; | |
plot_igraph <- | |
function(g, file, width, height) { | |
png(file, width = width, height = width) | |
plot(g, vertex.size = 3, vertex.color = 'black', vertex.frame.color = NA, | |
vertex.label = NA, edge.arrow.mode = 0, edge.color = rgb(0,0,0,.2)) | |
dev.off() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Invokes imagemagick to merge png files and cleans up tmp files produced by plot_segments_mc: | |
compose_clean <- | |
function(file, mc.cores) { | |
t0 = Sys.time() | |
for (i in mc.cores:1) { | |
system(ps('composite mcp-tmp-', i, '.png mcp-tmp-', i - 1, '.png mcp-tmp-', i - 1, '.png')) | |
} | |
# composite execution time; catched by a testing script | |
.imTime <<- Sys.time() - t0 | |
print(.imTime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Groups indices of a list or vector into n (almost) equal chunks: | |
iTable <- | |
function (x, n) | |
{ | |
x = seq_along(x) | |
i = floor(seq(from = x[1], to = x[length(x)], length.out = n + | |
1)) | |
res = data.frame(from = i[1:(length(i) - 1)], to = i[2:length(i)]) | |
res$from[2:nrow(res)] = res$from[2:nrow(res)] + 1 | |
return(res) |
NewerOlder