annotate deep/stacked_dae/aistats_review/m_mlp_ift.py @ 621:e162e75ac5c6

merge
author Yoshua Bengio <bengioy@iro.umontreal.ca>
date Sun, 09 Jan 2011 21:33:55 -0500
parents 820764689d2f
children
rev   line source
617
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
1 import pdb,bricks.costs,datetime,os,theano,sys
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
2 from bricks.experiments import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
3 from bricks.networks import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
4 from bricks import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
5 from datasets import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
6 from bricks.optimizer import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
7 from monitor.exp_monitoring import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
8
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
9 #from monitor.series import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
10 import numpy
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
11 #import jobman,jobman.sql,pylearn.version
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
12 #from jobman import DD
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
13 #from utils.JobmanHandling import *
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
14
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
15 class MnistTSdaeExperiment(ExperimentObject):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
16 # Todo : Write down the interface
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
17
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
18 def _init_dataset(self):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
19 self.dataset_list = [ PNIST07(), nist_all() ]
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
20 self.dataset = self.dataset_list[0]
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
21
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
22
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
23 def _init_outputs(self):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
24 self.ds_output = { 'Pnist_Train' : self.dataset_list[0].train,
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
25 'Pnist_Valid' : self.dataset_list[0].valid,
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
26 'Pnist_Test' : self.dataset_list[0].test,
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
27 'nist_Train' : self.dataset_list[1].train,
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
28 'nist_Valid' : self.dataset_list[1].valid,
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
29 'nist_Test' : self.dataset_list[1].test}
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
30
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
31 self.outputs = { 'CC' : costs.classification_error(self.network.layers[-1][0].out_dict['argmax_softmax_output'],self.network.in_dict['pred']) }
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
32 #'L1' : costs.L1(self.network.layers[0][0].out_dict['sigmoid_output']) }
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
33 #'LL' : costs.negative_ll(self.network.layers[-1][0].out_dict['softmax_output'],self.network.in_dict['pred']) }
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
34
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
35
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
36
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
37 def _init_network(self):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
38 """ Choose wich network to initialize """
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
39 #x,y = self.dataset.train(1).next()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
40 n_i = 1024
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
41 n_o = 62
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
42 numpy.random.seed(self.hp['seed'])
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
43 self.network = MLPNetwork(n_i,n_o,size=self.hp['size'])
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
44 default.load_pickled_network(self.network,'best_params/1/')
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
45
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
46 def _init_costs_params(self):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
47 #finetuning
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
48 self.costs = [ [costs.negative_ll(self.network.layers[-1][0].out_dict['softmax_output'],self.network.in_dict['pred'])] ]
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
49 self.params = [ [self.network.get_all_params(),self.network.get_all_params()] ]
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
50
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
51
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
52 def _init_monitor(self):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
53 self.monitor = monitor(self.outputs,self.ds_output,self.network,self.sub_paths,save_criterion='Pnist_Valid')
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
54
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
55 def startexp(self):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
56 print self.info()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
57 for j,optimizer in enumerate(self.optimizers):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
58 print 'Optim', '#'+str(j+1)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
59 sys.stdout.flush()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
60 for i in range(self.hp['ft_ep']):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
61 optimizer.tune(self.dataset.train,self.hp['bs'])
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
62 print repr(i).rjust(3),self.monitor.get_str_output()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
63 sys.stdout.flush()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
64
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
65
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
66 def run(self):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
67 self.startexp()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
68 self.monitor.dump()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
69 return True
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
70
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
71 def jobman_entrypoint(state, channel):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
72 import jobman,jobman.sql,pylearn.version
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
73 from jobman import DD
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
74 from utils.JobmanHandling import JobHandling,jobman_insert,cartesian_product_jobs
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
75 exp = MnistTSdaeExperiment(state,channel)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
76 return exp.jobhandler.start(state,channel)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
77
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
78 def standalone(state):
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
79 exp = MnistTSdaeExperiment(state)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
80 exp.run()
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
81
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
82
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
83 if __name__ == '__main__':
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
84 HP = { 'lr':[ [ .1] ],
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
85 'ft_ep':[100],
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
86 'bs':[100],
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
87 'size':[ [300],[4000],[5000],[6000],[7000] ],
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
88 'seed':[0]}
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
89
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
90 job_db_path = 'postgres://mullerx:b9f6ed1ee4@gershwin/mullerx_db/m_mlp_ift'
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
91 exp_path = "m_mlp_ift.jobman_entrypoint"
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
92
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
93 args = sys.argv[1:]
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
94
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
95 if len(args) > 0 and args[0] == 'jobman_insert':
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
96 jobman_insert(HP,job_db_path,exp_path)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
97
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
98 elif len(args) > 0 and args[0] == 'jobman_test':
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
99 chanmock = DD({'COMPLETE':0,'save':(lambda:None)})
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
100 dd_hp = cartesian_product_jobs(HP)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
101 print dd_hp[0]
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
102 jobman_entrypoint(dd_hp[0], chanmock)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
103
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
104 elif len(args) > 0 and args[0] == 'standalone':
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
105 hp = { 'lr':[ .1],
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
106 'ft_ep':100,
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
107 'bs':100,
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
108 'size':[ 3000 ],
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
109 'seed':0}
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
110 standalone(hp)
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
111
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
112
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
113 else:
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
114 print "Bad arguments"
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
115
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
116
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
117 #jobman sqlview postgres://mullerx:b9f6ed1ee4@gershwin/mullerx_db/m_mlp_ift m_mlp_ift_view
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
118 #psql -h gershwin -U mullerx -d mullerx_db
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
119 #b9f6ed1ee4
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
120
820764689d2f Experiment to test the performance of shallower networks.
Salah Rifai <salahmeister@gmail.com>
parents:
diff changeset
121 #jobdispatch --condor --env=THEANO_FLAGS=floatX=float32 --repeat_jobs=5 jobman sql -n0 'postgres://mullerx:b9f6ed1ee4@gershwin/mullerx_db/m_mlp_ift' .