Skip to content

Instantly share code, notes, and snippets.

View standy66's full-sized avatar

Andrew Stepanov standy66

  • Quantum Light Capital
  • London, United Kingdom
View GitHub Profile
channel = new FileInputStream(dbFilePath).getChannel();
ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
try {
while (buffer.remaining() > 0) {
int keySize = buffer.getInt();
byte[] key = new byte[keySize];
buffer.get(key);
int valueSize = buffer.getInt();
byte[] value = new byte[valueSize];
buffer.get(value);
@standy66
standy66 / gen.py
Created January 11, 2016 00:19
Python matrix generator
#! /usr/bin/env python3
import sys
import random
width = int(sys.argv[1])
height = int(sys.argv[2])
for i in range(0, width):
for j in range(0, height):
@standy66
standy66 / mult.py
Created January 11, 2016 00:20
Python matrix multiplier
#! /usr/bin/env python3
import sys
def read_matrix(path):
A = []
with open(path) as f:
content = f.readlines()
for line in content:
idx1, idx2, other = line.split()
with g.as_default():
print([v.name for v in tf.all_variables()])
W = [v for v in tf.all_variables() if v.name == "Conv/weights:0"][0]
W_val = sess.run(W)
fig, axes = plt.subplots(5, 5, figsize=(15, 15))
for i in range(5):
for j in range(5):
axes[i, j].imshow(W_val[:, :, 0, i * 5 + j], interpolation='nearest', cmap='gray')
plt.show()
from agentnet.utils.persistence import save,load
def build_pretrained_spaceinvaders(observation_reshape):
""" a smaller version of DQN pre-trained for ~2 hours on GPU """
assert tuple(observation_reshape.output_shape) == (None, 3, 105, 80)
#main neural network body
conv0 = Conv2DLayer(observation_reshape,16,filter_size=(8,8),stride=(4,4),name='conv0')
conv1 = Conv2DLayer(conv0,32,filter_size=(4,4),stride=(2,2),name='conv1')
dense0 = DenseLayer(conv1,256,name='dense',nonlinearity=lasagne.nonlinearities.tanh)
\documentclass[a4paper,12pt]{article}
\usepackage[T2A]{fontenc}
%\usepackage[utf8]{inputenc} % older versions of ucs package
\usepackage[utf8x]{inputenc} % more recent versions (at least>=2004-17-10)
\usepackage[russian]{babel}
\usepackage{amsmath}
\sloppy % Hyphenation is a problem..
@standy66
standy66 / sawtooth.py
Created July 13, 2017 09:12
Python sawtooth wave generator
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import Audio
from scipy.signal import spectrogram
sample_rate = 8000
t = np.arange(0, 10, 1.0/sample_rate)
x = t % (2 / sample_rate)
plt.figure(figsize=(16, 6), dpi=200)
@standy66
standy66 / pymystem3_example.py
Created August 2, 2017 14:27
pymystem3 example
import sys, re, pymystem3
mystem = pymystem3.Mystem()
def stem(s):
return [(e['text'].strip(), \
e['analysis'][0]['lex'] \
if 'analysis' in e and len(e['analysis']) > 0 else '', \
re.match('^([A-Z]+)', e['analysis'][0]['gr']).group(0) \
if 'analysis' in e and len(e['analysis']) > 0 else '', \
@standy66
standy66 / variable_scope.py
Last active August 20, 2017 18:27
tf variable scope example
with tf.name_scope("subgraph_1"):
with tf.variable_scope(tf.get_variable_scope(), resue=False):
y_1 = output(x_1)
with tf.name_scope("subgraph_2"):
with tf.variable_scope(tf.get_variable_scope(), reuse=True):
y_2 = output(x_2)
"""
Based on example here: https://gist.github.com/awni/56369a90d03953e370f3964c826ed4b0
"""
import numpy as np
import math
import collections
NEG_INF = -float("inf")