(进阶)003 - AWS DeepRacer分析log

下载 Evaluation log

解压log,找到 0-iteration.csv

log 可视化分析

import os
import numpy as np
import pandas as pd
from math import exp
from matplotlib.collections import LineCollection
import matplotlib.pyplot as plt
import matplotlib.animation as animation


def getCSVdata(file):
    with open(file,'r') as fo:
        return fo.read()

def getPathXY():
    path = pd.read_csv('Invent 2018.csv',header=None)
    pathList = path.values.tolist()
    X,Y = [item[0]*100 for item in pathList],[item[1]*100 for item in pathList]
    return X,Y
def getPDInfo(excelname,sheetname):
    dataAll = pd.read_excel(excelname,sheet_name=sheetname)
    timeSet = set(dataAll.episode.tolist())
    return dataAll,timeSet
def getTimesXYSBySheetName(dataAll,timeIndex):
    data = dataAll[dataAll.episode == timeIndex]
    x,y,tstamp,colorListSelectSpeed,colorListSelectReward,speedL,rewardList = [x*100 for x in data.X.values.tolist()],[y*100 for y in data.Y.values.tolist()],[t*0.3 for t in data.tstamp.values.tolist()],[t for t in data.color.values.tolist()][1:],[t for t in data.Rcolor.values.tolist()][1:],[t for t in data.throttle.values.tolist()][1:],[t for t in data.reward.values.tolist()][1:]
    tstampDelta = [tstamp[i+1]-tstamp[i] for i in range(len(tstamp)-1)]
    return x,y,tstampDelta,colorListSelectSpeed,colorListSelectReward,speedL,rewardList
def DrawTrack(fig,ex,ey,tstamp,colorListSelectSpeed,colorListSelectReward,speedL,rewardList):  #39  0.387   63.43
    ims = []
    for i in range(len(ex)-1):
        plt.title('speed:'+str(round(speedL[i],2)) + '\nreward:' + str(round(rewardList[i],3)))
        plt.xlabel('Env: re:Invent 2018\nunite:cm')
        im = plt.plot(ex[0:i+1],ey[0:i+1],color=colorListSelectSpeed[i],linewidth=4)
        ims.append(im)
        # plt.plot(xs, ys,color=color,linewidth=12.365) # 车宽算出来12.365cm
        plt.pause(tstamp[i])
    # ani = animation.ArtistAnimation(fig, ims, repeat_delay=1000)
    # ani.save("1.gif", writer='pillow')
    return ims
def speed2Color(speed,speedList,colorList):
    for index,p in enumerate(speedList):
        if speed<=p:
            return colorList[index]
    else:
        return colorList[0]
def reward2Color(reward,rewardList,colorList):
    if reward > 2:
        return 'red'
    elif reward >= 1:
        return 'orangered'
    else:
        return 'green'
if __name__ == '__main__':
    X,Y = getPathXY()
    plt.axis([-100,max(X)+100, -100,max(Y)+100])
    #plt.ion()
    plt.scatter(X, Y,color='#313D46',linewidth=38)
    fileList = [x for x in os.listdir() if x.lower().endswith('.csv') and x.startswith('0')]
    if len(fileList) == 1:
        dataRow = [x for x in getCSVdata(fileList[0]).split('\n') if x]
        dataConvRow = []
        head = []
        for index,value in enumerate(dataRow):
            if index == 0:
                head = [x.strip() for x in value.replace('action,','').split(',')]
            else:
                dataConvRow.append([x.strip() for x in (value[:value.find('[')] + value[value.find('],')+2:]).split(',')])
        df = pd.DataFrame(data=dataConvRow,columns=head)
        df.episode,df.steps,df.closest_waypoint = df.episode.map(int),df.steps.map(float).map(int),df.closest_waypoint.map(int)
        df.X,df.Y,df.throttle,df.reward,df.progress,df.track_len,df.tstamp = df.X.map(float),df.Y.map(float),df.throttle.map(float),df.reward.map(float),df.progress.map(float),df.track_len.map(float),df.tstamp.map(float)
        dfS = df[df.episode.isin([4])].copy(deep=True)
        ### 1. speed select
        # speedThrottle = 3.0
        # Lx,Ly = [100*x for x in dfS[dfS.throttle < speedThrottle].X.tolist()],[100*y for y in dfS[dfS.throttle < speedThrottle].Y.tolist()]
        # plt.scatter(Lx, Ly,marker = 'o', color = 'green', s = 24)
        ### 2. progress
        progressRange = (15,50)
        Lx,Ly = [100*x for x in dfS[(dfS.progress > progressRange[0]) & (dfS.progress  < progressRange[1])].X.tolist()],[100*y for y in dfS[(dfS.progress > progressRange[0]) & (dfS.progress  < progressRange[1])].Y.tolist()]
        plt.scatter(Lx, Ly,marker = 'o', color = 'green', s = 24)
        plt.show()
    else:
        print('CSV file not unique!')

    

对各个维度进行分析

对速度低于 1.5 的点进行筛选

speedThrottle = 1.5
在这里插入图片描述

对赛道范围的进行筛选

progressRange = (15,40)
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rambo.Fan

码字不易,打赏有动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值