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))
circleSize = 10 imageHeight = 80 lineWidth = 1 xBoundary = [leaveEdgeSpace, screenWidth - leaveEdgeSpace * 2] yBoundary = [leaveEdgeSpace, screenHeight - leaveEdgeSpace * 2] numOfAgent = 4 screenColor = THECOLORS['black'] circleColorList = [THECOLORS['grey']] * numOfAgent circleSize = 10 lineColor = THECOLORS['white'] textColor = THECOLORS['green'] drawImage = DrawImage(screen, imageHeight) drawText = DrawText(screen) 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)
def main(): numOfAgent = 4 sheepId = 0 wolfId = 1 masterId = 2 distractorId = 3 experimentValues = co.OrderedDict() experimentValues["condition"] = input( "Please enter your condition 1 or 2:").capitalize() experimentValues["name"] = input("Please enter your name:").capitalize() #experimentValues["name"] = 'test' manipulatedHyperVariables = co.OrderedDict() conditionList = [int(experimentValues["condition"])] manipulatedHyperVariables['ChaseConditon'] = conditionList trajetoryIndexList = [0] manipulatedHyperVariables['TrajIndex'] = trajetoryIndexList exprimentVarableList = crateVariableProduct(manipulatedHyperVariables) screenWidth = 800 screenHeight = 800 FPS = 60 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] 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) colorSpace = [ THECOLORS['purple'], THECOLORS['orange'], THECOLORS['red'], THECOLORS['blue'] ] # sheep wolf master distractor # circleColorList = [THECOLORS['grey']] * numOfAgent # circleColorList = [THECOLORS['red'], THECOLORS['green'], THECOLORS['grey'], THECOLORS['yellow']] circleColorList = colorSpace[:numOfAgent] 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, 'report1.png')) finishImage = pygame.image.load(os.path.join(picturePath, 'over.jpg')) introductionImage1 = pygame.transform.scale( introductionImage1, (int(screenWidth * 3 / 4), int(screenHeight / 4))) finishImage = pygame.transform.scale( finishImage, (int(screenWidth * 2 / 3), int(screenHeight / 4))) restImage = pygame.image.load(os.path.join(picturePath, 'rest.jpg')) reportInstrucImage = pygame.image.load( os.path.join(picturePath, 'report2.png')) reportInstrucImage = pygame.transform.scale( reportInstrucImage, (int(screenWidth * 1.4 * 3 / 5), int(screenHeight * 1.7 * 2 / 5))) 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) positionIndex = [0, 1] drawState = DrawState(screen, circleSize, numOfAgent, positionIndex, drawBackGround) # drawStateWithRope = DrawStateWithRope(screen, circleSize, numOfAgent, positionIndex, ropeColor, drawBackground) dataFileDir = '../PataData' 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, 'condition={}'.format(condition) + 'sampleIndex={}.pickle'.format(index))) stimulus = { condition: [ getTrajectory(trajectoryDf(condition, index)) for index in trajetoryIndexList ] for condition in conditionList } writerPath = os.path.join( resultsPath, experimentValues["name"]) + experimentValues["condition"] + '.csv' writer = WriteDataFrameToCSV(writerPath) txtPath = (os.path.join( resultsPath, experimentValues["condition"] + '-' + experimentValues["name"] + '.txt')) openReportTxt = OpenReportTxt(txtPath) displayFrames = 600 trial = ReportTrial(conditionList, displayFrames, drawState, drawImage, stimulus, colorSpace, numOfAgent, drawFixationPoint, drawText, FPS, reportInstrucImage, openReportTxt) experiment = Experiment(trial, writer, experimentValues, drawImage, restImage, drawBackGround, hasRest=False) numOfBlock = 1 numOfTrialsPerBlock = 1 designValues = createDesignValues( exprimentVarableList * numOfTrialsPerBlock, numOfBlock) restDuration = 3 drawImage(introductionImage1) experiment(designValues, restDuration) # drawBackGround() # drawImage(finishImage) print("Result saved at {}".format(txtPath))
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] # [0.0, 2.0] manipulatedVariables['offset'] = [0.0, 1.0] manipulatedVariables['hideId'] = [3, 4] manipulatedVariables['fps'] = [40, 50] manipulatedVariables['displayTime'] = [10, 15] 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()]) ] # catchTrailconditions = [dict(list(specificValueParameter)) for specificValueParameter in it.product(*[[(key, value) for value in values] for key, values in catchTrailVariables.items()])] conditionsWithId = list( zip(range(len(chaseTrailconditions)), chaseTrailconditions)) print(conditionsWithId) conditions = chaseTrailconditions conditions = [ condition.update({'conditionId': condtionId}) for condtionId, condition in zip(range(len(conditions)), conditions) ] chaseTrailNum = 10 chaseTrailTrajetoryIndexList = range(chaseTrailNum) 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()]) # catchTrailNum = 0 # catchTrailTrajetoryIndexList = range (catchTrailNum) # 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 ] [ 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 isShuffle = True designValues = createDesignValues( exprimentVarableList * numOfTrialsPerBlock, numOfBlock, isShuffle) positionIndex = [0, 1] standardFPS = 50 rawXRange = [200, 600] rawYRange = [200, 600] scaledXRange = [200, 600] scaledYRange = [200, 600] scaleTrajectoryInSpace = ScaleTrajectory(positionIndex, rawXRange, rawYRange, scaledXRange, scaledYRange) oldFPS = 50 numFramesToInterpolate = int(standardFPS / oldFPS - 1) interpolateState = InterpolateState(numFramesToInterpolate) scaleTrajectoryInTime = ScaleTrajectoryInTime(interpolateState) horizontalRotationTransformTrajectory = HorizontalRotationTransformTrajectory( positionIndex, rawXRange, rawYRange) rotationTransformTrajectory = RotationTransformTrajectory( positionIndex, rawXRange, rawYRange) def transFormTrajectory(trajList, randomId): randomSeed = np.mod(randomId, 8) rotationAngle = np.mod(randomSeed, 4) * np.pi / 2 rotationTraj = rotationTransformTrajectory(trajList, rotationAngle) # if np.mod(randomSeed//4,2) ==1: # finalTrajs = horizontalRotationTransformTrajectory(rotationTraj) # else: finalTrajs = rotationTraj return finalTrajs trajectoriesSaveDirectory = '../PataData/exp2Traj' # trajectoriesSaveDirectory =os.path.join(dataFolder, 'trajectory', modelSaveName) trajectorySaveExtension = '.pickle' selctDict = {3: chaseTrailNum, 4: chaseTrailNum} evaluateEpisode = 120000 evalNum = 20 fixedParameters = { 'distractorNoise': 3.0, 'evaluateEpisode': evaluateEpisode } generateTrajectoryLoadPath = GetSavePath(trajectoriesSaveDirectory, trajectorySaveExtension, fixedParameters) trajectoryDf = lambda condition: loadFromPickle( generateTrajectoryLoadPath({ 'offset': condition['offset'], 'hideId': condition['hideId'], 'damping': condition['damping'], 'frictionloss': condition['frictionloss'], 'masterForce': condition['masterForce'], 'select': selctDict[condition['hideId']] })) getTrajectory = lambda trajectoryDf: scaleTrajectoryInTime( scaleTrajectoryInSpace(trajectoryDf)) print('loading') # stimulus = {conditionId:getTrajectory(trajectoryDf(condition)) for conditionId,condition in conditionsWithId} # transformedStimulus = { conditionId: transFormTrajectory(getTrajectory(trajectoryDf(condition)), conditionId) for conditionId, condition in conditionsWithId } print('loding success') print(len(transformedStimulus[1])) 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 = 180 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', 'exp2') if not os.path.exists(resultsPath): os.makedirs(resultsPath) introductionImage1 = pygame.image.load( os.path.join(picturePath, 'IdOnlyIntro1.png')) introductionImage2 = pygame.image.load( os.path.join(picturePath, 'IdOnlyIntro2.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) writerPath = os.path.join(resultsPath, experimentValues["name"]) + '.csv' writer = WriteDataFrameToCSV(writerPath) # displayFrames = 500 reactionWindowStart = 50 keysForCheck = {'space': 1} checkHumanResponse = CheckHumanResponseWithSpace(keysForCheck) trial = ChaseTrialMujocoFps(conditionsWithId, reactionWindowStart, drawState, drawImage, transformedStimulus, checkHumanResponse, colorSpace, numOfAgent, drawFixationPoint, drawText, drawImageClick, clickWolfImage, clickSheepImage) experiment = Experiment(trial, writer, experimentValues, drawImage, restImage, drawBackGround) restDuration = 120 drawImage(introductionImage1) drawImage(introductionImage2) experiment(designValues, restDuration) # self.darwBackground() drawImage(finishImage) print("Result saved at {}".format(writerPath))