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 scipy.io | |
import lasagne | |
import theano | |
import theano.tensor as T | |
import numpy as np | |
import time | |
import logging | |
logger = logging.getLogger('') |
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
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 |
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
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 |
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
--[[ 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 |
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 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 |
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
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###### | |
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
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) |
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
# 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 |
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
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 |
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
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: |