欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

[loss画图记录]

时间:2023-05-25
一、导入库

import numpy as npimport pandas as pd #import networkx as nximport matplotlib.pyplot as pltimport randomfrom collections import *import csv import pickle import os

二、修改当前文件工作路径

os.getcwd() # 获得当前工作路径cd "C:\Users\Administrator\Desktop\潘\GDDPG\model_plot\L" # 修改工作路径### 获得当前文件路径下的文件lpath="C:\Users\Administrator\Desktop\潘\GDDPG\model_plot\L"for root, dirs, files in os.walk(lpath): print(files)

三、画loss的两个model的morning段的图

## 单独画GRLPA_flow_morning_loss图# 先改工作位置fig1, ax1 = plt.subplots(figsize=(8, 5), dpi=80)l_f='loss1000GRLPA29morningflow_weekday.pkl'#l_u='loss1000GRLPA29morningunweighted_weekday.pkl'loss = pickle.load(open(l_f,"rb"))loss = np.asarray(loss)loss = loss[::2][:100]x = range(len(loss))label = "morning"ax1.plot(x,loss,color="orange",label=label)ax1.legend()#plt.title("GRLPA model under flow-matrix in the morning") plt.savefig("GRLPA_flow_morning.png")

第二个

## 单独画GRLPA_unweighted_morning_loss图# 先改工作位置fig1, ax1 = plt.subplots(figsize=(8, 5), dpi=80)#l_f='loss1000GRLPA29morningflow_weekday.pkl'l_u='loss1000GRLPA29morningunweighted_weekday.pkl'loss = pickle.load(open(l_u,"rb"))loss = np.asarray(loss)loss = loss[::2][:100]x = range(len(loss))label = "morning"ax1.plot(x,loss,color="orange",label=label)ax1.legend()#plt.title("GRLPA model under flow-matrix in the morning") plt.savefig("GRLPA_unweighted_morning.png")

四、画loss的3个model的三个时间段的图

fig1, ax1 = plt.subplots(figsize=(8, 5), dpi=80)for f in files: if "GRLPA" in f: if "flow" in f: loss = pickle.load(open(f,"rb")) loss = np.asarray(loss) loss = loss[::2] x = range(len(loss)) label = Judge_Label(f) if label is not None: ax1.plot(x,loss,label=label) ax1.legend()plt.title("GRLPA model under flow-matrix") plt.savefig("GRLPA_flow.png")fig2, ax2 = plt.subplots(figsize=(8, 5), dpi=80)for f in files: if "GRLPA" in f: if "unweighted" in f: loss = pickle.load(open(f,"rb")) loss = np.asarray(loss) loss = loss[::2] x = range(len(loss)) label = Judge_Label(f) if label is not None: ax2.plot(x,loss,label=label) ax2.legend() plt.title("GRLPA model under unweighted-matrix") plt.savefig("GRLPA_unweighted.png")fig3, ax3 = plt.subplots(figsize=(8, 5), dpi=80)for f in files: if "DDPG" in f: loss = pickle.load(open(f,"rb")) loss = np.asarray(loss) loss = loss[::2] x = range(len(loss)) label = Judge_Label(f) if label is not None: ax3.plot(x,loss,label=label) ax3.legend() plt.title("DDPG model under unweighted-matrix") plt.savefig("DDPG_loss.png")

附录:调用函数

## 获取L文件夹下的所有为.pkl的文件def juduge_labdel(f): if "DDPG" in f: if "morning" in f: label="DDPG_morning" elif "noon" in f : label="DDPG_noon" elif "evening" in f or "eveining" in f: label="DDPG_evening" else : label= None if "GRLPA" in f: if "flow" in f: if "morning" in f: label="GRLPA_morning_flow" elif "noon" in f : label="GRLPA_noon_flow" elif "evening" in f or "eveining" in f: label="GRLPA_evening_flow" else: label= None else: if "morning" in f: label="GRLPA_morning_unweighted" elif "noon" in f : label="GRLPA_noon_unweighted" elif "evening" in f or "eveining" in f: label="GRLPA_evening_unweighted" else: label= None return labeldef Judge_Label(f): if "morning" in f: label="morning" elif "noon" in f : label="noon" elif "evening" in f or "eveining" in f: label="evening" else: label= None return label

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。