def main(): # manipulated variables manipulatedVariables = OrderedDict() manipulatedVariables['numWolves'] = [3] manipulatedVariables['numSheep'] = [4] manipulatedVariables['wolfType'] = ['individualReward', 'sharedReward'] manipulatedVariables['sheepConcern'] = ['selfSheep'] levelNames = list(manipulatedVariables.keys()) levelValues = list(manipulatedVariables.values()) modelIndex = pd.MultiIndex.from_product(levelValues, names=levelNames) toSplitFrame = pd.DataFrame(index=modelIndex) productedValues = it.product(*[[(key, value) for value in values] for key, values in manipulatedVariables.items()]) parametersAllCondtion = [dict(list(specificValueParameter)) for specificValueParameter in productedValues] DIRNAME = os.path.dirname(__file__) trajectoryDirectory = os.path.join(DIRNAME, '..', '..', 'data', 'evaluateHierarchyPlanningEnvMADDPG', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) trajectoryExtension = '.pickle' getTrajectorySavePath = lambda trajectoryFixedParameters: GetSavePath(trajectoryDirectory, trajectoryExtension, trajectoryFixedParameters) saveTrajectoryByParameters = lambda trajectories, trajectoryFixedParameters, parameters: saveToPickle(trajectories, getTrajectorySavePath(trajectoryFixedParameters)(parameters)) numTrajectories = 200 sampleTrajectoriesForConditions = SampleTrjactoriesForConditions(numTrajectories, saveTrajectoryByParameters) [sampleTrajectoriesForConditions(para) for para in parametersAllCondtion]
def main(): # manipulated variables manipulatedVariables = OrderedDict() manipulatedVariables['numWolves'] = [3] manipulatedVariables['numSheep'] = [2] # [1, 2, 4] manipulatedVariables['wolfType'] = ['sharedAgencyByIndividualRewardWolf'] manipulatedVariables['perturbedWolfID'] = [0] manipulatedVariables['perturbedWolfGoalID'] = [0, 1] productedValues = it.product(*[[(key, value) for value in values] for key, values in manipulatedVariables.items()]) parametersAllCondtion = [dict(list(specificValueParameter)) for specificValueParameter in productedValues] DIRNAME = os.path.dirname(__file__) trajectoryDirectory = os.path.join(DIRNAME, '..', '..', 'data', 'evaluateGoalPerturbationHighLevel', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) trajectoryExtension = '.pickle' getTrajectorySavePath = lambda trajectoryFixedParameters: GetSavePath(trajectoryDirectory, trajectoryExtension, trajectoryFixedParameters) saveTrajectoryByParameters = lambda trajectories, trajectoryFixedParameters, parameters: saveToPickle(trajectories, getTrajectorySavePath( trajectoryFixedParameters)( parameters)) numTrajectories = 20 sampleTrajectoriesForConditions = SampleTrjactoriesForConditions(numTrajectories, saveTrajectoryByParameters) [sampleTrajectoriesForConditions(para) for para in parametersAllCondtion]
def main(): # manipulated variables manipulatedVariables = OrderedDict() manipulatedVariables['numWolves'] = [2] # temp just 2 manipulatedVariables['numSheep'] = [1] # temp just 1 manipulatedVariables['inferenceSoft'] = [0.05, 0.1] manipulatedVariables['wolfPolicySoft'] = [1.5, 2.0] manipulatedVariables['otherCompeteRate'] = [ 1.0 ] # 0 never compete, 1 always compete manipulatedVariables['competeDetectionRate'] = [ 0.5 ] # 0 never detect compete, 1 only detect compete levelNames = list(manipulatedVariables.keys()) levelValues = list(manipulatedVariables.values()) modelIndex = pd.MultiIndex.from_product(levelValues, names=levelNames) toSplitFrame = pd.DataFrame(index=modelIndex) productedValues = it.product( *[[(key, value) for value in values] for key, values in manipulatedVariables.items()]) parametersAllCondtion = [ dict(list(specificValueParameter)) for specificValueParameter in productedValues ] DIRNAME = os.path.dirname(__file__) trajectoryDirectory = os.path.join(DIRNAME, '..', '..', 'data', 'evaluateCompeteDetection', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) trajectoryExtension = '.pickle' getTrajectorySavePath = lambda trajectoryFixedParameters: GetSavePath( trajectoryDirectory, trajectoryExtension, trajectoryFixedParameters) saveTrajectoryByParameters = lambda trajectories, trajectoryFixedParameters, parameters: saveToPickle( trajectories, getTrajectorySavePath(trajectoryFixedParameters)(parameters)) numTrajectories = 200 sampleTrajectoriesForConditions = SampleTrjactoriesForConditions( numTrajectories, saveTrajectoryByParameters) [sampleTrajectoriesForConditions(para) for para in parametersAllCondtion]
def main(): # manipulated variables manipulatedVariables = OrderedDict() manipulatedVariables['numWolves'] = [2, 3] levelNames = list(manipulatedVariables.keys()) levelValues = list(manipulatedVariables.values()) modelIndex = pd.MultiIndex.from_product(levelValues, names=levelNames) toSplitFrame = pd.DataFrame(index=modelIndex) productedValues = it.product(*[[(key, value) for value in values] for key, values in manipulatedVariables.items()]) parametersAllCondtion = [dict(list(specificValueParameter)) for specificValueParameter in productedValues] DIRNAME = os.path.dirname(__file__) trajectoryDirectory = os.path.join(DIRNAME, '..', '..', 'data', 'diagnoseAnalysis', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) trajectoryExtension = '.pickle' getTrajectorySavePath = lambda trajectoryFixedParameters: GetSavePath(trajectoryDirectory, trajectoryExtension, trajectoryFixedParameters) saveTrajectoryByParameters = lambda trajectories, trajectoryFixedParameters, parameters: saveToPickle(trajectories, getTrajectorySavePath(trajectoryFixedParameters)(parameters)) numTrajectories = 10000 sampleTrajectoriesForConditions = SampleTrjactoriesForConditions(numTrajectories, saveTrajectoryByParameters) inSmallRangeRateMeans = [sampleTrajectoriesForConditions(para) for para in parametersAllCondtion] toSplitFrame['inSmallRangeRate'] = inSmallRangeRateMeans toSplitFrame.plot.bar(y = 'inSmallRangeRate', ylim = (0, 1)) plt.show() plt.suptitle('Is hierarchical planned action in small range?')
def main(): load = 1 manipulatedVariables = OrderedDict() manipulatedVariables['numWolves'] = [3] manipulatedVariables['numSheep'] = [1, 2, 4] manipulatedVariables['sheepConcern'] = ['selfSheep'] manipulatedVariables['wolfType'] = ['sharedAgencyByIndividualRewardWolf'] manipulatedVariables['perturbAgentID'] = [0, 1, 2] manipulatedVariables['perturbQuantile'] = [0.3, 0.4, 0.5, 0.6, 0.7] manipulatedVariables['perturbDim'] = [0, 1] manipulatedVariables['interestedDim'] = [0, 1] manipulatedVariables['interestedAgentID'] = [0, 1, 2] resultPath = os.path.join(dirName, '..', '..', 'evalResults') if not os.path.exists(resultPath): os.makedirs(resultPath) resultLoc = os.path.join(resultPath, 'evalPerturbResult.pkl') if not load: levelNames = list(manipulatedVariables.keys()) levelValues = list(manipulatedVariables.values()) modelIndex = pd.MultiIndex.from_product(levelValues, names=levelNames) toSplitFrame = pd.DataFrame(index=modelIndex) statisticsDf = toSplitFrame.groupby(levelNames).apply(evalPerturbationPercent) print(statisticsDf) saveToPickle(statisticsDf, resultLoc) else: statisticsDf = loadFromPickle(resultLoc) # print(statisticsDf) toSplitFrame = statisticsDf.groupby(['numWolves', 'numSheep', 'sheepConcern', 'wolfType', 'perturbAgentID', 'perturbQuantile', 'interestedAgentID']).apply(np.mean) resultDF = toSplitFrame[toSplitFrame.index.get_level_values('perturbAgentID') != toSplitFrame.index.get_level_values('interestedAgentID')] print(resultDF) figure = plt.figure(figsize=(10, 10)) plotCounter = 1 numRows = len(manipulatedVariables['numSheep'])# numColumns = len(manipulatedVariables['perturbAgentID']) for key, outmostSubDf in resultDF.groupby('numSheep'):# outmostSubDf.index = outmostSubDf.index.droplevel('numSheep')# for keyCol, outterSubDf in outmostSubDf.groupby('perturbAgentID'): outterSubDf.index = outterSubDf.index.droplevel('perturbAgentID') axForDraw = figure.add_subplot(numRows, numColumns, plotCounter) for keyRow, innerSubDf in outterSubDf.groupby('interestedAgentID'): innerSubDf.index = innerSubDf.index.droplevel('interestedAgentID') innerSubDf.plot.line(ax = axForDraw, y='mean', label = keyRow) if plotCounter <= numColumns: axForDraw.title.set_text('Perturbed Agent = ' + str(keyCol) ) if plotCounter% numColumns == 1: axForDraw.set_ylabel('Number of Sheep = ' + str(key)) axForDraw.set_xlabel('Perturbation Quantile') # print(innerSubDf) plotCounter += 1 # plt.xlim([0.3, 0.7]) if key == 1: plt.ylim([10, 25]) elif key == 2: plt.ylim([30, 140]) else: plt.ylim([80, 165]) plt.xticks([0, 1, 2, 3, 4], manipulatedVariables['perturbQuantile'])#[0.3, 0.4, 0.5, 0.6, 0.7] plt.legend(title='Effect on Agent', title_fontsize = 8, prop={'size': 8}) # figure.text(x=0.03, y=0.5, s='Mean Episode Kill', ha='center', va='center', rotation=90) # plt.suptitle('MADDPG Evaluate predatorSelfishness/ preySpeed/ actionCost') # plt.savefig(os.path.join(resultPath, 'evalRewardWithKillProbAndDistSensitiveNoBiteRewKillInfo_killNum_allcond_regroup')) plt.show()