Skip to content

Instantly share code, notes, and snippets.

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)
@jakosz
jakosz / index.html
Created July 31, 2014 09:42
Draw a straight line using mouse
<!DOCTYPE HTML>
<meta charset='utf-8'>
<style>
body {
background: rgb(200,200,200);
}
svg {
margin: auto;
@jakosz
jakosz / index.html
Last active April 12, 2018 11:58
Context menu for SVG elements
<!DOCTYPE HTML>
<meta charset='utf-8'>
<style>
body {
background: rgb(200,200,200);
}
svg {
margin: auto;
@jakosz
jakosz / index.html
Last active August 29, 2015 14:04
Drag and drop SVG elements
<!DOCTYPE HTML>
<meta charset='utf-8'>
<style>
body {
background: rgb(200,200,200);
}
svg {
margin: auto;
test_erdos(n = 1000, p.or.m = (1:100/100)^3, wh = c(500, 1000, 2000, 4000, 8000), file = 'seg_mc_test.csv')
# 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,
# 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)
))
}
# 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()
}
# 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)
# 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)