Exemplo n.º 1
0
def main():
    dimension = 15
    bounds = [0, 0, dimension - 1, dimension - 1]
    condition = [-5, -3, -1, 0, 1, 3, 5]
    minDistanceBetweenGrids = max(condition) + 1
    maxDistanceBetweenGrids = UpdateWorld.calculateMaxDistanceOfGrid(bounds) - minDistanceBetweenGrids
    block = 15
    initialWorld = UpdateWorld.InitialWorld(bounds)
    updateWorld = UpdateWorld.UpdateWorld(bounds, condition, minDistanceBetweenGrids, maxDistanceBetweenGrids)
    pg.init()
    screenWidth = 680
    screenHeight = 680
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    textColorTuple = (255, 50, 50)
    softmaxBeta = 2.5
    episilonGreedy = 1
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT])

    picturePath = os.path.join(os.path.join(DIRNAME, '../..'), '/pictures/')
    resultsPath = os.path.join(os.path.join(DIRNAME, '../..'), '/results/')
    policyPath = os.path.join(os.path.join(DIRNAME, '../..'), 'machinePolicy/')
    humanController = HumanController(dimension)
    policyFile = open(policyPath + "noise0commitSnakeGoalGird15_policy.pkl", "rb")
    policy = pickle.load(policyFile)
    modelController = ModelController(policy, dimension, softmaxBeta, episilonGreedy)
    controller = modelController
    numberOfMachineRun = 20
    for i in range(16, numberOfMachineRun):
        experimentValues = co.OrderedDict()
        # experimentValues["name"] = input("Please enter your name:").capitalize()
        experimentValues["name"] = 'machineEpisilon' + str(episilonGreedy) + "_" + str(i)
        experimentValues["condition"] = 'None'
        writerPath = resultsPath + experimentValues["name"] + '.csv'
        writer = WriteDataFrameToCSV(writerPath)
        introductionImage = pg.image.load(picturePath + 'introduction.png')
        restImage = pg.image.load(picturePath + 'rest.png')
        finishImage = pg.image.load(picturePath + 'finish.png')
        introductionImage = pg.transform.scale(introductionImage, (screenWidth, screenHeight))
        finishImage = pg.transform.scale(finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
        drawBackground = DrawBackground(screen, dimension, leaveEdgeSpace, backgroundColor, lineColor, lineWidth,
                                        textColorTuple)
        checkBoundary = CheckBoundary([0, dimension - 1], [0, dimension - 1])
        drawNewState = DrawNewState(screen, drawBackground, targetColor, playerColor, targetRadius, playerRadius)
        drawImage = DrawImage(screen)
        designValues = UpdateWorld.createDesignValues(condition * 3, block)
        restTrial = list(range(0, len(designValues), len(condition) * 15))
        trial = Trial(controller, drawNewState, checkBoundary)
        experiment = Experiment(trial, writer, experimentValues, initialWorld, updateWorld, drawImage, resultsPath,
                                minDistanceBetweenGrids, maxDistanceBetweenGrids, restImage, finishImage, restTrial)
        # drawImage(introductionImage)
        experiment(designValues)
Exemplo n.º 2
0
def main():
    dimension = 21
    bounds = [0, 0, dimension - 1, dimension - 1]
    minDistanceBetweenGrids = 5
    condition = [-5, -3, -1, 0, 1, 3, 5]
    initialWorld = UpdateWorld.InitialWorld(bounds)
    pg.init()
    screenWidth = 720
    screenHeight = 720
    screen = pg.display.set_mode((screenWidth, screenHeight))
    gridSize = 21
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    stopwatchUnit = 10
    textColorTuple = (255, 50, 50)
    stopwatchEvent = pg.USEREVENT + 1
    pg.time.set_timer(stopwatchEvent, stopwatchUnit)
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT, stopwatchEvent])
    finishTime = 90000
    currentStopwatch = 32888
    score = 0
    drawBackground = DrawBackground(screen, gridSize, leaveEdgeSpace,
                                    backgroundColor, lineColor, lineWidth,
                                    textColorTuple)
    drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                playerColor, targetRadius, playerRadius)
    humanController = HumanController(gridSize, stopwatchEvent, stopwatchUnit,
                                      drawNewState, finishTime)
    policy = pickle.load(open("SingleWolfTwoSheepsGrid15.pkl", "rb"))
    modelController = ModelController(policy, gridSize, stopwatchEvent,
                                      stopwatchUnit, drawNewState, finishTime)
    trial = Trial(modelController, drawNewState, stopwatchEvent, finishTime)
    bean1Grid, bean2Grid, playerGrid = initialWorld(minDistanceBetweenGrids)
    bean1Grid = (3, 13)
    bean2Grid = (5, 0)
    playerGrid = (0, 8)
    results = trial(bean1Grid, bean2Grid, playerGrid, score, currentStopwatch)
Exemplo n.º 3
0
def main():
    dimension = 15
    minDistanceBetweenGrids = 5
    blockNumber = 3
    noiseCondition = list(permutations([1, 2, 0], 3))
    noiseCondition.append((1, 1, 1))
    picturePath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Pictures/'
    resultsPath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Results/'
    machinePolicyPath = os.path.abspath(os.path.join(
        os.getcwd(), os.pardir)) + '/machinePolicy/'
    bottom = [4, 6, 8]
    height = [6, 7, 8]
    direction = [0, 90, 180, 270]
    noiseDesignValues = UpdateWorld.createNoiseDesignValue(
        noiseCondition, blockNumber)
    shapeDesignValues = UpdateWorld.createShapeDesignValue(bottom, height)
    updateWorld = UpdateWorld.UpdateWorld(direction, dimension)
    pg.init()
    screenWidth = 600
    screenHeight = 600
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    textColorTuple = (255, 50, 50)
    softmaxBeta = -1
    experimentValues = co.OrderedDict()
    for i in range(50):
        experimentValues["name"] = "maxModel" + str(i)
        # experimentValues["name"] = input("Please enter your name:").capitalize()
        writerPath = resultsPath + experimentValues["name"] + '.csv'
        writer = WriteDataFrameToCSV(writerPath)
        introductionImage = pg.image.load(picturePath + 'introduction.png')
        finishImage = pg.image.load(picturePath + 'finish.png')
        introductionImage = pg.transform.scale(introductionImage,
                                               (screenWidth, screenHeight))
        finishImage = pg.transform.scale(
            finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
        drawBackground = DrawBackground(screen, dimension, leaveEdgeSpace,
                                        backgroundColor, lineColor, lineWidth,
                                        textColorTuple)
        drawText = DrawText(screen, drawBackground)
        drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                    playerColor, targetRadius, playerRadius)
        drawImage = DrawImage(screen)
        policy = pickle.load(
            open(machinePolicyPath + "noise0.1WolfToTwoSheepGird15_policy.pkl",
                 "rb"))
        modelController = ModelController(policy, dimension, softmaxBeta)
        humanController = HumanController(dimension)
        checkBoundary = CheckBoundary([0, dimension - 1], [0, dimension - 1])
        controller = modelController
        normalNoise = NormalNoise(controller)
        awayFromTheGoalNoise = AwayFromTheGoalNoise(controller)
        normalTrial = NormalTrial(controller, drawNewState, drawText,
                                  normalNoise, checkBoundary)
        specialTrial = SpecialTrial(controller, drawNewState, drawText,
                                    awayFromTheGoalNoise, checkBoundary)
        experiment = Experiment(normalTrial, specialTrial, writer,
                                experimentValues, updateWorld, drawImage,
                                resultsPath, minDistanceBetweenGrids)
        # drawImage(introductionImage)
        experiment(noiseDesignValues, shapeDesignValues)
def main():
    gridSize = 16
    bounds = [0, 0, gridSize - 1, gridSize - 1]
    minDistanceBetweenGrids = 5
    condition = [-5, -3, -1, 0, 1, 3, 5]
    counter = [0] * len(condition)
    initialWorld = UpdateWorld.InitialWorld(bounds)
    updateWorld = UpdateWorld.UpdateWorld(bounds, condition, counter)
    pg.init()
    screenWidth = 680
    screenHeight = 680
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    stopwatchUnit = 100
    finishTime = 1000 * 90
    block = 1
    softmaxBeita = -1
    textColorTuple = (255, 50, 50)
    stopwatchEvent = pg.USEREVENT + 1
    pg.time.set_timer(stopwatchEvent, stopwatchUnit)
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT, stopwatchEvent])
    pg.key.set_repeat(120, 120)
    picturePath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Pictures/'
    resultsPath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Results/'
    experimentValues = co.OrderedDict()
    experimentValues["name"] = input("Please enter your name:").capitalize()
    experimentValues["condition"] = 'None'
    writerPath = resultsPath + experimentValues["name"] + '.csv'
    writer = WriteDataFrameToCSV(writerPath)
    introductionImage = pg.image.load(picturePath + 'introduction.png')
    restImage = pg.image.load(picturePath + 'rest.png')
    finishImage = pg.image.load(picturePath + 'finish.png')
    introductionImage = pg.transform.scale(introductionImage,
                                           (screenWidth, screenHeight))
    finishImage = pg.transform.scale(
        finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
    drawBackground = DrawBackground(screen, gridSize, leaveEdgeSpace,
                                    backgroundColor, lineColor, lineWidth,
                                    textColorTuple)
    drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                playerColor, targetRadius, playerRadius)
    drawImage = DrawImage(screen)
    humanController = HumanController(gridSize, stopwatchEvent, stopwatchUnit,
                                      drawNewState, finishTime)
    policy = pickle.load(open("SingleWolfTwoSheepsGrid15.pkl", "rb"))
    modelController = ModelController(policy, gridSize, stopwatchEvent,
                                      stopwatchUnit, drawNewState, finishTime,
                                      softmaxBeita)
    trial = Trial(modelController, drawNewState, stopwatchEvent, finishTime)
    experiment = Experiment(trial, writer, experimentValues, initialWorld,
                            updateWorld, drawImage, resultsPath,
                            minDistanceBetweenGrids)
    giveExperimentFeedback = GiveExperimentFeedback(screen, textColorTuple,
                                                    screenWidth, screenHeight)
    drawImage(introductionImage)
    score = [0] * block
    for i in range(block):
        score[i] = experiment(finishTime)
        giveExperimentFeedback(i, score)
        if i == block - 1:
            drawImage(finishImage)
        # else:
        # drawImage(restImage)

    participantsScore = np.sum(np.array(score))
    print(participantsScore)
Exemplo n.º 5
0
def main():
    dimension = 15
    bounds = [0, 0, dimension - 1, dimension - 1]
    condition = [-5, -3, -1, 0, 1, 3, 5]
    minDistanceBetweenGrids = max(condition) + 1
    maxDistanceBetweenGrids = UpdateWorld.calculateMaxDistanceOfGrid(
        bounds) - minDistanceBetweenGrids
    block = 15
    initialWorld = UpdateWorld.InitialWorld(bounds)
    updateWorld = UpdateWorld.UpdateWorld(bounds, condition,
                                          minDistanceBetweenGrids,
                                          maxDistanceBetweenGrids)
    pg.init()
    screenWidth = 680
    screenHeight = 680
    screen = pg.display.set_mode((screenWidth, screenHeight))
    leaveEdgeSpace = 2
    lineWidth = 1
    backgroundColor = [205, 255, 204]
    lineColor = [0, 0, 0]
    targetColor = [255, 50, 50]
    playerColor = [50, 50, 255]
    targetRadius = 10
    playerRadius = 10
    textColorTuple = (255, 50, 50)
    softmaxBeta = 40
    episilonGreedy = 1
    temperature = 1
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT])
    picturePath = os.path.abspath(os.path.join(os.getcwd(),
                                               "../..")) + '/Pictures/'
    resultsPath = os.path.abspath(os.path.join(os.getcwd(),
                                               "../..")) + '/Results/'
    policyPath = os.path.abspath(os.path.join(os.getcwd(),
                                              "../..")) + '/machinePolicy/'
    selectModelParameter = SelectModelParameter(resultsPath, 'csv')
    policyFile = open(policyPath + "SingleWolfTwoSheepsGrid15.pkl", "rb")
    policy = pickle.load(policyFile)
    softmaxBeta = list(range(35, 45, 1))
    crossEntropyResults = dict()
    for Beta in softmaxBeta:
        modelController = ModelController(policy, dimension, Beta,
                                          episilonGreedy)
        boltzmannModelController = BoltzmannModelController(
            policy, dimension, temperature)
        controller = boltzmannModelController
        numberOfMachineRun = 5
        for i in range(numberOfMachineRun):
            experimentValues = co.OrderedDict()
            experimentValues["name"] = 'machineEpisilon' + str(
                episilonGreedy) + "Beta" + str(Beta) + "_" + str(i)
            experimentValues["condition"] = 'None'
            writerPath = resultsPath + experimentValues["name"] + '.csv'
            writer = WriteDataFrameToCSV(writerPath)
            restImage = pg.image.load(picturePath + 'rest.png')
            finishImage = pg.image.load(picturePath + 'finish.png')
            finishImage = pg.transform.scale(
                finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4)))
            drawBackground = DrawBackground(screen, dimension, leaveEdgeSpace,
                                            backgroundColor, lineColor,
                                            lineWidth, textColorTuple)
            checkBoundary = CheckBoundary([0, dimension - 1],
                                          [0, dimension - 1])
            drawNewState = DrawNewState(screen, drawBackground, targetColor,
                                        playerColor, targetRadius,
                                        playerRadius)
            drawImage = DrawImage(screen)
            designValues = UpdateWorld.createDesignValues(condition * 3, block)
            restTrial = list(range(0, len(designValues), len(condition) * 15))
            trial = Trial(controller, drawNewState, checkBoundary)
            experiment = Experiment(trial, writer, experimentValues,
                                    initialWorld, updateWorld, drawImage,
                                    resultsPath, minDistanceBetweenGrids,
                                    maxDistanceBetweenGrids, restImage,
                                    finishImage, restTrial)
            experiment(designValues)
            crossEntropyResults[Beta] = selectModelParameter("Beta" +
                                                             str(Beta))
    optimalBeta = min(crossEntropyResults, key=crossEntropyResults.get)
    print(optimalBeta)