From 7845ba50c7ac4efe55a8d81f1daed65d5e440d43 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 10 Sep 2010 15:48:16 +0200 Subject: [PATCH] + test_cov_parameters.py: script to execute the estimator testor (t-EstimatorNormalMulti) in using all combinaison parameters values for 2-D cov-matrix --- application/eda_sa/gplot.py | 91 ++++++++++++++++++++++++++----- test/t-doEstimatorNormalMulti.cpp | 58 ++++++++++++-------- test/test_cov_parameters.py | 17 ++++++ 3 files changed, 130 insertions(+), 36 deletions(-) create mode 100755 test/test_cov_parameters.py diff --git a/application/eda_sa/gplot.py b/application/eda_sa/gplot.py index 2d012e162..55e95cb01 100755 --- a/application/eda_sa/gplot.py +++ b/application/eda_sa/gplot.py @@ -44,7 +44,11 @@ def parser(parser=optparse.OptionParser()): parser.add_option('-d', '--dimension', help='give a dimension size', default=2) parser.add_option('-m', '--multiplot', action="store_true", help='plot all graphics in one window', dest="multiplot", default=True) parser.add_option('-p', '--plot', action="store_false", help='plot graphics separetly, one by window', dest="multiplot") - parser.add_option('-w', '--windowid', help='give the window id you want to display, 0 means we display all ones', default=0) + parser.add_option('-w', '--windowid', help='give the window id you want to display, 0 means we display all ones, this option should be combined with -p', default=0) + parser.add_option('-G', '--graphicsdirectory', help='give a directory name for graphics, this option should be combined with -u', default='plot') + parser.add_option('-g', '--graphicsprefixname', help='give a prefix name for graphics, this option should be combined with -u', default='plot') + parser.add_option('-t', '--terminal', action="store_true", help='display graphics on gnuplot windows', dest="terminal", default=True) + parser.add_option('-u', '--png', action="store_false", help='display graphics on png files', dest="terminal") options, args = parser.parse_args() @@ -95,10 +99,26 @@ def getSortedFiles(path): filelist = options.files.split(',') + checkFileErrors(path, filelist) + return filelist +def checkFileErrors(path, filelist): + for filename in filelist: + for line in open('%s/%s' % (path, filename)): + if '-nan' in line: + logging.warning("checkFileErrors: %s/%s file contains bad value, it is going to be skipped" % (path, filename)) + filelist.remove(filename) + break + def plotXPointYFitness(path, fields='3:1', state=None, g=None): - if g == None: g = Gnuplot.Gnuplot() + if g == None: + g = Gnuplot.Gnuplot() + + if not options.terminal: + g('set terminal png') + g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXPointYFitness')) + if state != None: state.append(g) g.title('Fitness observation') @@ -114,12 +134,19 @@ def plotXPointYFitness(path, fields='3:1', state=None, g=None): ) ) - g.plot(*files) + if len(files) > 0: + g.plot(*files) return g def plotXYPointZFitness(path, fields='4:3:1', state=None, g=None): - if g == None: g = Gnuplot.Gnuplot() + if g == None: + g = Gnuplot.Gnuplot() + + if not options.terminal: + g('set terminal png') + g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXYPointZFitness')) + if state != None: state.append(g) g.title('Fitness observation in 3-D') @@ -136,12 +163,19 @@ def plotXYPointZFitness(path, fields='4:3:1', state=None, g=None): ) ) - g.splot(*files) + if len(files) > 0: + g.splot(*files) return g def plotXYPoint(path, fields='3:4', state=None, g=None): - if g == None: g = Gnuplot.Gnuplot() + if g == None: + g = Gnuplot.Gnuplot() + + if not options.terminal: + g('set terminal png') + g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXYPoint')) + if state != None: state.append(g) g.title('Points observation in 2-D') @@ -157,12 +191,19 @@ def plotXYPoint(path, fields='3:4', state=None, g=None): ) ) - g.plot(*files) + if len(files) > 0: + g.plot(*files) return g def plotXYZPoint(path, fields='3:4:5', state=None, g=None): - if g == None: g = Gnuplot.Gnuplot() + if g == None: + g = Gnuplot.Gnuplot() + + if not options.terminal: + g('set terminal png') + g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXYZPoint')) + if state != None: state.append(g) g.title('Points observation in 3-D') @@ -179,12 +220,19 @@ def plotXYZPoint(path, fields='3:4:5', state=None, g=None): ) ) - g.splot(*files) + if len(files) > 0: + g.splot(*files) return g def plotParams(path, field='1', state=None, g=None): - if g == None: g = Gnuplot.Gnuplot() + if g == None: + g = Gnuplot.Gnuplot() + + if not options.terminal: + g('set terminal png') + g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'plotXYZPoint')) + if state != None: state.append(g) g.title('Hyper-volume comparaison through all dimensions') @@ -197,7 +245,13 @@ def plotParams(path, field='1', state=None, g=None): return g def plot2DRectFromFiles(path, state=None, g=None, plot=True): - if g == None: g = Gnuplot.Gnuplot() + if g == None: + g = Gnuplot.Gnuplot() + + if not options.terminal: + g('set terminal png') + g('set output \'%s_%s.png\'' % (options.graphicsprefixname, 'plot2DRectFromFiles')) + if state != None: state.append(g) g.title('Rectangle drawing observation') @@ -255,9 +309,19 @@ def main(): w = int(options.windowid) r = options.respop + if not options.terminal: + try: + os.mkdir(options.graphicsdirectory) + except OSError: + pass + if options.multiplot: g = Gnuplot.Gnuplot() + if not options.terminal: + g('set terminal png') + g('set output \'%s/%s_%s.png\'' % (options.graphicsdirectory, options.graphicsprefixname, 'multiplot')) + g('set parametric') g('set nokey') g('set noxtic') @@ -323,9 +387,8 @@ def main(): # g = plot2DRectFromFiles('./ResBounds', state=gstate, plot=False) # plotXYPoint(r, g=g) - wait(prompt='Press return to end the plot.\n') - - pass + if options.terminal: + wait(prompt='Press return to end the plot.\n') # when executed, just run main(): if __name__ == '__main__': diff --git a/test/t-doEstimatorNormalMulti.cpp b/test/t-doEstimatorNormalMulti.cpp index 398cdcbfd..2ba3c9684 100644 --- a/test/t-doEstimatorNormalMulti.cpp +++ b/test/t-doEstimatorNormalMulti.cpp @@ -1,3 +1,5 @@ +#include + #include #include @@ -33,6 +35,7 @@ int main(int ac, char** av) AtomType covar2_value = parser.createParam((AtomType)0.5, "covar2", "Covar value 2", '2', section).value(); AtomType covar3_value = parser.createParam((AtomType)1, "covar3", "Covar value 3", '3', section).value(); + if (parser.userNeedsHelp()) { parser.printHelp(std::cout); @@ -86,26 +89,37 @@ int main(int ac, char** av) //----------------------------------------------------------------------------- - // (3) distribution output + // (3a) distribution output preparation //----------------------------------------------------------------------------- - doDummyContinue< Distrib >* dummy_continue = new doDummyContinue< Distrib >(); - state.storeFunctor(dummy_continue); + doDummyContinue< Distrib >* distrib_dummy_continue = new doDummyContinue< Distrib >(); + state.storeFunctor(distrib_dummy_continue); - doCheckPoint< Distrib >* distribution_continue = new doCheckPoint< Distrib >( *dummy_continue ); - state.storeFunctor(distribution_continue); + doCheckPoint< Distrib >* distrib_continue = new doCheckPoint< Distrib >( *distrib_dummy_continue ); + state.storeFunctor(distrib_continue); doDistribStat< Distrib >* distrib_stat = new doStatNormalMulti< EOT >(); state.storeFunctor(distrib_stat); - distribution_continue->add( *distrib_stat ); + distrib_continue->add( *distrib_stat ); - eoMonitor* stdout_monitor = new eoStdoutMonitor(); - state.storeFunctor(stdout_monitor); - stdout_monitor->add(*distrib_stat); - distribution_continue->add( *stdout_monitor ); + std::ostringstream ss; + ss << p_size << "_" << mean_value << "_" << covar1_value << "_" + << covar2_value << "_" << covar3_value << "_gen"; - (*distribution_continue)( distrib ); + doFileSnapshot* distrib_file_snapshot = new doFileSnapshot("TestResDistrib", 1, ss.str()); + state.storeFunctor(distrib_file_snapshot); + distrib_file_snapshot->add(*distrib_stat); + distrib_continue->add(*distrib_file_snapshot); + + //----------------------------------------------------------------------------- + + + //----------------------------------------------------------------------------- + // (3b) distribution output + //----------------------------------------------------------------------------- + + (*distrib_continue)( distrib ); //----------------------------------------------------------------------------- @@ -154,20 +168,20 @@ int main(int ac, char** av) // (5) population output //----------------------------------------------------------------------------- - eoContinue< EOT >* cont = new eoGenContinue< EOT >( 2 ); // never reached fitness - state.storeFunctor(cont); + eoContinue< EOT >* pop_cont = new eoGenContinue< EOT >( 2 ); // never reached fitness + state.storeFunctor(pop_cont); - eoCheckPoint< EOT >* pop_continue = new eoCheckPoint< EOT >( *cont ); + eoCheckPoint< EOT >* pop_continue = new eoCheckPoint< EOT >( *pop_cont ); state.storeFunctor(pop_continue); - doPopStat< EOT >* popStat = new doPopStat; - state.storeFunctor(popStat); - pop_continue->add(*popStat); + doPopStat< EOT >* pop_stat = new doPopStat; + state.storeFunctor(pop_stat); + pop_continue->add(*pop_stat); - doFileSnapshot* fileSnapshot = new doFileSnapshot("TestResPop"); - state.storeFunctor(fileSnapshot); - fileSnapshot->add(*popStat); - pop_continue->add(*fileSnapshot); + doFileSnapshot* pop_file_snapshot = new doFileSnapshot("TestResPop"); + state.storeFunctor(pop_file_snapshot); + pop_file_snapshot->add(*pop_stat); + pop_continue->add(*pop_file_snapshot); (*pop_continue)( pop ); @@ -190,7 +204,7 @@ int main(int ac, char** av) // (7) distribution output //----------------------------------------------------------------------------- - (*distribution_continue)( distrib ); + (*distrib_continue)( distrib ); //----------------------------------------------------------------------------- diff --git a/test/test_cov_parameters.py b/test/test_cov_parameters.py new file mode 100755 index 000000000..c73c9fbbd --- /dev/null +++ b/test/test_cov_parameters.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +PSIZE = 10000 +MEAN = 0 +CMD = "./test/t-doEstimatorNormalMulti -P=%s -m=%.1f -1=%.1f -2=%.1f -3=%.1f && ./gplot.py -r TestResPop -p -w 5 -u -g %s -G results_for_test_cov_parameters" + +from os import system +from numpy import arange + +if __name__ == '__main__': + + for p1 in list(arange(0.1, 1.1, 0.1)): + for p2 in list(arange(-1., 0., 0.1)) + list(arange(0., 1.1, 0.1)): + for p3 in list(arange(0.1, 1.1, 0.1)): + cmd = CMD % ( PSIZE, MEAN, p1, p2, p3, '%d_%.1f_%.1f_%.1f_%.1f' % (PSIZE, MEAN, p1, p2, p3) ) + print cmd + system( cmd )