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)
示例#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)
示例#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]
    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)

    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)

    softmaxBeta = 2.5
    # policy = pickle.load(open(machinePolicyPath + "noise0.1commitSTNewGird15_policy.pkl", "rb"))
    policy = None
    goalPolicy = pickle.load(
        open(machinePolicyPath + "noise0.1commitSTGoalGird15_policy.pkl",
             "rb"))

    initPrior = [0.5, 0.5]
    commitBetaList = [1, 2, 5, 7]

    # for softmaxBeta in softmaxBetaList:
    for commitBeta in commitBetaList:
        for i in range(30):
            print(i)
            noiseDesignValues = UpdateWorld.createNoiseDesignValue(
                noiseCondition, blockNumber)
            shapeDesignValues = UpdateWorld.createShapeDesignValue(
                bottom, height)
            updateWorld = UpdateWorld.UpdateWorld(direction, dimension)

            experimentValues = co.OrderedDict()
            experimentValues["name"] = "commitBeta" + str(
                commitBeta) + '_' + str(i)
            resultsDirPath = os.path.join(resultsPath,
                                          "commitBeta" + str(commitBeta))
            if not os.path.exists(resultsDirPath):
                os.makedirs(resultsDirPath)
            writerPath = os.path.join(resultsDirPath,
                                      experimentValues["name"] + '.csv')
            writer = WriteDataFrameToCSV(writerPath)

            # modelController = ModelController(policy, dimension, softmaxBeta)
            modelControllerWithGoal = ModelControllerWithGoal(
                dimension, softmaxBeta, policy, goalPolicy, commitBeta)

            checkBoundary = CheckBoundary([0, dimension - 1],
                                          [0, dimension - 1])
            controller = modelControllerWithGoal
            normalNoise = NormalNoise(controller)
            awayFromTheGoalNoise = AwayFromTheGoalNoise(controller)
            # normalTrial = NormalTrial(controller, drawNewState, drawText, normalNoise, checkBoundary)
            # specialTrial = SpecialTrial(controller, drawNewState, drawText, awayFromTheGoalNoise, checkBoundary)
            inferGoalPosterior = InferGoalPosterior(goalPolicy, commitBeta)

            normalTrial = NormalTrialWithGoal(controller, drawNewState,
                                              drawText, normalNoise,
                                              checkBoundary, initPrior,
                                              inferGoalPosterior)
            specialTrial = SpecialTrialWithGoal(controller, drawNewState,
                                                drawText, awayFromTheGoalNoise,
                                                checkBoundary, initPrior,
                                                inferGoalPosterior)

            experiment = Experiment(normalTrial, specialTrial, writer,
                                    experimentValues, updateWorld, drawImage,
                                    resultsPath, minDistanceBetweenGrids)
            # debug
            # noiseDesignValues = ['special'] * 10
            experiment(noiseDesignValues, shapeDesignValues)
示例#4
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)
示例#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 = 1
    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 = -1
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT])
    picturePath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Pictures/'
    resultsPath = os.path.abspath(os.path.join(os.getcwd(),
                                               os.pardir)) + '/Results/'
    policyPath = os.path.abspath(os.path.join(os.getcwd(),
                                              os.pardir)) + '/machinePolicy/'
    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, 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)
    humanController = HumanController(dimension)
    # policy = pickle.load(open(policyPath+"SingleWolfTwoSheepsGrid15.pkl","rb"))
    # modelController = ModelController(policy, dimension,softmaxBeta)
    designValues = UpdateWorld.createDesignValues(condition * 3, block)
    restTrial = list(range(0, len(designValues), len(condition) * 15))
    trial = Trial(humanController, drawNewState, checkBoundary)
    experiment = Experiment(trial, writer, experimentValues, initialWorld,
                            updateWorld, drawImage, resultsPath,
                            minDistanceBetweenGrids, maxDistanceBetweenGrids,
                            restImage, finishImage, restTrial)
    drawImage(introductionImage)
    experiment(designValues)
def main():
    gridSize = 15
    bounds = [1, 1, gridSize - 2, gridSize - 2]
    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 * 30
    block = 1
    textColorTuple = (255, 50, 50)
    stopwatchEvent = pg.USEREVENT + 1
    pg.time.set_timer(stopwatchEvent, stopwatchUnit)
    pg.event.set_allowed([pg.KEYDOWN, pg.QUIT, stopwatchEvent])
    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)
    trial = Trial(humanController, 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)
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)