def testCheckHumanResponse(self, initialTime, results, pause, groudTruthResults, groudTruthPause): checkHumanResponse = CheckHumanResponse(self.keysForCheck) returnedResults, returnedPause = checkHumanResponse(initialTime, results, pause) print(returnedResults, returnedPause) truthValue = returnedResults['response'] == groudTruthResults['response'] self.assertTrue(truthValue) self.assertTrue(int(returnedResults['reactionTime']) > int(groudTruthResults['reactionTime'])) self.assertEqual(returnedPause, groudTruthPause)
def main(): numOfAgent = 4 manipulatedVariables = co.OrderedDict() # manipulatedVariables['damping'] = [0.0] # [0.0, 1.0] # manipulatedVariables['frictionloss'] = [0.0] # [0.0, 0.2, 0.4] # manipulatedVariables['masterForce'] = [0.0] manipulatedVariables['damping'] = [0.0, 0.5] # [0.0, 1.0] manipulatedVariables['frictionloss'] = [1.0] # [0.0, 0.2, 0.4] manipulatedVariables['masterForce'] = [0.0, 1.0] # [0.0, 2.0] chaseTrailVariables = manipulatedVariables.copy() catchTrailVariables = manipulatedVariables.copy() chaseTrailVariables['hideId'] = [3, 4 ] #0 wolf 1 sheep 2 master 3 4 distractor catchTrailVariables['hideId'] = [1] chaseTrailconditions = [ dict(list(specificValueParameter)) for specificValueParameter in it.product( *[[(key, value) for value in values] for key, values in chaseTrailVariables.items()]) ] # chaseTrailconditionsWithId =list (zip(range(len(conditions)),conditions )) catchTrailconditions = [ dict(list(specificValueParameter)) for specificValueParameter in it.product( *[[(key, value) for value in values] for key, values in catchTrailVariables.items()]) ] # catchTrailconditionsWithId =list (zip(range(len(conditions)),conditions )) # print('state',chaseTrailVariables,catchTrailVariables) conditionsWithId = list( zip(range(len(chaseTrailconditions) + len(catchTrailconditions)), chaseTrailconditions + catchTrailconditions)) # print(conditionsWithId) # conditions = [dict(list(specificValueParameter)) for specificValueParameter in it.product(*[[(key, value) for value in values] for key, values in manipulatedVariables.items()])] # conditionsWithId =list (zip(range(len(conditions)),conditions )) # print(conditionsWithId) conditions = chaseTrailconditions + catchTrailconditions conditions = [ condition.update({'conditionId': condtionId}) for condtionId, condition in zip(range(len(conditions)), conditions) ] # print (conditions) chaseTrailTrajetoryIndexList = range(2) chaseTrailManipulatedVariablesForExp = co.OrderedDict() chaseTrailManipulatedVariablesForExp['conditonId'] = range( len(chaseTrailconditions)) chaseTrailManipulatedVariablesForExp[ 'trajetoryIndex'] = chaseTrailTrajetoryIndexList chaseTrailProductedValues = it.product( *[[(key, value) for value in values] for key, values in chaseTrailManipulatedVariablesForExp.items()]) catchTrailTrajetoryIndexList = range(1) catchTrailManipulatedVariablesForExp = co.OrderedDict() catchTrailManipulatedVariablesForExp['conditonId'] = range( len(chaseTrailconditions), len(chaseTrailconditions) + len(catchTrailconditions)) catchTrailManipulatedVariablesForExp[ 'trajetoryIndex'] = catchTrailTrajetoryIndexList catchTrailProductedValues = it.product( *[[(key, value) for value in values] for key, values in catchTrailManipulatedVariablesForExp.items()]) # print(productedValues) exprimentVarableList = [ dict(list(specificValueParameter)) for specificValueParameter in chaseTrailProductedValues ] + [ dict(list(specificValueParameter)) for specificValueParameter in catchTrailProductedValues ] [ exprimentVarable.update( {'condition': conditionsWithId[exprimentVarable['conditonId']][1]}) for exprimentVarable in exprimentVarableList ] # exprimentVarableList = [exprimentVarable.update({'condition': conditionsWithId[exprimentVarable['conditonId']][1]}) for exprimentVarable in exprimentVarableList ] print(exprimentVarableList) print(len(exprimentVarableList)) numOfBlock = 1 numOfTrialsPerBlock = 1 designValues = createDesignValues( exprimentVarableList * numOfTrialsPerBlock, numOfBlock) positionIndex = [0, 1] FPS = 50 rawXRange = [-1, 1] rawYRange = [-1, 1] scaledXRange = [200, 600] scaledYRange = [200, 600] scaleTrajectoryInSpace = ScaleTrajectory(positionIndex, rawXRange, rawYRange, scaledXRange, scaledYRange) oldFPS = 50 numFramesToInterpolate = int(FPS / oldFPS - 1) interpolateState = InterpolateState(numFramesToInterpolate) scaleTrajectoryInTime = ScaleTrajectoryInTime(interpolateState) trajectoriesSaveDirectory = '../PataData/mujoco50Fps4Agent' # trajectoriesSaveDirectory =os.path.join(dataFolder, 'trajectory', modelSaveName) trajectorySaveExtension = '.pickle' evaluateEpisode = 120000 evalNum = 20 fixedParameters = { 'distractorNoise': 3.0, 'evaluateEpisode': evaluateEpisode } generateTrajectoryLoadPath = GetSavePath(trajectoriesSaveDirectory, trajectorySaveExtension, fixedParameters) trajectoryDf = lambda condition: pd.read_pickle( generateTrajectoryLoadPath({ 'hideId': condition['hideId'], 'damping': condition['damping'], 'frictionloss': condition['frictionloss'], 'masterForce': condition['masterForce'], 'evalNum': evalNum, })) # trajectoryDf = lambda condition: pd.read_pickle(generateTrajectoryLoadPath(condition)) getTrajectory = lambda trajectoryDf: scaleTrajectoryInTime( scaleTrajectoryInSpace(trajectoryDf)) # getTrajectory = lambda trajectoryDf: scaleTrajectoryInSpace(trajectoryDf) print('loading') stimulus = { conditionId: getTrajectory(trajectoryDf(condition)) for conditionId, condition in conditionsWithId } print(stimulus[0][0][0]) print(stimulus[10][0][0]) print('loding success') # print(stimulus[1][1]) experimentValues = co.OrderedDict() experimentValues["name"] = input("Please enter your name:").capitalize() screenWidth = 800 screenHeight = 800 fullScreen = False initializeScreen = InitializeScreen(screenWidth, screenHeight, fullScreen) screen = initializeScreen() leaveEdgeSpace = 200 circleSize = 10 clickImageHeight = 80 lineWidth = 3 fontSize = 50 xBoundary = [leaveEdgeSpace, screenWidth - leaveEdgeSpace * 2] yBoundary = [leaveEdgeSpace, screenHeight - leaveEdgeSpace * 2] screenColor = THECOLORS['black'] lineColor = THECOLORS['white'] textColor = THECOLORS['white'] fixationPointColor = THECOLORS['white'] colorSpace = [(203, 164, 4, 255), (49, 153, 0, 255), (255, 90, 16, 255), (251, 7, 255, 255), (9, 204, 172, 255), (3, 28, 255, 255)] picturePath = os.path.join( os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'pictures') resultsPath = os.path.join( os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'results') introductionImage1 = pygame.image.load( os.path.join(picturePath, 'mujocoIntro1.png')) introductionImage2 = pygame.image.load( os.path.join(picturePath, 'mujocoIntro2.png')) finishImage = pygame.image.load(os.path.join(picturePath, 'over.jpg')) introductionImage1 = pygame.transform.scale(introductionImage1, (screenWidth, screenHeight)) introductionImage2 = pygame.transform.scale(introductionImage2, (screenWidth, screenHeight)) finishImage = pygame.transform.scale( finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4))) clickWolfImage = pygame.image.load( os.path.join(picturePath, 'clickwolf.png')) clickSheepImage = pygame.image.load( os.path.join(picturePath, 'clicksheep.png')) restImage = pygame.image.load(os.path.join(picturePath, 'rest.jpg')) drawImage = DrawImage(screen) drawText = DrawText(screen, fontSize, textColor) drawBackGround = DrawBackGround(screen, screenColor, xBoundary, yBoundary, lineColor, lineWidth) drawFixationPoint = DrawFixationPoint(screen, drawBackGround, fixationPointColor) drawImageClick = DrawImageClick(screen, clickImageHeight, drawText) drawState = DrawState(screen, circleSize, numOfAgent, positionIndex, drawBackGround) # drawStateWithRope = DrawStateWithRope(screen, circleSize, numOfAgent, positionIndex, ropeColor, drawBackground) writerPath = os.path.join(resultsPath, experimentValues["name"]) + '.csv' writer = WriteDataFrameToCSV(writerPath) displayFrames = 500 keysForCheck = {'f': 0, 'j': 1} checkHumanResponse = CheckHumanResponse(keysForCheck) trial = ChaseTrialMujoco(conditionsWithId, displayFrames, drawState, drawImage, stimulus, checkHumanResponse, colorSpace, numOfAgent, drawFixationPoint, drawText, drawImageClick, clickWolfImage, clickSheepImage, FPS) experiment = Experiment(trial, writer, experimentValues, drawImage, restImage, drawBackGround) restDuration = 20 drawImage(introductionImage1) drawImage(introductionImage2) experiment(designValues, restDuration) # self.darwBackground() drawImage(finishImage) print("Result saved at {}".format(writerPath))
def main(): screenWidth = 800 screenHeight = 800 FPS = 60 fullScreen = False initializeScreen = InitializeScreen(screenWidth, screenHeight, fullScreen) screen = initializeScreen() saveImage = False saveImageFile = 'noRopeCondition1' numOfAgent = 4 leaveEdgeSpace = 200 circleSize = 10 clickImageHeight = 80 lineWidth = 3 fontSize = 50 xBoundary = [leaveEdgeSpace, screenWidth - leaveEdgeSpace * 2] yBoundary = [leaveEdgeSpace, screenHeight - leaveEdgeSpace * 2] stimulusXBoundary = [xBoundary[0] + circleSize, xBoundary[1] - circleSize] stimulusYBoundary = [yBoundary[0] + circleSize, yBoundary[1] - circleSize] screenColor = THECOLORS['black'] lineColor = THECOLORS['white'] textColor = THECOLORS['white'] fixationPointColor = THECOLORS['white'] ropeColor = THECOLORS['white'] colorSpace = [ THECOLORS['grey'], THECOLORS['red'], THECOLORS['blue'], THECOLORS['yellow'], THECOLORS['purple'], THECOLORS['orange'] ] random.shuffle(colorSpace) # circleColorList = [THECOLORS['grey']] * numOfAgent # circleColorList = [THECOLORS['red'], THECOLORS['green'], THECOLORS['grey'], THECOLORS['yellow']] circleColorList = colorSpace[:numOfAgent] stateIndex = ['wolf', 'sheep', 'master', 'distractor'] identityColorPairs = dict(zip(stateIndex, circleColorList)) picturePath = os.path.join( os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'pictures') resultsPath = os.path.join( os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'results') introductionImage = pygame.image.load( os.path.join(picturePath, 'introduction2.png')) finishImage = pygame.image.load(os.path.join(picturePath, 'over.jpg')) introductionImage = pygame.transform.scale(introductionImage, (screenWidth, screenHeight)) finishImage = pygame.transform.scale( finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4))) clickWolfImage = pygame.image.load( os.path.join(picturePath, 'clickwolf.png')) clickSheepImage = pygame.image.load( os.path.join(picturePath, 'clicksheep.png')) restImage = pygame.image.load(os.path.join(picturePath, 'rest.jpg')) # restImage = pygame.transform.scale(restImage, (screenWidth, screenHeight)) drawImage = DrawImage(screen) drawText = DrawText(screen, fontSize, textColor) drawBackGround = DrawBackGround(screen, screenColor, xBoundary, yBoundary, lineColor, lineWidth) drawFixationPoint = DrawFixationPoint(screen, drawBackGround, fixationPointColor) drawImageClick = DrawImageClick(screen, clickImageHeight, drawText) drawState = DrawState(drawBackGround, numOfAgent, screen, circleSize) drawStateWithRope = DrawStateWithRope(drawBackGround, numOfAgent, screen, circleSize, ropeColor) conditionList = [1] #[1, 2, 3, 4] trajetoryIndexList = [1] # [1, 2, 3, 4, 5] dataFileDir = '../PataData' dataSetBoundary = [26, 26] generateTrajetoryData = GenerateTrajetoryData(dataFileDir, stimulusXBoundary, stimulusYBoundary, dataSetBoundary) stimulus = { condition: generateTrajetoryData(condition, trajetoryIndexList) for condition in conditionList } experimentValues = co.OrderedDict() # experimentValues["name"] = input("Please enter your name:").capitalize() experimentValues["name"] = 'csz' writerPath = os.path.join(resultsPath, experimentValues["name"]) + '.csv' writer = WriteDataFrameToCSV(writerPath) displayFrames = FPS * 3 keysForCheck = {'f': 0, 'j': 1} checkHumanResponse = CheckHumanResponse(keysForCheck) trial = ChaseTrial(displayFrames, drawState, drawImage, stimulus, checkHumanResponse, colorSpace, numOfAgent, drawFixationPoint, drawText, drawImageClick, clickWolfImage, clickSheepImage, FPS, saveImage, saveImageFile) experiment = Experiment(trial, writer, experimentValues, drawImage, restImage) numOfBlock = 2 numOfTrialsPerBlock = 1 designValues = createDesignValues(conditionList * numOfTrialsPerBlock, numOfBlock) print(designValues) drawImage(introductionImage) experiment(designValues, numOfTrialsPerBlock) # drawImage(finishImage) print("Result saved at {}".format(writerPath))
def main(): numOfAgent = 4 manipulatedHyperVariables = co.OrderedDict() conditionList = [1, 2] #0;practice 1:off=0 2:off=12 manipulatedHyperVariables['ChaseCondition'] = conditionList trajetoryIndexList = range(20) manipulatedHyperVariables['TrajIndex'] = trajetoryIndexList exprimentVarableList = crateVariableProduct(manipulatedHyperVariables) print('loading') positionIndex = [0, 1] FPS = 60 dataFileDir = '../PataData/withoutLine' rawXRange = [-10, 10] rawYRange = [-10, 10] scaledXRange = [200, 600] scaledYRange = [200, 600] scaleTrajectory = ScaleTrajectory(positionIndex, rawXRange, rawYRange, scaledXRange, scaledYRange) oldFPS = 5 adjustFPS = AdjustDfFPStoTraj(oldFPS, FPS) getTrajectory = lambda trajectoryDf: scaleTrajectory( adjustFPS(trajectoryDf)) trajectoryDf = lambda condition, index: pd.read_pickle( os.path.join(dataFileDir, '{}'.format(condition) + ' ({}).pickle'. format(index))) stimulus = { condition: [ getTrajectory(trajectoryDf(condition, index)) for index in trajetoryIndexList ] for condition in conditionList } print('loding success') experimentValues = co.OrderedDict() experimentValues["name"] = input("Please enter your name:").capitalize() screenWidth = 800 screenHeight = 800 fullScreen = True initializeScreen = InitializeScreen(screenWidth, screenHeight, fullScreen) screen = initializeScreen() leaveEdgeSpace = 200 circleSize = 10 clickImageHeight = 80 lineWidth = 3 fontSize = 50 xBoundary = [leaveEdgeSpace, screenWidth - leaveEdgeSpace * 2] yBoundary = [leaveEdgeSpace, screenHeight - leaveEdgeSpace * 2] screenColor = THECOLORS['black'] lineColor = THECOLORS['white'] textColor = THECOLORS['white'] fixationPointColor = THECOLORS['white'] colorSpace = [(203, 164, 4, 255), (49, 153, 0, 255), (255, 90, 16, 255), (251, 7, 255, 255), (9, 204, 172, 255), (3, 28, 255, 255)] picturePath = os.path.join( os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'pictures') resultsPath = os.path.join( os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'results') introductionImage1 = pygame.image.load( os.path.join(picturePath, 'introduction1.png')) introductionImage2 = pygame.image.load( os.path.join(picturePath, 'introduction2.png')) finishImage = pygame.image.load(os.path.join(picturePath, 'over.jpg')) introductionImage1 = pygame.transform.scale(introductionImage1, (screenWidth, screenHeight)) introductionImage2 = pygame.transform.scale(introductionImage2, (screenWidth, screenHeight)) finishImage = pygame.transform.scale( finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4))) clickWolfImage = pygame.image.load( os.path.join(picturePath, 'clickwolf.png')) clickSheepImage = pygame.image.load( os.path.join(picturePath, 'clicksheep.png')) restImage = pygame.image.load(os.path.join(picturePath, 'rest.jpg')) drawImage = DrawImage(screen) drawText = DrawText(screen, fontSize, textColor) drawBackGround = DrawBackGround(screen, screenColor, xBoundary, yBoundary, lineColor, lineWidth) drawFixationPoint = DrawFixationPoint(screen, drawBackGround, fixationPointColor) drawImageClick = DrawImageClick(screen, clickImageHeight, drawText) drawState = DrawState(screen, circleSize, numOfAgent, positionIndex, drawBackGround) # drawStateWithRope = DrawStateWithRope(screen, circleSize, numOfAgent, positionIndex, ropeColor, drawBackground) writerPath = os.path.join(resultsPath, experimentValues["name"]) + '.csv' writer = WriteDataFrameToCSV(writerPath) displayFrames = 600 keysForCheck = {'f': 0, 'j': 1} checkHumanResponse = CheckHumanResponse(keysForCheck) trial = ChaseTrial(conditionList, displayFrames, drawState, drawImage, stimulus, checkHumanResponse, colorSpace, numOfAgent, drawFixationPoint, drawText, drawImageClick, clickWolfImage, clickSheepImage, FPS) experiment = Experiment(trial, writer, experimentValues, drawImage, restImage, drawBackGround) numOfBlock = 1 numOfTrialsPerBlock = 1 designValues = createDesignValues( exprimentVarableList * numOfTrialsPerBlock, numOfBlock) restDuration = 20 drawImage(introductionImage1) drawImage(introductionImage2) experiment(designValues, restDuration) # self.darwBackground() drawImage(finishImage) print("Result saved at {}".format(writerPath))
drawImageClick = DrawImageClick(screen, imageHeight, circleColorList, drawText) drawBackground = DrawBackground(screen, xBoundary, yBoundary, lineColor, lineWidth) drawState = DrawState(drawBackground, numOfAgent, screen, screenColor, circleColorList, circleSize) picturePath = os.path.join( os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'pictures') keysForCheck = {'f': 0, 'j': 1} clickWolfImage = pygame.image.load( os.path.join(picturePath, 'clickwolf.png')) clickSheepImage = pygame.image.load( os.path.join(picturePath, 'clicksheep.png')) checkHumanResponse = CheckHumanResponse(keysForCheck, drawImageClick, clickWolfImage, clickSheepImage) displayFrames = 10 stimulusXBoundary = [xBoundary[0] + circleSize, xBoundary[1] - circleSize] stimulusYBoundary = [yBoundary[0] + circleSize, yBoundary[1] - circleSize] sampleTrajectory = lambda numOfAgent, displayFrames: [[ samplePosition(stimulusXBoundary, stimulusYBoundary) for i in range(numOfAgent) ] for j in range(displayFrames)] stimulus = { 1: sampleTrajectory(numOfAgent, displayFrames), 2: sampleTrajectory(numOfAgent, displayFrames), 3: sampleTrajectory(numOfAgent, displayFrames), 4: sampleTrajectory(numOfAgent, displayFrames) }