ometah-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oMetah-devel] ometah/experiment interface.py metahtest.py


From: Jean-Philippe Aumasson
Subject: [oMetah-devel] ometah/experiment interface.py metahtest.py
Date: Mon, 13 Jun 2005 06:08:41 -0400

CVSROOT:        /cvsroot/ometah
Module name:    ometah
Branch:         
Changes by:     Jean-Philippe Aumasson <address@hidden> 05/06/13 10:08:41

Modified files:
        experiment     : interface.py metahtest.py 

Log message:
        * experimental function for CEC tests

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/experiment/interface.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/experiment/metahtest.py.diff?tr1=1.17&tr2=1.18&r1=text&r2=text

Patches:
Index: ometah/experiment/interface.py
diff -u ometah/experiment/interface.py:1.5 ometah/experiment/interface.py:1.6
--- ometah/experiment/interface.py:1.5  Mon Jun 13 08:34:03 2005
+++ ometah/experiment/interface.py      Mon Jun 13 10:08:41 2005
@@ -62,7 +62,6 @@
         """ plot distribution of points
         plist = list of Point objects
         breaks = number of breaks in the histogram """
-        # TODO : distrib pour une itération donnée...
         vlist = []
         vlist = [x.value for x in plist]
         r.hist(vlist, breaks, col='green', main='Distribution', xlab='Values', 
ylab='Frequency')
@@ -109,18 +108,21 @@
             sdlist.append(r.sd(i))
         r.plot(sdlist, col='blue', type='o', main='Standard deviations', 
xlab='Iteration', ylab='Std')
         
-    def log(self, string):
+    def log(self, astring):
         """ write log of current job in a *.log file with date,
         pb name, output files... """    
         if self.LOG_ON:
             logf = "%s/%s" % (self.__path, self.__logfile)
             fd = open(logf, 'a')
-            fd.write(string)
+            fd.write(astring)
             fd.close()
     
     def setLog(self, boolean):
         """ turn the log on or off """
-        self.LOG_ON = boolean        
+        self.LOG_ON = boolean
+
+    def setLogFileName(self, astring):
+        self.__logfile = astring
     
     def setPostscriptOutput(self, filename="default"):
         """  set a postscript output file """
@@ -136,7 +138,7 @@
             s = "%s.png" % (self.__defaultFileName)
         else:
             s = "%s.png" % (filename)         
-        r.bitmap(s, res=150) # ???????  SEGFAULT ????????
+        r.bitmap(s, res=150)
        
     def datedFileName(self, name, extension):
         """ return a string of toda
@@ -159,7 +161,7 @@
     def getPath(self):
         return self.__path
 
-    def copyToDisk(self, rfd, filename=""):
+    def copyToDisk(self, rfd, filename="xml"):
         """ copy the file open with fd to a new file on disk
         used to cp XML output on disk """
         xfile = "%s/%s.xml" % (self.__path, filename)
@@ -174,6 +176,16 @@
         wfd.close()
         return xfile
 
+    def rmDiskCopy(self, filename="xml"):
+        """ remove XML copy on disk """
+        path = "%s/%s.xml" % (self.__path, filename)
+        try: # if ls fail, the wrong file name, exit
+            os.listdir(path)
+        except:
+            self.log('ERROR : cannot remove disk copy of XML 
[Interface.rmDiskCopy]\n')
+            return
+        os.remove(path)
+
     def setTemp(self, path):
         """ set the path to the temporary directory """
         self.__temp = path
@@ -194,6 +206,16 @@
 
     def getPoints(self):
         return self.__points
+
+    def getOptimum(self):
+        """ returns the Point object which has the smallest value,
+        from __points list """
+        optim = self.__points[0]
+        for point in self.__points:
+            if point.value < optim:
+                optim = point
+        return optim
+            
         
 
     
Index: ometah/experiment/metahtest.py
diff -u ometah/experiment/metahtest.py:1.17 ometah/experiment/metahtest.py:1.18
--- ometah/experiment/metahtest.py:1.17 Mon Jun 13 08:34:04 2005
+++ ometah/experiment/metahtest.py      Mon Jun 13 10:08:41 2005
@@ -44,31 +44,10 @@
 D print execution time in log
 
 W Interface pour N runs, en plottant le nécessaire à chaque fois...
--> 25 runs de N = (max itérations), N = 10^3 | 10^4 | 10^5
--> nb dimension : 10 | 30 | 50
-stopping test (% précision) : where ? itsMeta or ometah.cpp ??
-same precision for all algos ?
-
-
-plottage de distribution : distrib pour chaque iteration, et pas pour 
l'ensemble...superposition des distributions ?
--> distrib pour optima(s) ?
-=> for each iteration, only keep best value (minimal)
-
-'runs' multiples, sauvegarder chaque optimum obtenu
--> trier 25 runs !
-values kept :
-1 (best), 7, 13 (median), 19, 25 (worst)
-+ mean & std for the 25 runs ( ~ sum_values / 25 )
-
-Termination error value : 1O^-8
 
 
 plottages solutions si plusieurs dimensions ?
 
-parse error when no description (ou no autre chose...)
-
-search only in the bounds => initialization in bounds ??
-(pr l'instant, bounds = [0, 1] pr tt pb)
 
 13/06/05
 
@@ -80,13 +59,21 @@
 
 D Ne pas lancer le parse & plott si erreur / usage en sortie
 
-Interface pour les 25 runs CEC-like
+W Interface pour les 25 runs CEC-like
+-> 25 runs de N = (max itérations), N = 10^3 | 10^4 | 10^5
+-> nb dimension : 10 | 30 | 50
+
+modulariser...parser à part ? main ?
 
 Distribution des optimums de chaque itération
 
 Critère d'arrêt (précision ou nbre d'itérations)
 
 
+paramètres spéciaux pour metahtest.py ?
+-> syntaxe du type :
+metahtest.py [options metahtest] -M [ options ometah ]
+
 
 /----
 
@@ -129,6 +116,8 @@
 __HIST_BREAKS = 20
 # name of the xml output file
 __OMETAH_OUTPUT = 'ometah_output'
+# log file name for CEC tests
+__TESTS_LOG_NAME = 'metah_CEC_tests.log'
 # temp directory to save files before final directory created
 __TEMP_DIR = "."
 
@@ -390,17 +379,50 @@
     return intfc
 
 
+def initTests(argv, index, logfile):
+    """ same as init(), but modified for CEC-like tests :
+    - do not create a special directory => setPath('./')
+    - set special log filename
+    - write XML with a special name containing the run index
+    - only one log file for all runs, don't move it after the setPath
+    see init() for comments """
+    import interface
+    intfc = interface.Interface(argv)
+    intfc.setLog(1)
+    intfc.setPath(".")
+    intfc.setTemp(".")
+    intfc.setLogFileName(logfile)
+    slog = "\n[Starting run %i at %s ]\n" % \
+           (index, time.ctime())
+    intfc.log(slog)
+    fd = intfc.getXmlFromExecOmetah(__OMETAH_PATH)
+    intfc.log('ometah execution ... OK\n')
+    xmlName = "%i_%s" % (index, __OMETAH_OUTPUT)
+    fileOut = intfc.copyToDisk(fd, filename=xmlName)
+    fd.close()
+    fd = open(fileOut, 'r')
+    if not 'xml-version="1.0"' in fd.readline():
+        intfc.log('ERROR : ometah failed to create XML\n')
+        print 'ERROR : see log file for details\n'
+        sys.exit()
+    parser = XMLParser(fd, intfc)
+    parser.readXml()
+    fd.close()
+    intfc.log('parsing XML : readXML() ... OK\n')
+    intfc.setPoints(parser.getPoints())
+    intfc.log('getting points list : getPoints() ...  OK\n')
+    header = parser.getHeader()
+    intfc.log(header.toString())
+    title = header.getTitle()
+    # don't move log nor xml
+    return intfc
+              
+    
 
 def plotSingleRun(intfc):
     """ make plottings for the given interface """
     points = intfc.getPoints()
-    
-    intfc.setBitmapOutput(filename = 'valuesDistribHist')    
-    intfc.plotValuesIterationsDistribHist(points, __HIST_BREAKS)    
-    r.dev_off()
-    intfc.log('outputing results : plotValuesIterationsDistribHist(...)  ...  
OK\n')
-    
-    
+            
     # plotValues for each point
     intfc.setBitmapOutput(filename = intfc.datedFileName('values', '.png'))    
     intfc.plotValuesIterationsGraph(points, 1)
@@ -428,7 +450,7 @@
     
 
 
-def runSingle(argv):
+def runSingleOnce(argv):
     """ run once and make plottings for a single calcul """
     import time
     t = time.time()
@@ -443,20 +465,16 @@
     slog = "\n[ End at " + time.ctime() + " ] \n"
     interf.log(slog)
 
-def runMulti(argvs, n):
-    """ make n runs for the given pb & algo,
-    keeping values and solutions for each run  """
-    # TODO : give a list of argvs and loop over the list    
+def runArgvList(argvs):
+    """ argvs is a list of command line arguments,
+    we run and plot for each one """
+    # NOT USED FOR THE MOMENT
     import time
 
-    points = []
-    ## BOF...use Point object !! => add Err attribute in Point
-    
     for arg in argvs:
         t = time.time()
         interf = init(arg)
-        #plotMultiRun(interf)
-        # for r.bitmap's segfault : move all png and ps files to our working 
directory
+        plotSingleRun(interf)
         cmd = 'mv *.png *.ps %s &> /dev/null' % (interf.getPath())
         os.system(cmd)        
         slog = "\nTotal time : %f\n" %  ( time.time()-t )
@@ -464,7 +482,30 @@
         slog = "\n[ End at " + time.ctime() + " ] \n"
         interf.log(slog)
 
-
+def runTestsCEC(argv):
+    """ run argv N times and plot the results
+    used for CEC-like tests """
+    N = 25 # as in CEC's tests...
+
+    # list of the N optimas, have to sort it after...
+    optima = []
+
+    # PB: don't create N times the same directory
+    # => special interface ?
+    for i in range(N):
+        intf = initTests(argv, i, __TESTS_LOG_NAME)
+        print "optimum for run %i : %f" % \
+              (i, intf.getOptimum().value)
+    # once N runs done, create a directory to put the log and R outputs
+
+    # TODO : rename to pb+algo ...
+    dir = 'TESTS'
+    os.mkdir(dir)
+    cmd = "mv %s %s" % (__TESTS_LOG_NAME, dir)
+    os.system(cmd)
+    cmd = "mv %s %s" % ("*xml" , dir)
+    os.system(cmd)
+        
 
 #######################################################
 # MAIN
@@ -474,9 +515,10 @@
 def main():
     """ main() """
 
-    import sys
-    # runMulti([sys.argv], 1)
-    runSingle(sys.argv)
+    import sys    
+    #runArgvList([sys.argv])
+    #runSingleOnce(sys.argv)
+    runTestsCEC(sys.argv)
     
 if __name__ == '__main__':
     main()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]