Mercurial > pylearn
changeset 778:a985baadf74d
Merge
author | Foo Bar <barfoo@iro.umontreal.ca> |
---|---|
date | Sat, 13 Jun 2009 22:02:13 -0400 |
parents | ba055d419bcf (current diff) 72ce8288a283 (diff) |
children | 2c159439c47c |
files | pylearn/algorithms/sandbox/DAA_inputs_groups.py |
diffstat | 2 files changed, 44 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/pylearn/algorithms/sandbox/DAA_inputs_groups.py Sat Jun 13 10:11:43 2009 -0400 +++ b/pylearn/algorithms/sandbox/DAA_inputs_groups.py Sat Jun 13 22:02:13 2009 -0400 @@ -19,6 +19,7 @@ if type == 'l1': return T.sum(T.abs(param)) if type == 'l2': + return T.sum(param*param)#faster... return T.sum(T.pow(param,2)) raise NotImplementedError('Only l1 and l2 regularization are currently implemented')
--- a/pylearn/sandbox/test_scan_inputs_groups.py Sat Jun 13 10:11:43 2009 -0400 +++ b/pylearn/sandbox/test_scan_inputs_groups.py Sat Jun 13 22:02:13 2009 -0400 @@ -1,6 +1,6 @@ import sys, time, unittest -import numpy +import numpy,time import numpy as N from theano.tests import unittest_tools as utt @@ -14,6 +14,7 @@ utt.seed_rng() def test_vector(self): + print "test_vector" n=100000 v=T.dvector() def t(prob,val,fill): @@ -24,14 +25,17 @@ if prob[i]<0.1: nb_missing+=1 val[i]=N.nan + t=time.time() out=f(val) + print "time %.3fs"%(time.time()-t) for i in range(n): if N.isnan(val[i]): if isinstance(fill,N.ndarray): - assert out[0][i]==fill[i] + assert abs(out[0][i]-fill[i])<1e-6 else: assert out[0][i]==fill else: + assert out[0][i]==val[i] assert out[1][i]==1 prob=N.random.random(n) @@ -45,32 +49,47 @@ #TODO: test fill_with_array! def test_matrix(self): - shp=(100,100) + print "test_matrix" + shp=(100,10) v=T.dmatrix() - op=FillMissing()(v) - fct=function([v],op) + def t(prob,val,fill): + op=FillMissing(fill)(v) + f=function([v],op) + nb_missing=0 + for i in range(shp[0]): + for j in range(shp[1]): + if prob[i,j]<0.1: + nb_missing+=1 + val[i,j]=N.nan + t=time.time() + out=f(val) + print "time %.3fs"%(time.time()-t) + for i in range(shp[0]): + for j in range(shp[1]): + if N.isnan(val[i,j]): + if isinstance(fill,N.ndarray): + assert abs(out[0][i,j]-fill[j])<1e-6 + else: + assert out[0][i,j]==fill + else: + assert out[0][i,j]==val[i,j] + assert out[1][i,j]==1 + + prob=N.random.random(N.prod(shp)).reshape(shp) val=N.random.random(shp) - nb_missing=0 - for i in range(shp[0]): - for j in range(shp[1]): - if prob[i,j]<0.1: - nb_missing+=1 - val[i,j]=N.nan - out=fct(val) - for i in range(shp[0]): - for j in range(shp[1]): - if N.isnan(val[i,j]): - assert out[0][i,j]==0 - assert out[1][i,j]==0 - else: - assert out[1][i,j]==1 - + fill=0 + t(prob,val,fill)#test with fill a constant + + fill=N.random.random(shp[1]) + t(prob,val,fill)#test with fill a vector + #TODO: test fill_with_array! def test_matrix3d(self): - shp=(100,100,100) + print "test_matrix3d" + shp=(10,100,100) v= T.TensorType('float64', (False, False, False))() op=FillMissing()(v) fct=function([v],op) @@ -84,8 +103,9 @@ if prob[i,j,k]<0.1: nb_missing+=1 val[i,j,k]=N.nan - + t=time.time() out=fct(val) + print "time %.3fs"%(time.time()-t) for i in range(shp[0]): for j in range(shp[1]): for k in range(shp[2]): @@ -93,6 +113,7 @@ assert out[0][i,j,k]==0 assert out[1][i,j,k]==0 else: + assert out[0][i,j,k]==val[i,j,k] assert out[1][i,j,k]==1 if __name__ == '__main__':