Mercurial > pylearn
changeset 696:2f5fa4faf831
merge
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Thu, 14 May 2009 20:01:04 -0400 |
parents | 4c24b2023f32 (current diff) 69947f4e9c0e (diff) |
children | 28da8bb76336 |
files | |
diffstat | 1 files changed, 55 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/pylearn/sandbox/scan_inputs_groups.py Thu May 14 20:00:39 2009 -0400 +++ b/pylearn/sandbox/scan_inputs_groups.py Thu May 14 20:01:04 2009 -0400 @@ -105,10 +105,10 @@ raise NotImplementedError('index superior to weight list length',idx_list) for i in range(len(args[1])): if (args[1][i].shape)[0] != batchsize: - raise NotImplementedError('different batchsize in the inputs list',args[1][i]) + raise NotImplementedError('different batchsize in the inputs list',args[1][i].shape) for i in range(len(args)-2): if (args[2+i].shape)[1] != n_hid: - raise NotImplementedError('different length of hidden in the weights list',args[2+i]) + raise NotImplementedError('different length of hidden in the weights list',args[2+i].shape) for i in range(len(idx_list)): if idx_list[i]>0: @@ -168,10 +168,10 @@ raise NotImplementedError('index superior to weight list length',idx_list) for i in range(len(args[1])): if (args[1][i].shape)[0] != batchsize: - raise NotImplementedError('different batchsize in the inputs list',args[1][i]) + raise NotImplementedError('different batchsize in the inputs list',args[1][i].shape) for i in range(len(args)-3): if (args[2+i].shape)[1] != n_hid: - raise NotImplementedError('different length of hidden in the weights list',args[2+i]) + raise NotImplementedError('different length of hidden in the weights list',args[2+i].shape) zcalc = [False for i in range(len(args)-3)] @@ -234,7 +234,7 @@ raise NotImplementedError('size of index different of inputs list size',idx_list) for i in range(len(args)-3): if (args[3+i].shape)[0] != n_hid: - raise NotImplementedError('different length of hidden in the weights list',args[3+i]) + raise NotImplementedError('different length of hidden in the weights list',args[3+i].shape) zcalc = [False for i in idx_list] z[0] = [None for i in idx_list] @@ -304,7 +304,7 @@ raise NotImplementedError('size of index different of inputs list size',idx_list) for i in range(len(args)-4): if (args[3+i].shape)[0] != n_hid: - raise NotImplementedError('different length of hidden in the weights list',args[3+i]) + raise NotImplementedError('different length of hidden in the weights list',args[3+i].shape) zidx=numpy.zeros((len(idx_list)+1)) @@ -377,7 +377,7 @@ if len(idx_list) != len(inputs_list) : raise NotImplementedError('size of index different of inputs list size',idx_list) - y[0] = [-i if (i>0 and not(self.R.noisify_group_bool(noise_level_group))) else i for i in idx_list] + y[0] = numpy.asarray([-i if (i>0 and not(self.R.noisify_group_bool(noise_level_group))) else i for i in idx_list]) z[0] = [(self.R.noisify_bit(inputs_list[i],noise_level_bit) if y[0][i]>0 else numpy.zeros((inputs_list[i].shape)))\ for i in range(len(inputs_list))] @@ -386,7 +386,7 @@ def __hash__(self): - return hash(ScanNoise)^hash(self.seed)^hash(self.R)^12254 + return hash(ScanNoise)^hash(self.seed)^hash(self.R.rand)^12254 def __str__(self): return "ScanNoise" @@ -500,3 +500,50 @@ def __str__(self): return "ScanBiasDecGrad" + +# Mask construction------------------------------------ +class ScanMask(Op): + """This Op takes an index list (as tensor.ivector) and a list of weigths. + It will construct a list of T.iscalar representing the Mask + to do the correct regularisation on the weigths""" + def __init__(self,encbool=True): + self.encbool = encbool + + def make_node(self, idx_list, weights_list): + idx_list = Checkidx_list(idx_list) + weights_list = Checkweights_list(weights_list) + return Apply(self, [idx_list] + weights_list, [T.iscalar() for i in range(len(weights_list))]) + + def perform(self, node, args, z): + if self.encbool: + idx_list = args[0][args[0]>0] + dim = 1 + else: + idx_list = abs(args[0][args[0] != 0]) + dim = 0 + n_hid = args[1].shape[dim] + + if max(idx_list) >= (len(args)-1)+1 : + raise NotImplementedError('index superior to weights list length',idx_listdec) + for i in range(len(args)-1): + if args[1+i].shape[dim] != n_hid: + raise NotImplementedError('different length of hidden in the encoding weights list',args[1+i].shape) + + for i in range(len(args[1:])): + z[i][0] = numpy.asarray((idx_list == i+1).sum(),dtype='int32') + + def __hash__(self): + return hash(ScanMask)^hash(self.encbool)^11447 + + def grad(self,args,gz): + return [None] * len(args) + + def __str__(self): + if self.encbool: + string = "Enc" + else: + string = "Dec" + return "ScanMask" + string + +scanmaskenc=ScanMask(True) +scanmaskdec=ScanMask(False) \ No newline at end of file