当前位置: 首页 > news >正文

TensorFlow2 study notes[2]

文章目录

  • tf.autodiff.ForwardAccumulator
  • references

tf.autodiff.ForwardAccumulator

  1. the function can be used to achieve the Computation of Jacobian-vector products with forward-mode autodiff.
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
  2. primals is variables need to watch.tangents is direction vector.
tf.autodiff.ForwardAccumulator(primals, tangents
)
import tensorflow as tf# 定义函数
def f(x, y):return x ** 2 + y**5 + tf.sin(y)*tf.cos(x)# 输入变量和方向向量
x = tf.constant(2.0)
y = tf.constant(3.0)
v_x = tf.constant(1.5)  # x 方向的分量
v_y = tf.constant(0.2)  # y 方向的分量# 初始化 ForwardAccumulator
with tf.autodiff.ForwardAccumulator(primals=[x, y],          # 要跟踪的变量tangents=[v_x, v_y]      # 方向向量 v
) as acc:# 计算函数值z = f(x, y)# 提取方向导数 (JVP)
jvp = acc.jvp(z)
print("函数值:", z.numpy())      # 输出: 4.0 + sin(3) ≈ 4.14112
print("方向导数 (JVP):", jvp.numpy())  # 输出: 2*2*1 + cos(3)*0 ≈ 4.0

在这里插入图片描述

references

  1. https://tensorflow.google.cn/api_docs
  2. deepseek
http://www.lryc.cn/news/586007.html

相关文章:

  • 【嵌入式硬件实例】-555定时器实现倍压电路
  • 【408考研知识点全面讲解计算机学科专业基础综合(408)】——数据结构之排序
  • 依赖注入的逻辑基于Java语言
  • 【第五节】部署http接口到ubuntu server上的docker内
  • Eplan API Scripts
  • Transforms
  • Spring Boot 整合 OAuth2 详细教程(适用于 2025 年 Spring Boot 3.x)
  • 力扣-19. 删除链表的倒数第N个节点
  • 什么是 Bootloader?怎么把它移植到 STM32 上?
  • 【6.1.3 漫画分布式锁】
  • 线程属性设置全攻略
  • 14. 请谈一下浏览器的强缓存和协商缓存
  • 9.2 埃尔米特矩阵和酉矩阵
  • Pandas 模块之数据的读取
  • arcgis投影后数据显示问题记录
  • 非程序员如何用 AI 提升日常工作效率:以产品经理为例的落地实践指南
  • error while loading shared libraries
  • 小架构step系列12:单元测试
  • [爬虫实战] 多进程/多线程/协程-异步爬取豆瓣Top250
  • Pytest 跳过测试技巧:灵活控制哪些测试该跑、哪些该跳过
  • linux系统mysql性能优化
  • H2在springboot的单元测试中的应用
  • 多 Agent 强化学习实践指南(一):CTDE PPO 在合作捕食者-猎物游戏中的应用详解
  • 引入了模块但没有使用”,会不会被打包进去
  • 【C++小白逆袭】内存管理从崩溃到精通的秘籍
  • c++反射实现
  • 张量数值计算
  • 跨系统开发代码换行符如何解决
  • 每日一SQL 【销售分析 III】
  • 试用了10款翻译软件后,我只推荐这一款!完全免费还超好用