在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

電子發燒友App

硬聲App

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示
創作
電子發燒友網>電子資料下載>電子資料>PyTorch教程23.7之效用函數和類

PyTorch教程23.7之效用函數和類

2023-06-06 | pdf | 0.18 MB | 次下載 | 免費

資料介紹

本節包含本書中使用的實用函數和類的實現。

import collections
import inspect
from IPython import display
from torch import nn
from d2l import torch as d2l
import collections
import inspect
import random
from IPython import display
from mxnet import autograd, gluon, np, npx
from mxnet.gluon import nn
from d2l import mxnet as d2l

npx.set_np()
import collections
import inspect
import jax
from IPython import display
from d2l import jax as d2l
No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
import collections
import inspect
import tensorflow as tf
from IPython import display
from d2l import tensorflow as d2l

超參數。

@d2l.add_to_class(d2l.HyperParameters) #@save
def save_hyperparameters(self, ignore=[]):
  """Save function arguments into class attributes."""
  frame = inspect.currentframe().f_back
  _, _, _, local_vars = inspect.getargvalues(frame)
  self.hparams = {k:v for k, v in local_vars.items()
          if k not in set(ignore+['self']) and not k.startswith('_')}
  for k, v in self.hparams.items():
    setattr(self, k, v)

進度條。

@d2l.add_to_class(d2l.ProgressBoard) #@save
def draw(self, x, y, label, every_n=1):
  Point = collections.namedtuple('Point', ['x', 'y'])
  if not hasattr(self, 'raw_points'):
    self.raw_points = collections.OrderedDict()
    self.data = collections.OrderedDict()
  if label not in self.raw_points:
    self.raw_points[label] = []
    self.data[label] = []
  points = self.raw_points[label]
  line = self.data[label]
  points.append(Point(x, y))
  if len(points) != every_n:
    return
  mean = lambda x: sum(x) / len(x)
  line.append(Point(mean([p.x for p in points]),
           mean([p.y for p in points])))
  points.clear()
  if not self.display:
    return
  d2l.use_svg_display()
  if self.fig is None:
    self.fig = d2l.plt.figure(figsize=self.figsize)
  plt_lines, labels = [], []
  for (k, v), ls, color in zip(self.data.items(), self.ls, self.colors):
    plt_lines.append(d2l.plt.plot([p.x for p in v], [p.y for p in v],
                   linestyle=ls, color=color)[0])
    labels.append(k)
  axes = self.axes if self.axes else d2l.plt.gca()
  if self.xlim: axes.set_xlim(self.xlim)
  if self.ylim: axes.set_ylim(self.ylim)
  if not self.xlabel: self.xlabel = self.x
  axes.set_xlabel(self.xlabel)
  axes.set_ylabel(self.ylabel)
  axes.set_xscale(self.xscale)
  axes.set_yscale(self.yscale)
  axes.legend(plt_lines, labels)
  display.display(self.fig)
  display.clear_output(wait=True)

添加 FrozenLake 環境

def frozen_lake(seed): #@save
  # See https://www.gymlibrary.dev/environments/toy_text/frozen_lake/ to learn more about this env
  # How to process env.P.items is adpated from https://sites.google.com/view/deep-rl-bootcamp/labs

  env = gym.make('FrozenLake-v1', is_slippery=False)
  env.seed(seed)
  env.action_space.np_random.seed(seed)
  env.action_space.seed(seed)
  env_info = {}
  env_info['desc'] = env.desc # 2D array specifying what each grid item means
  env_info['num_states'] = env.nS # Number of observations/states or obs/state dim
  env_info['num_actions'] = env.nA # Number of actions or action dim
  # Define indices for (transition probability, nextstate, reward, done) tuple
  env_info['trans_prob_idx'] = 0 # Index of transition probability entry
  env_info['nextstate_idx'] = 1 # Index of next state entry
  env_info['reward_idx'] = 2 # Index of reward entry
  env_info['done_idx'] = 3 # Index of done entry
  env_info['mdp'] = {}
  env_info['env'] = env

  for (s, others) in env.P.items():
    # others(s) = {a0: [ (p(s'|s,a0), s', reward, done),...], a1:[...], ...}

    for (a, pxrds) in others.items():
      # pxrds is [(p1,next1,r1,d1),(p2,next2,r2,d2),..].
      # e.g. [(0.3, 0, 0, False), (0.3, 0, 0, False), (0.3, 4, 1, False)]
      env_info['mdp'][(s,a)] = pxrds

  return env_info

創造環境

def make_env(name ='', seed=0): #@save
  # Input parameters:
  # name: specifies a gym environment.
  # For Value iteration, only FrozenLake-v1 is supported.
  if name == 'FrozenLake-v1':
    return frozen_lake(seed)

  else:
    raise ValueError("%s env is not supported in this Notebook")

示值函數

def show_value_function_progress(env_desc, V, pi): #@save
  # This function visualizes how value and policy changes over time.
  # V: [num_iters, num_states]
  # pi: [num_iters, num_states]
  # How to visualize value function is adapted (but changed) from: https://sites.google.com/view/deep-rl-bootcamp/labs

  num_iters = V.shape[0]
  fig, ax = plt.subplots(figsize=(15, 15))

  for k in range(V.shape[0]):
    plt.subplot(4, 4, k + 1)
    plt.imshow(V[k].reshape(4,4), cmap="bone")
    ax = plt.gca()
    ax.set_xticks(np.arange(0, 5)-.5, minor=True)
    ax.set_yticks(np.arange(0, 5)-.5, minor=True)
    ax.grid(which="minor", color="w", linestyle='-', linewidth=3)
    ax.tick_params(which="minor", bottom=False, left=False)
    ax.set_xticks([])
    ax.set_yticks([])

    # LEFT action: 0, DOWN action: 1
    # RIGHT action: 2, UP action: 3
    action2dxdy = {0:(-.25, 0),1: (0, .25),
            2:(0.25, 0),3: (-.25, 0)}

    for y in range(4):
      for x in range(4):
        action = pi[k].reshape(4,4)[y, x]
        dx, dy = action2dxdy[action]

        if env_desc[y,x].decode() == 'H':
          ax.text(x, y, str(env_desc[y,x].decode()),
            ha="center", va="center", color="y",
             size=20, fontweight='bold')

        elif env_desc[y,x].decode() == 'G':
          ax.text(x, y, str(env_desc[y,x].decode()),
            ha="center", va="center", color="w",
             size=20, fontweight='bold')

        else:
          ax.text(x, y, str(env_desc[y,x].decode()),
            ha="center", va="center", color="g",
             size=15, fontweight='bold')

        # No arrow for cells with G and H labels
        if env_desc[y,x].decode() != 'G' and env_desc[y,x].decode() != 'H':
          ax.arrow(x, y, dx, dy, color='r', head_width=0.2, head_length=0.15)

    ax.set_title("Step = " + str(k + 1),

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數據手冊
  2. 1.06 MB  |  532次下載  |  免費
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費
  9. 5元宇宙深度解析—未來的未來-風口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費
  11. 6迪文DGUS開發指南
  12. 31.67 MB  |  194次下載  |  免費
  13. 7元宇宙底層硬件系列報告
  14. 13.42 MB  |  182次下載  |  免費
  15. 8FP5207XR-G1中文應用手冊
  16. 1.09 MB  |  178次下載  |  免費

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費
  3. 2555集成電路應用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費
  7. 4開關電源設計實例指南
  8. 未知  |  21549次下載  |  免費
  9. 5電氣工程師手冊免費下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費
  11. 6數字電路基礎pdf(下載)
  12. 未知  |  13750次下載  |  免費
  13. 7電子制作實例集錦 下載
  14. 未知  |  8113次下載  |  免費
  15. 8《LED驅動電路設計》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費
  3. 2protel99se軟件下載(可英文版轉中文版)
  4. 78.1 MB  |  537798次下載  |  免費
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費
  11. 6電路仿真軟件multisim 10.0免費下載
  12. 340992  |  191187次下載  |  免費
  13. 7十天學會AVR單片機與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費
  15. 8proe5.0野火版下載(中文版免費下載)
  16. 未知  |  138040次下載  |  免費
主站蜘蛛池模板: 天天干网| 你懂得网址在线观看| 视频在线观看高清免费看| 激情综合婷婷| 色激情网| 成人综合在线视频| 美女一区二区三区| 婷婷色网站| 国产一区在线mmai| 欧美a级网站| 九九午夜| 天天尻| 天天插天天爱| 在线免费观看视频| 国产日本三级| 免费日韩网站| 日本黄色网页| 四虎最新免费观看网址| www.三级| 免费精品99久久国产综合精品| 免费黄色大片在线观看| 国产成人悠悠影院| 69日本人xxxx16-18| 黄色大视频| 西西人体大胆高清啪啪欧洲| 黄色成人免费观看| 欧美一级爱操视频| 天天澡天天摸天天爽免费| 一夜七次郎久久综合伊人| 手机在线播放视频| 69国产成人精品午夜福中文| 成人综合网站| 91大神精品长腿在线观看网站| 3344在线| 狠狠色婷婷七月色综合| 四虎影院美女| 性开放网站| 手机亚洲第1页| 黄网站免费大全| 天天上天天干| 欧美xxxx性高清|