annotate deep/crbm/utils.py @ 346:7bc555cc9aab

Ajouté dans set_batches : choix de la classe principale
author Guillaume Sicard <guitch21@gmail.com>
date Mon, 19 Apr 2010 07:09:44 -0400
parents 82dae7c46046
children 64fa85d68923
rev   line source
339
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
1 #!/usr/bin/python
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
2 # coding: utf-8
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
3
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
4 from __future__ import with_statement
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
5
343
82dae7c46046 Last few bugfixes before launching
fsavard
parents: 339
diff changeset
6 import jobman
339
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
7 from jobman import DD
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
8
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
9 from pylearn.io.seriestables import *
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
10 import tables
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
11
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
12
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
13
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
14 # from pylearn codebase
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
15 # useful in __init__(param1, param2, etc.) to save
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
16 # values in self.param1, self.param2... just call
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
17 # update_locals(self, locals())
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
18 def update_locals(obj, dct):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
19 if 'self' in dct:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
20 del dct['self']
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
21 obj.__dict__.update(dct)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
22
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
23 # from a dictionary of possible values for hyperparameters, e.g.
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
24 # hp_values = {'learning_rate':[0.1, 0.01], 'num_layers': [1,2]}
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
25 # create a list of other dictionaries representing all the possible
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
26 # combinations, thus in this example creating:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
27 # [{'learning_rate': 0.1, 'num_layers': 1}, ...]
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
28 # (similarly for combinations (0.1, 2), (0.01, 1), (0.01, 2))
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
29 def produit_cartesien_jobs(val_dict):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
30 job_list = [DD()]
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
31 all_keys = val_dict.keys()
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
32
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
33 for key in all_keys:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
34 possible_values = val_dict[key]
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
35 new_job_list = []
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
36 for val in possible_values:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
37 for job in job_list:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
38 to_insert = job.copy()
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
39 to_insert.update({key: val})
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
40 new_job_list.append(to_insert)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
41 job_list = new_job_list
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
42
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
43 return job_list
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
44
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
45 def jobs_from_reinsert_list(cols, job_vals):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
46 job_list = []
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
47 for vals in job_vals:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
48 job = DD()
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
49 for i, col in enumerate(cols):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
50 job[col] = vals[i]
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
51 job_list.append(job)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
52
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
53 return job_list
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
54
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
55 def save_params(all_params, filename):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
56 import pickle
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
57 with open(filename, 'wb') as f:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
58 values = [p.value for p in all_params]
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
59
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
60 # -1 for HIGHEST_PROTOCOL
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
61 pickle.dump(values, f, -1)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
62
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
63 # Perform insertion into the Postgre DB based on combination
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
64 # of hyperparameter values above
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
65 # (see comment for produit_cartesien_jobs() to know how it works)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
66 def jobman_insert_job_vals(job_db, experiment_path, job_vals):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
67 jobs = produit_cartesien_jobs(job_vals)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
68
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
69 db = jobman.sql.db(job_db)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
70 for job in jobs:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
71 job.update({jobman.sql.EXPERIMENT: experiment_path})
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
72 jobman.sql.insert_dict(job, db)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
73
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
74 def jobman_insert_specific_jobs(job_db, experiment_path,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
75 insert_cols, insert_vals):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
76 jobs = jobs_from_reinsert_list(insert_cols, insert_vals)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
77
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
78 db = jobman.sql.db(job_db)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
79 for job in jobs:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
80 job.update({jobman.sql.EXPERIMENT: experiment_path})
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
81 jobman.sql.insert_dict(job, db)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
82
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
83 # Just a shortcut for a common case where we need a few
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
84 # related Error (float) series
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
85 def get_accumulator_series_array( \
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
86 hdf5_file, group_name, series_names,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
87 reduce_every,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
88 index_names=('epoch','minibatch'),
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
89 stdout_too=True,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
90 skip_hdf5_append=False):
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
91 all_series = []
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
92
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
93 new_group = hdf5_file.createGroup('/', group_name)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
94
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
95 other_targets = []
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
96 if stdout_too:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
97 other_targets = [StdoutAppendTarget()]
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
98
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
99 for sn in series_names:
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
100 series_base = \
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
101 ErrorSeries(error_name=sn,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
102 table_name=sn,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
103 hdf5_file=hdf5_file,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
104 hdf5_group=new_group._v_pathname,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
105 index_names=index_names,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
106 other_targets=other_targets,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
107 skip_hdf5_append=skip_hdf5_append)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
108
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
109 all_series.append( \
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
110 AccumulatorSeriesWrapper( \
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
111 base_series=series_base,
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
112 reduce_every=reduce_every))
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
113
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
114 ret_wrapper = SeriesArrayWrapper(all_series)
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
115
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
116 return ret_wrapper
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
117
ffbf0e41bcee Aded code to run experiment on cluster, separate configuration from other machinery. Not tested yet.
fsavard
parents:
diff changeset
118