栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

[loss画图记录]

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[loss画图记录]

一、导入库
import numpy as np
import pandas as pd 
#import networkx as nx
import matplotlib.pyplot as plt
import random
from 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 label

def 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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/739782.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号