def main(): manipulatedVariables = OrderedDict() manipulatedVariables['alphaForStateWidening'] = [0.25, 0.5, 0.75] #manipulatedVariables['attentionType'] = ['idealObserver'] manipulatedVariables['attentionType'] = ['hybrid4'] #manipulatedVariables['attentionType'] = ['preAttention', 'attention4', 'hybrid4'] manipulatedVariables['CForStateWidening'] = [2] manipulatedVariables['minAttentionDistance'] = [7.5, 10.5, 13.5] manipulatedVariables['rangeAttention'] = [2, 4, 8] manipulatedVariables['numTrees'] = [2] manipulatedVariables['numSimulationTimes'] = [33] 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', 'mcts', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) trajectoryExtension = '.pickle' getTrajectorySavePathByCondition = lambda condition: tsl.GetSavePath(trajectoryDirectory, trajectoryExtension, condition) measurementEscapeExtension = '.csv' getCSVSavePathByCondition = lambda condition: tsl.GetSavePath(trajectoryDirectory, measurementEscapeExtension, condition) runOneCondition = RunOneCondition(getTrajectorySavePathByCondition, getCSVSavePathByCondition) #runOneCondition(parametersAllCondtion[0]) numCpuCores = os.cpu_count() numCpuToUse = int(0.9 * numCpuCores) runPool = mp.Pool(numCpuToUse) runPool.map(runOneCondition, parametersAllCondtion) precisionToSubtletyDict={500:0,50:5,11:30,3.3:60,1.83:90,0.92:120,0.31:150,0.001: 180}
def main(): manipulatedVariables = OrderedDict() manipulatedVariables['alpha'] = [0.25] manipulatedVariables['attType'] = ['idealObserver', 'hybrid4'] #manipulatedVariables['attType'] = ['hybrid4']#, 'preAttention'] #manipulatedVariables['attType'] = ['preAttention'] #manipulatedVariables['attType'] = ['idealObserver', 'preAttention', 'attention4', 'hybrid4'] #manipulatedVariables['attType'] = ['preAttentionMem0.65', 'preAttentionMem0.25', 'preAttentionPre0.5', 'preAttentionPre4.5'] manipulatedVariables['C'] = [2] manipulatedVariables['minAttDist'] = [5.0, 10.0, 20.0, 40.0] manipulatedVariables['rangeAtt'] = [5.0, 20.0] manipulatedVariables['cBase'] = [50] manipulatedVariables['numTrees'] = [4] manipulatedVariables['numSim'] = [154] manipulatedVariables['actRatio'] = [1.0] manipulatedVariables['burnTime'] = [0] manipulatedVariables['softId'] = [1.0] manipulatedVariables['softSubtlety'] = [1.0] manipulatedVariables['actCost'] = [0.05, 0.1, 0.15, 0.2] manipulatedVariables['damp'] = [1.0] 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', 'mcts', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) trajectoryExtension = '.pickle' getTrajectorySavePathByCondition = lambda condition: tsl.GetSavePath( trajectoryDirectory, trajectoryExtension, condition) measurementEscapeExtension = '.csv' getCSVSavePathByCondition = lambda condition: tsl.GetSavePath( trajectoryDirectory, measurementEscapeExtension, condition) runOneCondition = RunOneCondition(getTrajectorySavePathByCondition, getCSVSavePathByCondition) #runOneCondition(parametersAllCondtion[0]) numCpuCores = os.cpu_count() numCpuToUse = int(numCpuCores) runPool = mp.Pool(numCpuToUse) runPool.map(runOneCondition, parametersAllCondtion) precisionToSubtletyDict = { 500: 0, 50: 5, 11: 30, 3.3: 60, 1.83: 90, 0.92: 120, 0.31: 150, 0.001: 180 }
def main(): manipulatedVariables = OrderedDict() manipulatedVariables['alpha'] = [0.25] #manipulatedVariables['attType'] = ['idealObserver']#, 'hybrid4'] #manipulatedVariables['attType'] = ['hybrid4']#, 'preAttention'] #manipulatedVariables['attType'] = ['preAttention'] manipulatedVariables['attType'] = ['idealObserver', 'preAttention', 'attention4', 'hybrid4'] #manipulatedVariables['attType'] = ['preAttentionMem0.65', 'preAttentionMem0.25', 'preAttentionPre0.5', 'preAttentionPre4.5'] manipulatedVariables['C'] = [2] manipulatedVariables['minAttDist'] = [10.0, 40.0]#[10.0, 20.0, 40.0] manipulatedVariables['rangeAtt'] = [10.0] manipulatedVariables['cBase'] = [50] manipulatedVariables['numTrees'] = [2] manipulatedVariables['numSim'] = [144] manipulatedVariables['actRatio'] = [1.0] manipulatedVariables['burnTime'] = [0] manipulatedVariables['softId'] = [1] manipulatedVariables['softSubtlety'] = [1] manipulatedVariables['actCost'] = [0.1, 0.4, 0.7, 1.0] manipulatedVariables['damp'] = [0.0] manipulatedVariables['measure'] = ['escape'] 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', 'mcts', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) measurementEscapeExtension = '.csv' getCSVSavePathByCondition = lambda condition: tsl.GetSavePath(trajectoryDirectory, measurementEscapeExtension, condition) #columnNames = [500.0, 11.0, 3.3, 1.83, 0.92, 0.31, 0.001] #columnNames = [500.0, 3.3, 0.92] columnNames = [500.0, 3.3, 0.92, 0.01] readcsv = Readcsv(getCSVSavePathByCondition, columnNames) precisionToSubtletyDict={500.0:0, 50.0:5, 11.0:30, 3.3:60, 1.83:90, 0.92:120, 0.31:150, 0.01: 180} levelNames = list(manipulatedVariables.keys()) levelValues = list(manipulatedVariables.values()) modelIndex = pd.MultiIndex.from_product(levelValues, names=levelNames) toSplitFrame = pd.DataFrame(index = modelIndex) modelResultDf = toSplitFrame.groupby(levelNames).apply(readcsv) toDropLevels = ['alpha', 'C', 'cBase', 'numTrees', 'rangeAtt', 'damp', 'burnTime', 'softId', 'softSubtlety', 'measure', 'actRatio', 'numSim'] modelResultDf.index = modelResultDf.index.droplevel(toDropLevels) fig = plt.figure() numColumns = len(manipulatedVariables['actCost']) numRows = len(manipulatedVariables['minAttDist']) plotCounter = 1 for key, group in modelResultDf.groupby(['minAttDist', 'actCost']): columnNamesAsSubtlety = [precisionToSubtletyDict[precision] for precision in group.columns] group.columns = columnNamesAsSubtlety group = group.stack() group.index.names = ['attType', 'actCost', 'minAttDist', 'chasingSubtlety'] group.index = group.index.droplevel(['actCost', 'minAttDist']) group = group.to_frame() group.columns = ['model'] axForDraw = fig.add_subplot(numRows, numColumns, plotCounter) if (plotCounter) % max(numColumns, 2) == 1: axForDraw.set_ylabel(str(key[0])) if plotCounter <= numColumns: axForDraw.set_title(str(key[1])) for attentionType, grp in group.groupby('attType'): grp.index = grp.index.droplevel('attType') #if str(attentionType) == manipulatedVariables['attType'][-1]: # grp['human'] = [0.24, 0.51] # grp['human'] = [0.6, 0.48, 0.37, 0.25, 0.24, 0.42, 0.51] # grp.plot.line(ax = axForDraw, y = 'human', label = 'human', ylim = (0, 0.7), marker = 'o', rot = 0 ) grp.plot.line(ax = axForDraw, y = 'model', label = str(attentionType), ylim = (0, 1.1), marker = 'o', rot = 0 ) plotCounter = plotCounter + 1 #plt.suptitle('Measurement = Perception Rate') #plt.suptitle('Measurement = Action Deviation') #plt.suptitle('Measurement = Velocity Diff') plt.suptitle('Measurement = Escape rate') fig.text(x = 0.5, y = 0.92, s = 'Action Cost', ha = 'center', va = 'center') #fig.text(x = 0.5, y = 0.92, s = 'Min Attention Distance', ha = 'center', va = 'center') #fig.text(x = 0.05, y = 0.5, s = 'Attention Range', ha = 'center', va = 'center', rotation=90) fig.text(x = 0.05, y = 0.5, s = 'minAttDist', ha = 'center', va = 'center', rotation=90) plt.show()
def main(): manipulatedVariables = OrderedDict() manipulatedVariables['alphaForStateWidening'] = [0.25] #manipulatedVariables['attentionType'] = ['idealObserver'] manipulatedVariables['attentionType'] = ['hybrid4'] #manipulatedVariables['attentionType'] = ['preAttention', 'attention4', 'hybrid4'] manipulatedVariables['CForStateWidening'] = [2] manipulatedVariables['minAttentionDistance'] = [6.5, 11.5, 16.5] manipulatedVariables['rangeAttention'] = [2, 4, 8] manipulatedVariables['cBase'] = [50] manipulatedVariables['numTrees'] = [2] manipulatedVariables['numSimulationTimes'] = [74] manipulatedVariables['actionRatio'] = [0.2] manipulatedVariables['burnTime'] = [3, 6, 12] 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', 'mcts', 'trajectories') if not os.path.exists(trajectoryDirectory): os.makedirs(trajectoryDirectory) measurementEscapeExtension = '.csv' getCSVSavePathByCondition = lambda condition: tsl.GetSavePath( trajectoryDirectory, measurementEscapeExtension, condition) columnNames = [500.0, 3.3, 1.83, 0.92, 0.001] readcsv = Readcsv(getCSVSavePathByCondition, columnNames) precisionToSubtletyDict = { 500.0: 0, 50.0: 5, 11: 30, 3.3: 60, 1.83: 90, 0.92: 120, 0.31: 150, 0.001: 180 } levelNames = list(manipulatedVariables.keys()) levelValues = list(manipulatedVariables.values()) modelIndex = pd.MultiIndex.from_product(levelValues, names=levelNames) toSplitFrame = pd.DataFrame(index=modelIndex) modelResultDf = toSplitFrame.groupby(levelNames).apply(readcsv) toDropLevels = [ 'alphaForStateWidening', 'attentionType', 'CForStateWidening', 'cBase', 'numTrees', 'numSimulationTimes', 'actionRatio' ] modelResultDf.index = modelResultDf.index.droplevel(toDropLevels) fig = plt.figure() numColumns = len(manipulatedVariables['minAttentionDistance']) numRows = len(manipulatedVariables['rangeAttention']) plotCounter = 1 for key, group in modelResultDf.groupby( ['rangeAttention', 'minAttentionDistance']): columnNamesAsSubtlety = [ precisionToSubtletyDict[precision] for precision in group.columns ] group.columns = columnNamesAsSubtlety group = group.stack() group.index.names = [ 'rangeAttention', 'minAttentionDistance', 'burnTime', 'chasingSubtlety' ] group.index = group.index.droplevel( ['minAttentionDistance', 'rangeAttention']) group = group.to_frame() group.columns = ['model'] axForDraw = fig.add_subplot(numRows, numColumns, plotCounter) if (plotCounter) % max(numColumns, 2) == 1: axForDraw.set_ylabel(str(key[0])) if plotCounter <= numColumns: axForDraw.set_title(str(key[1])) for burnTime, grp in group.groupby('burnTime'): grp.index = grp.index.droplevel('burnTime') if burnTime == max(manipulatedVariables['burnTime']): grp['human'] = [0.6, 0.37, 0.25, 0.24, 0.52] grp.plot.line(ax=axForDraw, y='human', label='human', ylim=(0, 0.9), marker='o', rot=0) grp.plot.line(ax=axForDraw, y='model', label='burnTime=' + str((burnTime - 1) * 0.2) + 's', ylim=(0, 0.9), marker='o', rot=0) plotCounter = plotCounter + 1 plt.suptitle('Measurement = Escape Rate of Hybrid') fig.text(x=0.5, y=0.92, s='Min Attention Distance', ha='center', va='center') fig.text(x=0.05, y=0.5, s='Attention Range', ha='center', va='center', rotation=90) plt.show()