Skip to content

Instantly share code, notes, and snippets.

View skaae's full-sized avatar

Søren Kaae Sønderby skaae

View GitHub Profile
from __future__ import print_function
import gzip
import itertools
import pickle
import os
import sys
PY2 = sys.version_info[0] == 2
from __future__ import print_function
import gzip
import itertools
import pickle
import os
import sys
PY2 = sys.version_info[0] == 2
import numpy as np
import theano
import theano.tensor as T
from theano import ifelse
from .. import init
from .. import nonlinearities
from .base import Layer
@skaae
skaae / adam.py
Created February 26, 2015 14:53
def adam(loss, all_params, learning_rate=0.0002, beta1=0.1, beta2=0.001,
epsilon=1e-8, gamma=1-1e-7):
"""
ADAM update rules
Default values are taken from [Kingma2014]
References:
[Kingma2014] Kingma, Diederik, and Jimmy Ba.
"Adam: A Method for Stochastic Optimization."
arXiv preprint arXiv:1412.6980 (2014).
def adam(loss, all_params, learning_rate=0.001, b1=0.9, b2=0.999, e=1e-8,
gamma=1-1e-8):
"""
ADAM update rules
Default values are taken from [Kingma2014]
References:
[Kingma2014] Kingma, Diederik, and Jimmy Ba.
"Adam: A Method for Stochastic Optimization."
arXiv preprint arXiv:1412.6980 (2014).
def adam(loss, all_params, learning_rate=0.001, b1=0.9, b2=0.999, e=1e-8,
gamma=1-1e-8):
"""
ADAM update rules
Default values are taken from [Kingma2014]
References:
[Kingma2014] Kingma, Diederik, and Jimmy Ba.
"Adam: A Method for Stochastic Optimization."
arXiv preprint arXiv:1412.6980 (2014).
--[[
LSTM cell. Modified from
https://github.com/oxford-cs-ml-2015/practical6/blob/master/LSTM.lua
--]]
local LSTM = {}
-- Creates one timestep of one LSTM
function LSTM.lstm(opt)
local x = nn.Identity()()
import numpy as np
class ConfusionMatrix:
"""
Simple confusion matrix class
row is the true class, column is the predicted class
"""
def __init__(self, n_classes, class_names=None):
self.n_classes = n_classes
if class_names is None:
self.class_names = map(str, range(n_classes))

lasagne.updates

lasagne.updates

The update functions implement different methods to control the learning rate for use with stochastic gradient descent.

Update functions take a loss expression or a list of gradient expressions and a list of parameters as input and return an ordered dictionary of updates:

def get_output_for(self, input, mask=None, **kwargs):
"""
Compute this layer's output function given a symbolic input variable
Parameters
----------
input : theano.TensorType
Symbolic input variable.
mask : theano.TensorType
Theano variable denoting whether each time step in each