Skip to content

Instantly share code, notes, and snippets.

View skaae's full-sized avatar

Søren Kaae Sønderby skaae

View GitHub Profile
import scipy.io
import lasagne
import theano
import theano.tensor as T
import numpy as np
import time
import logging
logger = logging.getLogger('')
class ElemwiseMergeLayer(MergeLayer):
"""
This layer performs an elementwise merge of its input layers.
It requires all input layers to have the same output shape.
Parameters
-----------
incomings : a list of :class:`Layer` instances or tuples
the layers feeding into this layer, or expected input shapes,
with all incoming shapes being equal
Function profiling
==================
Message: /home/soren/Documents/experiments/TRANSFORMER_NET/grutranstest.py:271
Time in 5 calls to Function.__call__: 1.034791e+01s
Time in Function.fn.__call__: 1.034693e+01s (99.991%)
Time in thunks: 1.022032e+01s (98.767%)
Total compile time: 4.257923e+01s
Number of Apply nodes: 1224
Theano Optimizer time: 1.321189e+01s
Theano validate time: 8.471053e-01s
@skaae
skaae / MyConfusionMatrix.Lua
Created August 8, 2015 16:19
confusion matrix for torch
--[[ A Confusion Matrix class
Example:
conf = optim.ConfusionMatrix( {'cat','dog','person'} ) -- new matrix
conf:zero() -- reset matrix
for i = 1,N do
conf:add( neuralnet:forward(sample), label ) -- accumulate errors
end
print(conf) -- print matrix
import numpy as np
import theano
import theano.tensor as T
import lasagne.nonlinearities as nonlinearities
import lasagne.init as init
from lasagne.utils import unroll_scan
from lasagne.layers import *
import lasagne.layers.helper as helper
@skaae
skaae / ex5.py
Created September 23, 2015 07:59
with open("/home/lpp/.bashrc", 'r') as f:
lines = f.readlines()
with open('junk.txt', 'w') as f:
f.write("".join(lines[1:5]
####### OR######
class GruDenseLayer(lasagne.layers.Layer):
def __init__(self, incoming, num_units,
b_resetgate=None,
b_updategate=None,
b_hidden_update=None,
W_resetgate=init.GlorotUniform(),
W_updategate=init.GlorotUniform(),
W_hidden_update=init.GlorotUniform(),
**kwargs):
super(GruDenseLayer, self).__init__(incoming, **kwargs)
# Initialize column sums
column_sums = [0., 0.]
# Iterate over all rows
for row in row_list:
# For each of the two column values, add to the corresponding sum
column_sums[0] += row[0]
column_sums[1] += row[1]
# Calculate the average by dividing by the length
def read_fasta(fasta_filename):
'''Function to parse a fasta sequence file'''
# Initialize dictionary
fasta_dict = {}
# Open file and iterate over lines
for line in open(fasta_filename):
# Remove newline and other whitespace from end of line
def find_prot(fasta_dict, protein_name):
'''Function to find protein in fasta_dictionary'''
# Check if fasta_dict contains the protein name key
if protein_name in fasta_dict:
# Return biological sequence
return fasta_dict[protein_name]
else: