示例#1
0
def plotAllAveragedSingleGraphsForDirectory(experimentDirectory, architectureList = ["DQNNet", "FirstRepresentationSwitchNet", "PolicySwitchNet"], taskSeparator = "^"):
    resultsCollectionFunction        = lambda f: dataManipulation.getResultsFromTaskFile(f, 0, 1, 2)

    if experimentDirectory[-1] == "/":
        taskString = experimentDirectory[experimentDirectory[0:-1].rindex("/") + 1:-1]
    else:
        taskString = experimentDirectory[experimentDirectory.rindex("/") + 1:]


    taskList   = taskString.split(taskSeparator)
    numTasks   = len(taskList)
    print taskString
    print taskList
    plotCounter = 1
    for architecture in architectureList:
        archDirectory = experimentDirectory + "/" + architecture
        contents = os.listdir(archDirectory)
        resultFiles = [c for c in contents if (".csv" in c and "results" in c)]
        for resultFile in resultFiles:
            taskNum = resultFile[resultFile.index("task_") + 5:resultFile.index("_results")]
            print taskNum

            title = taskList[int(taskNum)]
            suffix = resultFile[resultFile.index("_results") + 8: resultFile.index(".")]
            resultFilePath = archDirectory + "/" + resultFile
            saveToFilePath = archDirectory + "/" + "graph_" + title + suffix
            plotSingleResultFile(resultFilePath, title + suffix, xLabel = 'Epoch Number', yLabel = "Average Reward", plotNumber =  plotCounter, saveToName = saveToFilePath, resultsCollectionFunction = resultsCollectionFunction, showPlot = False)
            plotCounter += 1
示例#2
0
def main(args):
    # test("transferBaselinesCompiled/")
    # test2("transferBaselinesCompiled/pong/DQNNet/task_0_results_Avg.csv", "Pong")
    # test("transferBaselinesFullCompiled/")
    # test3("transferBaselinesCompiled/")
    # test4("transferBaselinesCompiled/", "transferBaselinesFullCompiled/")

    resultsCollectionFunction        = lambda f: dataManipulation.getResultsFromTaskFile(f, 0, 3, -1)
    resultsCollectionFunctionSummed  = lambda f: dataManipulation.getResultsFromTaskFile(f, 0, 1, 2)


# createExperimentDataSeries("../compiledResults/transferMultigameResult/", "../compiledResults/dqnMinBaselineResult/", "assault,demon_attack,space_invaders,phoenix", False)
    
    # createExperimentDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", "/home/robert/Desktop/Research/CompiledResults/testStructure/DqnBaselines", "assault^demon_attack^space_invaders^phoenix", summed = False, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)
    # createExperimentDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", "/home/robert/Desktop/Research/CompiledResults/testStructure/DqnBaselines", "enduro^demon_attack^pong^space_invaders", summed = False, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)
    # createExperimentDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", "/home/robert/Desktop/Research/CompiledResults/testStructure/DqnBaselines", "enduro^pong^gopher^space_invaders", summed = False, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)

    # createExperimentDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", "/home/robert/Desktop/Research/CompiledResults/testStructure/DqnBaselines", "assault^demon_attack^space_invaders^phoenix", summed = True, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)
    # createExperimentDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", "/home/robert/Desktop/Research/CompiledResults/testStructure/DqnBaselines", "enduro^demon_attack^pong^space_invaders", summed = True, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)
    # createExperimentDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", "/home/robert/Desktop/Research/CompiledResults/testStructure/DqnBaselines", "enduro^pong^gopher^space_invaders", summed = True, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)
    # return


    # testDirectory = "/home/robert/Desktop/Research/CompiledResults/transferMultigameResult/enduro^pong^gopher^space_invaders"
    # testDirectory = "/home/robert/Desktop/Research/CompiledResults/transferMultigameResult/enduro^demon_attack^pong^space_invaders"
    # testDirectory = "/home/robert/Desktop/Research/CompiledResults/transferMultigameResult/assault^demon_attack^space_invaders^phoenix"
    # plotAllAveragedSingleGraphsForDirectory(testDirectory)
    # return



    # testFilename = "/home/robert/Desktop/Research/CompiledResults/transferMultigameResult/assault^demon_attack^space_invaders^phoenix/DQNNet/averaged_task_0_results.csv"
    # plotSingleResultFile(testFilename, "Assault 4game", "Epoch Number", "average reward", saveToName = "", resultsCollectionFunction = resultsCollectionFunctionSummed)
    # return

    

    romStringList = ["assault^demon_attack^space_invaders^phoenix", "enduro^demon_attack^pong^space_invaders", "enduro^pong^gopher^space_invaders"]
    taskPrefixList = ["4Similar", "2Similar", "NonSimilar"]
    taskIDList = [2, 3, 3]
    
    # romStringList = ["assault^demon_attack^space_invaders^phoenix", "enduro^demon_attack^pong^space_invaders"]
    # taskPrefixList = ["4Similar", "2Similar"]
    # taskIDList = [1, 1]
    
    # romStringList = ["enduro^demon_attack^pong^space_invaders", "enduro^pong^gopher^space_invaders"]
    # taskPrefixList = ["2Similar", "NonSimilar"]
    # taskIDList = [0, 0]

    extensionList = ["DQNNet", "FirstRepresentationSwitchNet", "PolicySwitchNet", "Disjoint"]
    # extensionList = ["DQNNet"]
    # extensionList = ["Disjoint"]
    # extensionList = ["PolicySwitchNet"]
    # extensionList = ["FirstRepresentationSwitchNet"]

    baselineDirectory = "/home/robert/Desktop/Research/CompiledResults/testStructure/DqnBaselines"

    for e in extensionList:
        createComparisonDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", romStringList, taskIDList, taskPrefixList, [e], baselineDirectory, summed = False, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)
        createComparisonDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", romStringList, taskIDList, taskPrefixList, [e], baselineDirectory, summed = True, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)


    createComparisonDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", romStringList, taskIDList, taskPrefixList, extensionList, baselineDirectory, summed = False, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)
    createComparisonDataSeries("/home/robert/Desktop/Research/CompiledResults/testStructure/transferMultigameResult", romStringList, taskIDList, taskPrefixList, extensionList, baselineDirectory, summed = True, divided = True, resultsCollectionFunction = resultsCollectionFunctionSummed)

    return

    if len(args) > 0:
        t = int(args[0])
    else:
        t = 0

    if t == 0:
        createExperimentDataSeries("../compiledResults/transferMultigameResult/", "../compiledResults/dqnMinBaselineResult/", "assault,demon_attack,space_invaders,phoenix", False)
    elif t == 1:
        createExperimentDataSeries("../compiledResults/transferMultigameResult/", "../compiledResults/dqnMinBaselineResult/", "enduro,demon_attack,pong,space_invaders", False)
    elif t == 2:
        createExperimentDataSeries("../compiledResults/transferMultigameResult/", "../compiledResults/dqnMinBaselineResult/", "enduro,pong,gopher,space_invaders", False)
示例#3
0
def createExperimentDataSeriesOld(directory, baselineDirectory, romString, summed = True, divided = True):
    pathToArchs = (directory + "/" + romString)
    games = romString.split(",")
    numTasks = len(games)
    gameDict = {}
    archList = []

    for g in games:
        gameDict[g] = {}

    #load transfer part
    for arch in os.listdir(pathToArchs):
        if "." in arch:
            continue #Not a directory

        archList.append(arch)
        archDirectory = pathToArchs + "/" + arch

        for file in os.listdir(archDirectory):
            if "results" in file and ".csv" in file:

                taskNum = int(file[file.index('_') + 1 : file.index('_results')])
                currentGame = games[taskNum]
                gameDict[currentGame][arch] = dataManipulation.getResultsFromTaskFile(archDirectory + "/" + file)
                
                if divided:
                    gameDict[currentGame][arch][0] = divideDataElementsByFactor(gameDict[currentGame][arch][0], numTasks)
                
                if summed:
                    gameDict[currentGame][arch][1] = computeSummedData(gameDict[currentGame][arch][1])
                    gameDict[currentGame][arch][2] = gameDict[currentGame][arch][2] ** 2
                    gameDict[currentGame][arch][2] = computeSummedData(gameDict[currentGame][arch][2]) ** 0.5

    #load baselines
    count = 1
    for game in games:
        baselineFile = baselineDirectory + "/" + game + "/DQNNet/task_0_results_Avg.csv"
        gameDict[game]["baseline"] = dataManipulation.getResultsFromTaskFile(baselineFile)

        if divided:       
            numDataPointsToUse = int(len(gameDict[game]["baseline"][0]) / (numTasks / 2))
            gameDict[game]["baseline"][0] = gameDict[game]["baseline"][0][0:numDataPointsToUse]
            gameDict[game]["baseline"][1] = gameDict[game]["baseline"][1][0:numDataPointsToUse]
            gameDict[game]["baseline"][2] = gameDict[game]["baseline"][2][0:numDataPointsToUse]

        if summed:
                    gameDict[game]["baseline"][1] = computeSummedData(gameDict[game]["baseline"][1])
                    gameDict[game]["baseline"][2] = gameDict[game]["baseline"][2] ** 2
                    gameDict[game]["baseline"][2] = computeSummedData(gameDict[game]["baseline"][2]) ** 0.5


        taskDataSeriesList = []
        baselineDataSeries = DataSeries(gameDict[game]["baseline"][0], gameDict[game]["baseline"][1], gameDict[game]["baseline"][2], game)

        for arch in archList:
            currentArchDataSeries = DataSeries(gameDict[game][arch][0], gameDict[game][arch][1], gameDict[game][arch][2], game + "_" + arch)
            taskDataSeriesList.append(currentArchDataSeries)
        
        taskDataSeriesList.append(baselineDataSeries)

        if summed:
            titleSuffix = "summed"
        else:
            titleSuffix = ""

        plotDataSeries(count, taskDataSeriesList, romString, saveFigure = pathToArchs + "/" + game + "_"+titleSuffix+"Graph")
        count += 1
    plt.show()