循环神经网络
写在前面 参考书籍 Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola. Dive into Deep Learning. 2020. 简介 - Dive-into-DL-PyTorch (tangshusen.me) 循环神经网络前导 source code: NJU-ymhui/DeepLearning: Deep Learning with pytorch (github.com) use git to clone:...
注意力机制
写在前面 参考书籍 Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola. Dive into Deep Learning. 2020. 简介 - Dive-into-DL-PyTorch (tangshusen.me) 注意力机制 source code: NJU-ymhui/DeepLearning: Deep Learning with pytorch (github.com) use git to clone: https://github.com/NJU-ymhui/DeepLearning.git /attention visualization.py batch_matrix.py nadaraya_watson.py score.py bahdanau.py multi_head.py self_attention.py position_encoding.py 注意力机制(Attention...
卷积神经网络
写在前面 参考书籍 Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola. Dive into Deep Learning. 2020. 简介 - Dive-into-DL-PyTorch (tangshusen.me) 卷积神经网络 source code: NJU-ymhui/DeepLearning: Deep Learning with pytorch (github.com) use git to clone: https://github.com/NJU-ymhui/DeepLearning.git /CNN cross_correlation.py fill.py multi_pipe.py pool_layer.py LeNet.py 多层感知机的局限性 详见7.1. From Fully Connected Layers to Convolutions — Dive into Deep Learning 1.0.3 documentation (d2l.ai) 卷积 详见7.1. From...
多层感知机
写在前面 参考书籍 Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola. Dive into Deep Learning. 2020. 简介 - Dive-into-DL-PyTorch (tangshusen.me) 多层感知机 source code: NJU-ymhui/DeepLearning: Deep Learning with pytorch (github.com) use git to clone:...
线性神经网络
线性神经网络 source code: NJU-ymhui/DeepLearning: Deep Learning with pytorch (github.com) use git to clone: https://github.com/NJU-ymhui/DeepLearning.git /Linear vectorization_acceleration.py timer.py normal.py linear_regression_self.py linear_regression_lib.py image.py softmax_self.py 写在前面 参考书籍 Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola. Dive into Deep Learning. 2020. 简介 - Dive-into-DL-PyTorch (tangshusen.me) 线性回归 线性模型 线性模型的基础是线性假设,即因变量=各自变量的加权和+偏移。 公式 ŷ = w~1~x~1~ + w~2~x~2~...
线性代数
在pytorch中使用线性代数处理数据 source code: NJU-ymhui/DataOperations: Use pytorch for data operations (github.com) use git to clone: https://github.com/NJU-ymhui/DataOperations.git linear_algebra.py tensor_operation.py 基本概念 轴 **张量的每一个轴对应数据的一个维度。**轴的编号从0开始;轴的编号指明了张量的某个方向。 示例:一个二维张量可以视作一个矩阵,它有两个轴:行(轴-0)与列(轴-1) 维度 此处的维度描述的是张量这个宏观概念。 维度是张量的一个属性,指的是张量的数据结构在各个方向上的扩展性。例如,一个二维张量(矩阵)有两个维度,三维张量有三个维度,以此类推。维度可以理解为张量的形状的一部分,描述了张量在每个方向上的大小。例如,形状为 (2, 3, 4) 的三维张量有 3...
数据操作
使用pytorch进行数据处理 source code: NJU-ymhui/DataOperations: Use pytorch for data operations (github.com) use git to clone: https://github.com/NJU-ymhui/DataOperations.git start.py dataprepare.py 入门 pytorch中的数组被称为张量(Tensor),与numpy中的ndarray类似,但ndarray仅支持CPU运算,而Tensor同时可以很好地支持GPU加速运算,并且Tensor类支持自动微分。 导入pytorch库 import torch ...
回溯
回溯 回溯法是递归的子集,通过将原问题分割成可迭代的子问题,将当前元素与更小的结果进行组合(就像回溯一样,回去和子结果组合)进行求解 例题 全排列 题目 给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。 示例 1: 输入:nums = [1,2,3]输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 示例 2: 输入:nums = [0,1]输出:[[0,1],[1,0]] 示例 3: 输入:nums = [1]输出:[[1]] 提示: 1 <= nums.length <= 6 -10 <= nums[i] <= 10 nums 中的所有整数 互不相同 分析 全排列问题是回溯法的经典题型。[a, b, c, ...]的全排列tot(n)可以视作第一个元素和之后所有元素的全排列进行组合,第一个“主导”元素可以由所有元素轮流担任,因此将该问题分解为n * tot(n -...
compare函数
比较函数 许多语言通过定义compare函数来定义排序的标准(升序 or 降序),比如C的qsort,Java的优先队列(堆)PriorityQueue 对于compare函数,当升序时 第一个数小于第二个数,返回负数 第一个数等于第二个数,返回零 第一个数大于第二个数,返回正数 当降序时 第一个数大于第二个数,返回负数 第一个数等于第二个数,返回零 第一个数小于第二个数,返回正数 以Java降序为例 new Comparator<Integer>() { @Override public int compare(int o1, int o2) { return o2 - o1; // 降序如果前面大于后面返回负数 }} (•‿•)
子串
子串 子串指的是一个串中一部分连续元素的集合,是原串的一个子集 例题 和为k的子数组 题目 给你一个整数数组 nums 和一个整数 k ,请你统计并返回 该数组中和为 k 的子数组的个数 。 子数组是数组中元素的连续非空序列。 示例 1: 输入:nums = [1,1,1], k = 2输出:2 示例 2: 输入:nums = [1,2,3], k = 3输出:2 提示: 1 <= nums.length <= 2 * 104 -1000 <= nums[i] <= 1000 -107 <= k <= 107 分析 子数组可以被看作两个前缀作差,即arr = longPrefix - shortPrefix。因此目标值k可以通过前缀和的差求得,即k = sum[long] - sum[short],移项有sum[long] = sum[short] + k. 同时注意到sum[long]的求得总是在sum[short]右侧发生,因此我们可以一边求前缀和并把加上k的结果(short +...