def plotAllTSForInitalPopulationType(initPopType):
		title = None # 'Fitness time series for the two types of sensors attachment'
		dataDict = {attachments[x]: -1.*np.loadtxt(fitnessFileName(x, initPopType)) for x in attachments.keys()}
		tplt.plotAverageTimeSeries(dataDict, 'Error', 'errorComparison_GENS50_IP' + initPopType + '.png', title=title, legendLocation=None, xlabel=xlabel, xlimit=50, ylimit=ylimit, figsize=(2.5,4), xscale=xscale, yscale=yscale, margins=margins)
		tplt.plotAllTimeSeries(dataDict, 'Error', 'errorAllTrajectories_GEN50_IP' + initPopType + '.png', title=title, legendLocation=None, xlabel=xlabel, xlimit=50, ylimit=ylimit, figsize=(2.5,4), xscale=xscale, yscale=yscale, margins=margins, alpha=alpha)
		tplt.plotAverageTimeSeries(dataDict, 'Error', 'errorComparison_IP' + initPopType + '.png', title=title, legendLocation=1, xlabel=xlabel, xlimit=500, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins)
		tplt.plotAllTimeSeries(dataDict, 'Error', 'errorAllTrajectories_IP' + initPopType + '.png', title=title, legendLocation=1, xlabel=xlabel, xlimit=500, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins, alpha=alpha)
Esempio n. 2
0
	def plotAll():
		os.chdir('results')
		xlabel = 'Generations'
		ylimit = None
		yscale = 'lin'
		xscale = 'lin'
		margins = 0.5
		xlimit = 6000
		alpha = 0.3
		title = None
#		figsize = (2.5,4)
		figsize = None
		striptype = 'conf95'

		filenames = [ 'gid{}'.format(x) for x in range(1,9) ]
		dataDict = { fn: np.loadtxt(fn) for fn in filenames }

		comp3 = { tsn: dataDict[fn] for tsn,fn in {'no turning': 'gid3', 'smooth turning': 'gid7', 'abrupt turning': 'gid8'}.items() }

		comparisons = { 'comp3': comp3 }

		for e,d in comparisons.items():
			tplt.plotAverageTimeSeries(d, 'Fitness', e + '-avg.png',
			                           title=title, legendLocation=4, xlabel=xlabel,
			                           xlimit=xlimit, ylimit=ylimit, figsize=figsize, xscale=xscale, yscale=yscale, margins=margins, strips=striptype)
			tplt.plotAllTimeSeries(d, 'Fitness', e + '-all.png', alpha=alpha,
			                       title=title, legendLocation=4, xlabel=xlabel,
			                       xlimit=xlimit, ylimit=ylimit, figsize=figsize, xscale=xscale, yscale=yscale, margins=margins)

		os.chdir('..')
def plotMinMMMDistTSs(experiment, prefixFun):
    '''Extracting and plotting time series for distance to the maximally modular morphology (MMM)'''

    xlabel = r'$T$'
    figureDims = [7, 4]
    #figureDims = None
    xlimit = evsDefaults['genStopAfter']
    margins = 0.5
    strips = 'conf95'

    title = None
    legendLocation = 1

    gridFileNamePrefix = prefixFun

    def minMMMDistFileName(gridPoint):
        return '../results/' + gridFileNamePrefix(gridPoint) + '_minMMMDist'

    def generateMinMMMDistTimeSeries(gridPoint):
        minMMMDistTS = [
            gctools.minParetoFrontHammingDistanceToMMM(gen)
            for gen in range(1, evsDefaults['genStopAfter'] + 1)
        ]
        filename = minMMMDistFileName(gridPoint)
        with open(filename, 'a') as file:
            file.write(' '.join(map(str, minMMMDistTS)) + '\n')

    experiment.executeAtEveryGridPointDir(generateMinMMMDistTimeSeries)

    os.chdir('results')
    ylabel = r'$\mu$'
    ylimit = None

    title = None
    dataDict = {
        gridFileNamePrefix(p): np.loadtxt(minMMMDistFileName(p))
        for p in nonRSGrid
    }

    # Plotting averages in linear time scales on y
    yscale = 'lin'
    xscale = 'lin'
    tplt.plotAverageTimeSeries(dataDict,
                               ylabel,
                               'minMMMDistTS.png',
                               title=title,
                               legendLocation=legendLocation,
                               xlabel=xlabel,
                               xlimit=xlimit,
                               ylimit=ylimit,
                               xscale=xscale,
                               yscale=yscale,
                               margins=margins,
                               strips=strips,
                               figureDims=figureDims)

    plt.clf()

    os.chdir('..')
Esempio n. 4
0
def plotErrorTSs(experiment, prefixFun):
	import shutil

	gridFileNamePrefix = prefixFun

	##### Extracting and plotting fitness time series #####

	xlabel = r'$T$'
	#figureDims = [7,4]
	figureDims = None
	xlimit = evsDefaults['genStopAfter']
	margins = 0.5
	strips = 'conf95'

	title = None
	legendLocation = 1

	def fitnessFileName(gp):
		return gridFileNamePrefix(gp) + '_fitness'
	def columnExtractor(gp):
		outFile = fitnessFileName(gp)
		subprocess.call('cut -d \' \' -f 2 bestIndividual*.log | tail -n +4 | tr \'\n\' \' \' >> ../results/' + outFile, shell=True)
		subprocess.call('echo >> ../results/' + outFile, shell=True)
	experiment.executeAtEveryGridPointDir(columnExtractor)

	os.chdir('results')

	ylabel = r'$\log_{10} E$'
	forcedYLabelPos = [0.05, 1.]
	ylimit = None

	title = None
	dataDict = {gridFileNamePrefix(p): -1.*np.loadtxt(fitnessFileName(p)) for p in nonRSGrid}

	# Plotting averages
	yscale = 'lin'
	xscale = 'lin'

	tplt.plotAverageTimeSeries(dataDict, ylabel, 'errorComparisonLinLin.png', title=title, legendLocation=legendLocation, xlabel=xlabel, xlimit=xlimit, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins, strips=strips, figureDims=figureDims, forcedYLabelPos=forcedYLabelPos)
	xscale = 'log'
	tplt.plotAverageTimeSeries(dataDict, ylabel, 'errorComparisonLogLin.png', title=title, legendLocation=legendLocation, xlabel=xlabel, xlimit=xlimit, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins, strips=strips, figureDims=figureDims, forcedYLabelPos=forcedYLabelPos)

	# Plotting the trajectory scatter
	alpha = 0.3
	yscale = 'lin'

	xscale = 'lin'
	tplt.plotAllTimeSeries(dataDict, ylabel, 'errorAllTrajectoriesLinLog.png', title=title, legendLocation=legendLocation, xlabel=xlabel, xlimit=xlimit, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins, alpha=alpha, figureDims=figureDims, forcedYLabelPos=forcedYLabelPos)
	xscale = 'log'
	tplt.plotAllTimeSeries(dataDict, ylabel, 'errorAllTrajectoriesLogLog.png', title=title, legendLocation=legendLocation, xlabel=xlabel, xlimit=xlimit, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins, alpha=alpha, figureDims=figureDims, forcedYLabelPos=forcedYLabelPos)

	plt.clf()

	os.chdir('..')
def processResults(experiment):
    import os
    import shutil
    import numpy as np
    import pbsGridWalker.tools.plotutils as tplt

    #	tfs.makeDirCarefully('results', maxBackups=100)
    def fitnessFileName(gp):
        return 'EV' + str(gp['evolver']) + '_NI' + str(
            gp['newIndividualsPerGeneration']
        ) + '_IP' + gp['initialPopulationType'] + '_fitness'

    def columnExtractor(gp):
        outFile = fitnessFileName(gp)
        subprocess.call(
            'cut -d \' \' -f 2 bestIndividual*.log | tail -n +4 | tr \'\n\' \' \' >> ../results/'
            + outFile,
            shell=True)
        subprocess.call('echo >> ../results/' + outFile, shell=True)
#	experiment.executeAtEveryGridPointDir(columnExtractor)

    os.chdir('results')
    xlabel = 'Generations'
    ylimit = None
    yscale = 'lin'
    xscale = 'lin'
    margins = 0.5
    xlimit = None
    alpha = 0.3
    title = None

    def robustLoadTxt(ffn):
        arr0 = []
        with open(ffn, 'r') as ff:
            for line in ff:
                vals = map(float, line.split())
                arr0.append(vals)
        minlen = min([len(vs) for vs in arr0])
        arr1 = []
        for vs in arr0:
            arr1.append(vs[:minlen])
        arr1 = np.array(arr1)
        return arr1

#	dataDict = { str(mg): np.loadtxt(fitnessFileName(mg)) for mg in [0.1, 0.3, 0.5, 0.7, 0.9] }
#	dataDict = { str(mg): robustLoadTxt(fitnessFileName(mg)) for mg in [0.1, 0.3, 0.5, 0.7, 0.9] }

#	tplt.plotAverageTimeSeries(dataDict, 'Error', 'mg.png',
#	                           title=title, legendLocation=None, xlabel=xlabel,
#	                           xlimit=xlimit, ylimit=ylimit, figsize=(2.5,4), xscale=xscale, yscale=yscale, margins=margins)

    ni = 0

    for ip in ['sparse', 'random']:
        dataDict = {
            'with SRS' if ev == 'temporalUnrolling' else 'without SRS':
            robustLoadTxt(
                fitnessFileName({
                    'initialPopulationType': ip,
                    'newIndividualsPerGeneration': ni,
                    'evolver': ev
                }))
            for ev in ['temporalUnrolling', 'temporalUnrollingVer0']
        }

        tplt.plotAllTimeSeries(dataDict,
                               'Fitness',
                               'ev_IP' + ip + '.png',
                               title=title,
                               legendLocation=4,
                               xlabel=xlabel,
                               xlimit=xlimit,
                               ylimit=ylimit,
                               xscale=xscale,
                               yscale=yscale,
                               margins=margins,
                               alpha=alpha)
        tplt.plotAverageTimeSeries(dataDict,
                                   'Fitness',
                                   'ev_IP' + ip + '_NI' + str(ni) + '_avg.png',
                                   title=title,
                                   legendLocation=4,
                                   xlabel=xlabel,
                                   xlimit=xlimit,
                                   ylimit=ylimit,
                                   xscale=xscale,
                                   yscale=yscale,
                                   margins=margins)

    ni = 5

    for ip in ['sparse', 'random']:
        dataDict = {
            'with SRS' if ev == 'temporalUnrolling' else 'without SRS':
            robustLoadTxt(
                fitnessFileName({
                    'initialPopulationType': ip,
                    'newIndividualsPerGeneration': ni,
                    'evolver': ev
                }))
            for ev in ['temporalUnrolling', 'temporalUnrollingVer0']
        }

        tplt.plotAllTimeSeries(dataDict,
                               'Fitness',
                               'ev_IP' + ip + '_NI' + str(ni) + '.png',
                               title=title,
                               legendLocation=4,
                               xlabel=xlabel,
                               xlimit=xlimit,
                               ylimit=ylimit,
                               xscale=xscale,
                               yscale=yscale,
                               margins=margins,
                               alpha=alpha)
        tplt.plotAverageTimeSeries(dataDict,
                                   'Fitness',
                                   'ev_IP' + ip + '_NI' + str(ni) + '_avg.png',
                                   title=title,
                                   legendLocation=4,
                                   xlabel=xlabel,
                                   xlimit=xlimit,
                                   ylimit=ylimit,
                                   xscale=xscale,
                                   yscale=yscale,
                                   margins=margins)

#	def plotAllTSForInitalPopulationType(initPopType):
#		title = None
#		dataDict = {attachments[x]: -1.*np.loadtxt(fitnessFileName(x, initPopType)) for x in attachments.keys()}
#		tplt.plotAverageTimeSeries(dataDict, 'Error', 'errorComparison_GENS50_IP' + initPopType + '.png', title=title, legendLocation=None, xlabel=xlabel, xlimit=50, ylimit=ylimit, figsize=(2.5,4), xscale=xscale, yscale=yscale, margins=margins)
#		tplt.plotAllTimeSeries(dataDict, 'Error', 'errorAllTrajectories_GEN50_IP' + initPopType + '.png', title=title, legendLocation=None, xlabel=xlabel, xlimit=50, ylimit=ylimit, figsize=(2.5,4), xscale=xscale, yscale=yscale, margins=margins, alpha=alpha)
#		tplt.plotAverageTimeSeries(dataDict, 'Error', 'errorComparison_IP' + initPopType + '.png', title=title, legendLocation=1, xlabel=xlabel, xlimit=500, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins)
#		tplt.plotAllTimeSeries(dataDict, 'Error', 'errorAllTrajectories_IP' + initPopType + '.png', title=title, legendLocation=1, xlabel=xlabel, xlimit=500, ylimit=ylimit, xscale=xscale, yscale=yscale, margins=margins, alpha=alpha)
#	for ip in initialPopulationTypes:
#		plotAllTSForNew(ip)
    os.chdir('..')