[动手学深度学习DAY5]:卷积神经网络
1.卷积神经网络基础 2.LeNet 3.经典CNN模型 1.卷积神经网络基础 卷积层 池化层 细节解释 卷积层 二维互相关运算 二维互相关(cross-correlation)运算的输入是一个二维输入数组和一个二维核(kernel)数组,输出也是一个二维数组,其中核数组通常称为卷积核或过滤器(filter)。卷积核的尺寸通常小于输入数组,卷积核在输入数组上滑动,在每个位置上,卷积核与该位置处的输…
Read More »[动手学深度学习DAY4]:RNN进阶、机器翻译和Transformer
Part1.RNN进阶 GRU LSTM 深度循环神经网络 双向循环神经网络 GRU RNN结构中容易出现梯度衰减或者爆炸,我们通过添加门控结构可以一定程度缓解这个问题,也可以捕捉时间序列中时间步距离较长的依赖关系。 $$R_{t} = σ(X_tW_{xr} + H_{t−1}W_{hr} + b_r)\\ Z_{t} = σ(X_tW_{xz} + H_{t−1}W_{hz} + b_z)\\…
Read More »[动手学深度学习DAY3]:过拟合、欠拟合和梯度消失、梯度爆炸
Part1.过拟合、欠拟合 训练误差 模型在训练数据集上的误差。 泛化误差 模型在任意一个测试数据样本上的误差,一般通过测试集上的误差进行近似。 过拟合 模型的训练误差远远小于模型的泛化误差,即模型过度拟合了训练集上的数据分布,而该数据分布并不能很好的近似数据的原始分布,导致测试数据的误差很大。 欠拟合 模型无法获得较低的训练误差,说明模型不能学习拟合训练集上的数据分布。 模型复杂度 模型复杂度一…
Read More »[动手学深度学习DAY2]:文本预处理、语言模型及RNN基础
Part1.文本预处理 文本预处理主要分为: 读入文本 分词 建立字典 将文本的词序列转为索引序列 读入文本
1 2 3 4 5 6 7 8 9 10 |
import collections import re def read_time_machine(): with open('/home/kesci/input/timemachine7163/timemachine.txt', 'r') as f: lines = [re.sub('[^a-z]+', ' ', line.strip().lower()) for line in f] return lines lines = read_time_machine() print('# sentences %d' % len(lines)) |
分词 我们对每个句子进行分词,也就是将一个句子划分成若干个词(token),转换为一个词的序列。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def tokenize(sentences, token='word'): #Split sentences into word or char tokens if token == 'word': return [sentence.split(' ') for sentence in sentences] elif token == 'char': return [list(sentence) for sentence in sentences] else: print('ERROR: unkown token type '+token) tokens = tokenize(lines) tokens[0:2] #[['the', 'time', 'machine', 'by', 'h', 'g', 'wells', ''], ['']] |
我们也可以通过现有的分词工具进行分词,例如spaCy和NLT…
Read More »[动手学深度学习DAY1]:线性回归、Softmax和多层感知机
Part1:线性回归 线性回归就是通过一个线性函数来拟合数据集中输入与输出之间的关系。线性函数可以表示为:$$y = XW + b$$通过给定一些训练数据(training set,包含数据的输入\(X\)与其对应的输出\(y\))对线性回归模型进行训练,我们可以得到一个能够有效拟合真实数据集的线性函数模型参数\(W\)和\(b\),该函数可以对新的输入数据预测其对应的输出。下面对线性回归的主要步…
Read More »Hello,2020!
逝去的2019 光阴如箭,2019年已经在世纪的刻度上留下印记;岁月如梭,2019年已经在历史的年轮上留下痕迹。在迎接2020年到来的同时,我也愿意去总结一下逝去的2019年,就和前两年一样,算是对过去的一年的致敬与反思。2019年在我的学习阶段是重要的一年,因为它代表着我正式成教与学的接受式学习走向自我探索与研究;2019年在我的人生阶段也是重要的一年,因为它代表着我逐渐了解并确定自己的目标与未…
Read More »Hello, 2019!
浑浑噩噩,一年就这么过去了,想着去年这个时候,我好像也在写一年的总结,只能说时间过得真快,恍惚之间,一年就过去了。想想这一年时间,上半年在实验室完成了本科毕业设计,学习到了一些相关的东西,通过答辩然后顺利毕业。暑假大多数时间都留在学校,期间去腾讯参加了一个夏令营,顺带回了一趟家。下半年研究生正式入学,课程还好,不算少也不算多,不过入学前和入学后的身份的转变也让自己有了一些压力,还是非常希望自己能快…
Read More »Hello,2018!
2017就这样过去了,一年的时间好像很快,仿佛昨天我还在图书馆复习着操作系统,仿佛昨天我还在回校的列车上;一年的时间好像也很慢,我度过了365个日夜,有些日夜我甚至想不起我在干什么,我走过了10个省市,参加了6场比赛,一次培训,穿梭在祖国的大地。2017年对我来说应该是平淡的一年,我在学校做着学生应该做的事情,上课复习考试,偶尔出去参加比赛,仿佛就像重复着2016年,2015年,抑或是高中的生活;…
Read More »[模板]圆与多边形交的面积
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> const double eps = 1e-8; const double pi = acos(-1.0); int dcmp(double x) { if(x > eps) return 1; return x < -eps ? -1 : 0; } struct Point { double x, y; Point(){x = y = 0;} Point(double a, double b) {x = a, y = b;} inline void read() {scanf("%lf%lf", &x, &y);} inline Point operator-(const Point &b)const {return Point(x - b.x, y - b.y);} inline Point operator+(const Point &b)const {return Point(x + b.x, y + b.y);} inline Point operator*(const double &b)const {return Point(x * b, y * b);} inline double dot(const Point &b)const {return x * b.x + y * b.y;} inline double cross(const Point &b, const Point &c)const {return (b.x - x) * (c.y - y) - (c.x - x) * (b.y - y);} inline double Dis(const Point &b)const {return sqrt((*this - b).dot(*this - b));} inline bool InLine(const Point &b, const Point &c)const//三点共线 {return !dcmp(cross(b, c));} inline bool OnSeg(const Point &b, const Point &c)const//点在线段上,包括端点 {return InLine(b, c) && (*this - c).dot(*this - b) < eps;} }; inline double min(double a, double b) {return a < b ? a : b;} inline double max(double a, double b) {return a > b ? a : b;} inline double Sqr(double x) {return x * x;} inline double Sqr(const Point &p) {return p.dot(p);} Point LineCross(const Point &a, const Point &b, const Point &c, const Point &d) { double u = a.cross(b, c), v = b.cross(a, d); return Point((c.x * v + d.x * u) / (u + v), (c.y * v + d.y * u) / (u + v)); } double LineCrossCircle(const Point &a, const Point &b, const Point &r, double R, Point &p1, Point &p2) { Point fp = LineCross(r, Point(r.x + a.y - b.y, r.y + b.x - a.x), a, b); double rtol = r.Dis(fp); double rtos = fp.OnSeg(a, b) ? rtol : min(r.Dis(a), r.Dis(b)); double atob = a.Dis(b); double fptoe = sqrt(R * R - rtol * rtol) / atob; if(rtos > R - eps) return rtos; p1 = fp + (a - b) * fptoe; p2 = fp + (b - a) * fptoe; return rtos; } double SectorArea(const Point &r, const Point &a, const Point &b, double R) //不大于180度扇形面积,r->a->b逆时针 { double A2 = Sqr(r - a), B2 = Sqr(r - b), C2 = Sqr(a - b); return R * R * acos((A2 + B2 - C2) * 0.5 / sqrt(A2) / sqrt(B2)) * 0.5; } double TACIA(const Point &r, const Point &a, const Point &b, double R) //TriangleAndCircleIntersectArea,逆时针,r为圆心 { double adis = r.Dis(a), bdis = r.Dis(b); if(adis < R + eps && bdis < R + eps) return r.cross(a, b) * 0.5; Point ta, tb; if(r.InLine(a, b)) return 0.0; double rtos = LineCrossCircle(a, b, r, R, ta, tb); if(rtos > R - eps) return SectorArea(r, a, b, R); if(adis < R + eps) return r.cross(a, tb) * 0.5 + SectorArea(r, tb, b, R); if(bdis < R + eps) return r.cross(ta, b) * 0.5 + SectorArea(r, a, ta, R); return r.cross(ta, tb) * 0.5 + SectorArea(r, a, ta, R) + SectorArea(r, tb, b, R); } const int N = 505; Point p[N]; double SPICA(int n, Point r, double R)//SimplePolygonIntersectCircleArea { int i; double res = 0, if_clock_t; for(i = 0; i < n; ++ i) { if_clock_t = dcmp(r.cross(p[i], p[(i + 1) % n])); if(if_clock_t < 0) res -= TACIA(r, p[(i + 1) % n], p[i], R); else res += TACIA(r, p[i], p[(i + 1) % n], R); } return fabs(res); } double r; int n; int main() { while (~scanf("%lf", &r)) { scanf("%d", &n); for (int i = 0; i < n; i++) p[i].read(); printf("%.2f\n", SPICA(n, Point(0, 0), r)); } return 0; } |
Read More »
[SGU261]Discrete Roots
前几天写了这道题,用了三个比较简单的模板,然后套在一起就没有然后了 题意如下: 给你两个质数p,k,和整数a(0≤a<p),求解所有满足x^k≡a(mod p)的x。 至于解题分析嘛,目前我还不知道为啥我的blog打latex公式没有用,所以,我觉得下面链接那份份比我分析的好多了(懒啊 可以去这个看看哦https://www.cnblogs.com/w007878/p/3621653.htm…
Read More »