mirror of
https://github.com/wassname/Deep-reinforcement-learning-with-pytorch.git
synced 2026-09-09 11:13:45 +08:00
31 lines
571 B
Python
31 lines
571 B
Python
import argparse
|
|
import pickle
|
|
from collections import namedtuple
|
|
|
|
import os
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
import torch
|
|
|
|
|
|
def discount(sequence, Gamma = 0.99):
|
|
R = 0
|
|
reward = []
|
|
for r in sequence[::-1]:
|
|
R = r + Gamma * R
|
|
reward.insert(0, R)
|
|
return reward
|
|
|
|
|
|
def makedir():
|
|
if not os.path.exists('./exp'):
|
|
os.makedirs('./exp/model')
|
|
os.makedirs('./exp/logs')
|
|
|
|
|
|
def save_model(model, iteration_time):
|
|
path = './exp/model/model'+str(iteration_time)+'.pkl'
|
|
torch.save(model.state_dict(), path)
|
|
|
|
|