深度学习学习笔记
深度学习学习笔记
非文的NLP修炼笔记
研究生在读,NLP小白一枚,希望大家多多指教~
展开
-
使用Python将sin(x)和cos(x)画在同一个图例里
话不多说,直接上代码:import numpy as npimport matplotlib.pyplot as pltx = np.arange(0, 6, 0.1)y1 = np.sin(x)y2 = np.cos(x)plt.plot(x, y1, label='sin')plt.plot(x, y2, linestyle='--', label='cos')plt.xlabel('x')plt.ylabel('y')plt.title('sin & cos')p原创 2022-05-13 20:47:01 · 4050 阅读 · 0 评论 -
使用Python查看并显示图像
今天又来写一个Python的基础用法,使用Python来显示图像,不多说,代码如下:import matplotlib.pyplot as pltfrom matplotlib.image import imreadimg = imread('x:/xx/xx/xx/moon.jpg')plt.imshow(img)plt.show()原创 2022-05-13 20:26:29 · 13624 阅读 · 0 评论 -
深度学习中常用的函数
下面介绍深度学习中常用的函数及其代码实现:1.恒等函数import numpy as npimport matplotlib.pyplot as pltdef identity_function(x): return xx = np.arange(0.0, 5.0, 0.1)y = identity_function(x)plt.plot(x, y)plt.xlabel('x')plt.ylabel('y')plt.show()2.阶跃函数impo原创 2022-05-11 16:48:16 · 1104 阅读 · 0 评论 -
使用Python求函数最小值
现已知函数f(x) = (x0)**2 + (x1)**2,使用Python求其最小值。import numpy as npimport matplotlib.pyplot as pltdef _numerical_gradient_no_batch(f, x): h = 1e-4 grad = np.zeros_like(x) for idx in range(x.size): tmp_val = x[idx] x[idx]原创 2022-05-10 22:44:00 · 4442 阅读 · 0 评论 -
用Python画出函数f(x) = X^2的梯度指向图
现给出函数f(x)= X^2,其中X为向量,包含元素(x1, x2, ……),通过Python画出其指向图。import numpy as npimport matplotlib.pyplot as pltdef _numerical_gradient_no_batch(f, x): h = 1e-4 grad = np.zeros_like(x) for idx in range(x.size): tmp_val = x[idx]原创 2022-05-10 19:55:50 · 710 阅读 · 0 评论 -
通过Python求函数f(x) = (x0)^2 + (x1)^2在某一点的梯度
现给出函数f(x) = (x0)^2 + (x1)^2,通过Python来求其在某一点的梯度。import numpy as npdef function_2(x): return x[0]**2 + x[1]**2def numerical_gradient(f, x): h = 1e-4 grad = np.zero_like(x) for idx in range(x.size): tmp_val = x[idx]原创 2022-05-10 15:49:02 · 416 阅读 · 0 评论 -
Python求函数f(x) = (x0)^2 + (x1)^2的偏导数
现给出函数f(x) = (x1)^2 + (x2)^2,用Python来求其在某一点的关于某个变量的偏导数。1.求当x0=3, x1=4时,关于x0的偏导数2.求当x0=3, x1=4时,关于x1的偏导数以下是代码实现:import numpy as npdef function_tmp1(x): return x0**x0 + 4.0**2.0def function_tmp2(x): return 3.0**2 + x1*x1def numerical原创 2022-05-10 15:04:55 · 606 阅读 · 0 评论 -
使用Python绘制二元函数图像
使用Python绘制二元函数f(x) = (x1)2 + (x2)2的图像。import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfig = plt.figure()ax = Axes3D(fig)x1 = np.arange(-3.0, 3.0, 0.1)x2 = np.arange(-3.0, 3.0, 0.1)X, Y = np.meshgrid(x1, x原创 2022-05-10 14:48:21 · 5126 阅读 · 11 评论 -
Python求函数导数并绘制切线
下面我们通过Python来求函数y = 0.01x**2 + 0.1*x的导数,并绘制函数图像以及函数在某一点的切线。首先,我们给出导数的数学定义式:其次,我们先来写一写函数导数的实现代码。一般来说,求导数我们可能会采用下面这样的代码:def numerical_diff(f, x): h = 10e-50 return (f(x+h) - f(x)) / h其中的h = 10e-50是用来表达“微小变化”。但实际上,这样的表达会有两个问题,一个是会产生“舍入误差”原创 2022-05-10 10:22:22 · 2812 阅读 · 2 评论 -
损失函数及其代码实现
1.均方误差import numpy as npdef mean_squared_error(y, t): return 0.5 * np.sum((y-t)**2)2.交叉熵误差import numpy as npdef cross_entropy_error(y, t): delta = 1e-7 return -np.sum(t * np.log(y + delta))原创 2022-05-09 14:43:24 · 795 阅读 · 0 评论 -
对MNIST数据集实现神经网络的推理处理
1.显示MNIST图像import numpy as npfrom dataset.mnist import load_mnistfrom PIL import Imagedef img_show(img): pil_img = Image.fromarray(np.uint8(img)) pil.img.show()(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=F原创 2022-05-07 16:13:23 · 695 阅读 · 0 评论 -
三层神经网络的实现
代码实现:import numpy as npdef sigmoid(x): return 1 / (1 + np.exp(-x))def identity_function(x): return xdef init_network(): network = {} network['W1'] = np.array([[0.1, 0.3, 0.5], [0.2, 0.4, 0.6]]) network['b1'] = n...原创 2022-05-07 10:09:11 · 149 阅读 · 0 评论