+ added basic scripts to generate runs for an experiment
[qpalma.git] / scripts / ModelSelection.py
1 #!/usr/bin/env python
2 # -*- coding:latin-1 -*-
3
4 import cPickle
5 import os
6 import os.path
7 import time
8
9 import Experiment as Exp
10
11 class Model:
12
13 allInstances = []
14
15 def __init__(self):
16 self.project_root = os.getcwd()
17 self.sampleDir = Configuration.sample_dir
18 self.resultRootDir = Configuration.result_dir
19 self.splits = Configuration.splits
20 self.numSplits = len(self.splits)
21 self.numFeatures = Configuration.numFeatures
22
23 assert os.path.isdir(self.sampleDir), 'Error your sample dir is not valid!!'
24 assert os.path.isdir(self.resultRootDir), 'Error your result root dir is not valid!!'
25
26 #self.possibleCs = [10**d for d in range(-2,4)]
27 self.possibleCs = [1.02]
28 self.possibleAlgos = [
29 #'noRescaling',
30 'marginRescaling'
31 #'slackRescalingWithMarginContraints',
32 #'slackRescalingLinearApprox'
33 ]
34
35 def createInstances(self):
36 os.system('rm -rf *.pickle')
37 os.system('rm -rf config*pickle')
38 instance_counter = 0
39
40 for algo in self.possibleAlgos:
41 for C in self.possibleCs:
42 resultDir = 'new_result_%.2f_%s'%(C,algo)
43 resultDir = os.path.join(self.resultRootDir,resultDir)
44 os.mkdir(resultDir)
45
46 # now iterate over all splits
47 for splitIdx in range(self.numSplits):
48 valIdx = (splitIdx+1)%self.numSplits
49 test = self.splits[splitIdx]
50 valid = self.splits[valIdx]
51 train = []
52 for j in range(self.numSplits):
53 if j == splitIdx or j == valIdx:
54 continue
55 train.extend(self.splits[j])
56
57 os.chdir(self.project_root)
58
59 print train
60 print valid
61 print test
62 train.extend(valid)
63 print train
64
65 configObject = ConfigurationClass( instance_counter, self.numSplits, self.sampleDir,\
66 resultDir, train, test, self.numFeatures, C, algo)
67 currentInstance = LMM(configObject)
68 currentInstance = Subgradient(configObject)
69
70 #print 'instance created, starting to pickle configuration...'
71 fh = open('config_%d.pickle'%instance_counter,'w+')
72 cPickle.dump(configObject,fh)
73 fh.close()
74
75 #print 'starting to pickle algorithm object...'
76 fh = open('lmm_%d.pickle'%instance_counter,'w+')
77 cPickle.dump(currentInstance,fh)
78 fh.close()
79 instance_counter += 1
80
81 self.numInstances = instance_counter
82
83 def doSelection(self):
84 for idx in range(self.numInstances):
85 time.sleep(3)
86 os.system('echo ./resurrect %d | qsub -l h_vmem=1.0G -cwd -j y -N \"model_%d.log\"'%(idx,idx))
87 #os.system('./resurrect %d >out_%d.log 2>err_%d.log &'%(idx,idx,idx))
88
89
90 if __name__ == '__main__':
91 m = Model()
92 m.createInstances()
93 m.doSelection()