+ using new parsers now
[qpalma.git] / scripts / ModelSelection.py
index ff4599d..af196e3 100644 (file)
@@ -6,6 +6,7 @@ import os
 import os.path
 import time
 
+from qpalma_main import QPalma
 import Experiment as Exp
 
 class Model:
@@ -13,78 +14,33 @@ class Model:
    allInstances = []
    
    def __init__(self):
-      self.project_root = os.getcwd()
-      self.sampleDir = Configuration.sample_dir
-      self.resultRootDir = Configuration.result_dir
-      self.splits = Configuration.splits
-      self.numSplits = len(self.splits)
-      self.numFeatures = Configuration.numFeatures
-
-      assert os.path.isdir(self.sampleDir), 'Error your sample dir is not valid!!'
-      assert os.path.isdir(self.resultRootDir), 'Error your result root dir is not valid!!'
-
-      #self.possibleCs = [10**d for d in range(-2,4)]
-      self.possibleCs = [1.02]
-      self.possibleAlgos = [
-      #'noRescaling',
-      'marginRescaling'
-      #'slackRescalingWithMarginContraints',
-      #'slackRescalingLinearApprox'
-      ]
+      pass
 
    def createInstances(self):
-      os.system('rm -rf *.pickle')
-      os.system('rm -rf config*pickle')
-      instance_counter = 0
-
-      for algo in self.possibleAlgos:
-         for C in self.possibleCs:
-            resultDir = 'new_result_%.2f_%s'%(C,algo)
-            resultDir = os.path.join(self.resultRootDir,resultDir)
-            os.mkdir(resultDir)
-
-            # now iterate over all splits
-            for splitIdx in range(self.numSplits):
-               valIdx = (splitIdx+1)%self.numSplits
-               test = self.splits[splitIdx]
-               valid = self.splits[valIdx]
-               train = []
-               for j in range(self.numSplits):
-                  if j == splitIdx or j == valIdx:
-                     continue
-                  train.extend(self.splits[j])
-                  
-               os.chdir(self.project_root)
 
-               print train
-               print valid
-               print test
-               train.extend(valid)
-               print train
+      allRuns = Exp.createRuns()
+      
+      for currentRun in allRuns:
+               
+         currentInstance = QPalma(currentRun)
 
-               configObject = ConfigurationClass( instance_counter, self.numSplits, self.sampleDir,\
-               resultDir, train, test, self.numFeatures, C, algo)
-               currentInstance = LMM(configObject)
-               currentInstance = Subgradient(configObject)
+         #print 'instance created, starting to pickle configuration...'
+         name = currentRun['name']
+         instance_fn = '%s.pickle'%name
+         fh = open(instance_fn,'w+')
+         cPickle.dump(currentInstance,fh)
+         fh.close()
 
-               #print 'instance created, starting to pickle configuration...'
-               fh = open('config_%d.pickle'%instance_counter,'w+')
-               cPickle.dump(configObject,fh)
-               fh.close()
-
-               #print 'starting to pickle algorithm object...'
-               fh = open('lmm_%d.pickle'%instance_counter,'w+')
-               cPickle.dump(currentInstance,fh)
-               fh.close()
-               instance_counter += 1 
-
-      self.numInstances = instance_counter
+         self.allInstances.append(instance_fn)
 
    def doSelection(self):
-      for idx in range(self.numInstances):
-         time.sleep(3)
-         os.system('echo ./resurrect %d | qsub -l h_vmem=1.0G -cwd -j y -N \"model_%d.log\"'%(idx,idx))
-         #os.system('./resurrect %d >out_%d.log 2>err_%d.log &'%(idx,idx,idx))
+      for instance in self.allInstances:
+         time.sleep(2)
+         cmd = 'echo ./resurrect %s | qsub -l h_vmem=5.0G -cwd -j y -N \"%s.log\"'%(instance,instance)
+         #print cmd
+         os.system(cmd)
+
+         #os.system('echo "./resurrect %s >out_%s.log 2>err_%s.log &"'%(instance,instance,instance))
 
 
 if __name__ == '__main__':