在线观看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錦銳科技CA51F2 SDK開發包
  2. 24.06 MB   |  29次下載  |  1 積分
  3. 2錦銳CA51F005 SDK開發包
  4. 19.47 MB   |  3次下載  |  1 積分
  5. 310周年文章合集白皮書
  6. 15.63 MB  |  2次下載  |  免費
  7. 4世界各國&地區常見電壓/頻率/插頭/插座一覽表
  8. 2.36 MB   |  1次下載  |  免費
  9. 5FS4059B、FS4059C雙節鋰電池充電應用圖
  10. 0.05 MB   |  1次下載  |  免費
  11. 6MX6200語音芯片使用手冊V1.4
  12. 1.25 MB   |  1次下載  |  免費
  13. 7蘋果iphone 11電路原理圖
  14. 4.98 MB   |  1次下載  |  2 積分
  15. 8XILINX XCZU67DR FPGA完整原理圖
  16. 18.22 MB   |  次下載  |  8 積分

本月

  1. 1AI智能眼鏡產業鏈分析
  2. 4.43 MB   |  354次下載  |  免費
  3. 2蘇泊爾電磁爐線路的電路原理圖資料合集
  4. 2.02 MB   |  294次下載  |  5 積分
  5. 3貼片三極管上的印字與真實名稱的對照表詳細說明
  6. 0.50 MB   |  93次下載  |  1 積分
  7. 4長虹液晶電視R-HS310B-5HF01的電源板電路原理圖
  8. 0.46 MB   |  87次下載  |  5 積分
  9. 5U盤一鍵制作
  10. 23.84 MB   |  41次下載  |  免費
  11. 6錦銳科技CA51F2 SDK開發包
  12. 24.06 MB   |  29次下載  |  1 積分
  13. 7AO4803A雙P通道增強型場效應晶體管的數據手冊
  14. 0.11 MB   |  28次下載  |  2 積分
  15. 8長虹液晶彩電LS29機芯的技術資料說明
  16. 3.42 MB   |  16次下載  |  2 積分

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935127次下載  |  10 積分
  3. 2開源硬件-PMP21529.1-4 開關降壓/升壓雙向直流/直流轉換器 PCB layout 設計
  4. 1.48MB  |  420064次下載  |  10 積分
  5. 3Altium DXP2002下載入口
  6. 未知  |  233089次下載  |  10 積分
  7. 4電路仿真軟件multisim 10.0免費下載
  8. 340992  |  191388次下載  |  10 積分
  9. 5十天學會AVR單片機與C語言視頻教程 下載
  10. 158M  |  183342次下載  |  10 積分
  11. 6labview8.5下載
  12. 未知  |  81588次下載  |  10 積分
  13. 7Keil工具MDK-Arm免費下載
  14. 0.02 MB  |  73815次下載  |  10 積分
  15. 8LabVIEW 8.6下載
  16. 未知  |  65988次下載  |  10 積分
主站蜘蛛池模板: 性瘾高h姚蕊全文免费阅读 性做久久久久 | 国产毛片农村妇女aa板 | 亚洲午夜久久久久国产 | aaaaaa级特色特黄的毛片 | 免费色视频 | 高清一区二区三区免费 | 高清色黄毛片一级毛片 | 色狠狠色综合吹潮 | 激情六月天婷婷 | 好爽好紧好大的免费视频国产 | 毛片a区| 猛操在线 | 丁香五月欧美成人 | 91免费视| 青青草国产三级精品三级 | 好紧好爽太大了h视频 | 黄色国产精品 | 亚洲综合五月天 | 四虎欧美在线观看免费 | 欧美色频 | 欧美不卡视频在线 | 亚洲精品在线不卡 | 亚洲黄色网址大全 | 国产伦精品一区二区三区四区 | 国产精品推荐天天看天天爽 | 国产精品久久久精品三级 | 欧美黄业| 午夜影视啪啪免费体验区入口 | 视频在线一区 | 成人欧美精品大91在线 | 天天视频官网天天视频在线 | 边摸边吃奶边做视频叫床韩剧 | 黄色特级毛片 | a一级黄 | 久久人人网 | 日本19xxxxxxxxx69 日本68xxxxxxxxx59 | 99久久国产综合精品国 | 免费欧美黄色网址 | 樱桃磁力bt天堂 | 高清欧美一级在线观看 | 久久夜色精品国产亚洲噜噜 |