- 博客(36)
- 收藏
- 关注
原创 deep learning sigmoid函数和softplus函数
Certain functions arise often while working with probability distributions,especially the probability distributions used in deep learning models.One of these functions is the logistic sigmoidAnother commonly encountered function is thesoftplus function.
2020-08-31 21:52:28 380
原创 deep learning概率论基本概念
Aprobability distributionis a description of how likely a random variable orset of random variables is to take on each of its possible states. The way wedescribe probability distributions depends on whether the variables are discrete orcontinuous.A proba.
2020-08-31 21:41:27 170
原创 python- numpy dot相乘与for loop 的时间优化
import timea = np.random.rand(1000000)b = np.random.rand(1000000)tic = time.time()c = np.dot(a, b)toc = time.time()print(c)print('Vectorized version:'+ str(1000*(toc - tic)) + 'ms')c = 0tic = time.time()for i in range(1000000): c += a[i]
2020-08-31 20:18:46 427
原创 pytorch-用线性回归梯度下降模型-预测水果产量
假设有如下数据集, 如何预测水果产量假设水果产量与地区无关, 与只与温度, 降雨量, 湿度有关, 若用线性模型预测, 可以通过线性回归的方法, 预测产量。加入线性无关, 通过蓝色方框参数可以求解W1, W2, W3值。根据线性模型, 加入喂入数据权重w, 与偏差值b, 建立线性方程。yield_apple = w11 * temp + w12 * rainfall + w13 * humidity + b1yield_orange = w21 * temp + w22 * rain..
2020-08-30 23:13:07 819
原创 深度学习pytorch- tensor和numpy相互转换torch.from_numpy()
处理批量数据时, 经常需要tensor和numpy的相互转化torch.from_numpy(x), 将x 转换为torch类型y.numpy(), 将y由tensor转化为numpyimport numpy as npx = np.array([[1, 2], [3, 4.]])xarray([[1., 2.],[3., 4.]])# Convert the numpy array to a torch tensor.y = torch.from_numpy(x)yte.
2020-08-30 20:22:20 3664
原创 深度学习pytorch- tensor, 基本运算与梯度gradient和backward
与numpy中的基本操作相似, pytorch 的作用是引入GPU加快运算, 增加图形界面, 适合大数据运算, 尤其是deep learninggradient 梯度类似于求导, 找到梯度下降的最佳路径。tensor 除了可以进行线性代数运算, 还可以求梯度。建立三个tensor:# Create tensors.import torchx = torch.tensor(3.) # 数字w = torch.tensor(4., requires_grad=True) # 数字b = to.
2020-08-30 20:10:08 1373
原创 深度学习pytorch- tensor, dtype 和 shape
tensorsnum.代表float类型, 一般只用写一个数字, 代表整体。shape: 矩阵大小float32 数字类型tensor 可以表示数字, 1, 2, 3,…, n 维矩阵。import torch# Numbert1 = torch.tensor(1.)t1tensor(1.)t1.dtypetorch.float32t1.shapetorch.Size([])# Vectort2 = torch.tensor([1., 2, 3, 4])
2020-08-30 19:29:49 881
原创 python 游戏- pygame space invader
# pygame install: windows: cmd: pip install pygameimport pygamefrom os import pathimport randomimport math# init the pygamepygame.init()# create the screenscreen = pygame.display.set_mode((800, 600))# title and iconpygame.display.set_caption(.
2020-08-29 21:18:06 202
原创 pytorch-用线性回归预测水果产量
假设有如下数据集, 如何预测水果产量假设水果产量与地区无关, 与只与温度, 降雨量, 湿度有关, 若用线性模型预测, 可以通过线性回归的方法, 预测产量。加入线性无关, 通过蓝色方框参数可以求解W1, W2, W3值。根据线性模型, 加入喂入数据权重w, 与偏差值b, 建立线性方程。yield_apple = w11 * temp + w12 * rainfall + w13 * humidity + b1yield_orange = w21 * temp + w22 * rain..
2020-08-29 17:53:49 1829
原创 torch-tensor 和numpy的转化
import numpy as npx = np.array([[1, 2], [3, 4.]])xarray([[1., 2.],[3., 4.]])# Convert the numpy array to a torch tensor.y = torch.from_numpy(x)ytensor([[1., 2.],[3., 4.]], dtype=torch.float64)x.dtype, y.dtype(dtype(‘float64’), torch.flo
2020-08-29 15:04:47 2029
原创 pytorch-tensor基本操作与求导
tensor相当于表示n维矩阵import torch# Numbert1 = torch.tensor(4.)t1tensor(4.)代表float类型一个数字t1.dtypetorch.float32# Vectort2 = torch.tensor([1., 2, 3, 4])t2tensor([1., 2., 3., 4.])# Matrixt3 = torch.tensor([[5., 6], [7, 8], .
2020-08-29 14:56:42 908
原创 pytlhon-matplotlib.pyplot, numpy绘图功能3d
from mpl_toolkits import mplot3d%matplotlib inlineimport numpy as npimport matplotlib.pyplot as pltfig = plt.figure()ax = plt.axes(projection='3d')
2020-08-29 13:06:28 171
原创 pytlhon-matplotlib.pyplot绘图功能2-d
最基本的线性回归图matplotlib库里的pyplot类似于matlab的功能, 可以plot任何曲线。可以加x轴, y轴标记。默认x轴从0开始。import matplotlib.pyplot as pltplt.plot([1, 2, 3, 4]) # y = [1, 2, 3, 4]plt.ylabel('some numbers') # add y axisplt.xlabel('x axis') # x = [0, 1, 2, 3] by defaultplt.show().
2020-08-29 12:50:29 208
原创 python-numpy表示1, 2, 3维矩阵
一维数组arr = np.random.random()arr0.06183590466429245arr = np.random.random(size = 3)arrarray([0.2383645 , 0.95909024, 0.057593 ])#Return : Array of random floats in the interval [0.0, 1.0). or a single such random float if size not provided.二维矩阵.
2020-08-28 20:43:14 1528
原创 python-numpy基础知识-科学计算转置与矩阵乘积
基本运算import numpy as np a = np.array([1, 2, 5, 3]) # add 1 to every element print ("Adding 1 to every element:", a+1) # subtract 3 from each element print ("Subtracting 3 from each element:", a-3) # multiply each element by 10 print (".
2020-08-28 19:14:55 907
原创 python-numpy基础知识-科学计算
1. 创建numpy array一维数组:import numpy as nparr = np.array([0, 1, 2, 3, 4, 5])arrarray([0, 1, 2, 3, 4, 5])二维数组:arr = np.array([[1, 2, 3], [4, 5, 6]])arrarray([[1, 2, 3], [4, 5, 6]])通过tuple 创建arr = np.array((1, 3, 2))arrarra
2020-08-28 18:58:33 122
原创 python算法-迭代与递归求fibonacci number
Recursive fibonacci number# NO.8 fibonacci number, this method takes time and is inefficientdef fibo_recur(n): if n <= 1: return n return fibo_recur(n - 1) + fibo_recur(n - 2)fibo_recur(35)Iterative fibonacci numberdef iterativ.
2020-08-28 16:05:51 130
原创 python算法-迭代与递归求乘积
Iterative product of 2 natural numbersdef product_iter(a, b): # iteration product '''consider all natural numbers''' if b == 0: return b for i in range(b): if i == b - 1: return a return a + product_iter(a.
2020-08-28 16:02:17 406
原创 python算法-迭代与递归求阶乘
Iterative factorialdef fact_iter(n): # considering 0! for prod = 1 prod = 1 for i in range (1, n+1): prod *= i return prodfact_iter(5)Recursive factorialdef fact_recur(n): '''assume n >= 0''' if n <= 1: r.
2020-08-28 15:59:12 729
原创 python算法-二分查找算法
Bicection search a number in a listdef bicect_search(L, e): if L == []: return False elif len(L) == 1: return L[0] == e else: half = len(L) // 2 if L[half] > e: return bicect_search(L[: half], e)
2020-08-28 15:53:31 69
原创 python算法-将整数转化为字符窜
方法1:def int_to_str(i): digits = '0123456789' # define a string if i == 0: return '0' res = '' while i > 0: res = digits[i % 10] + res # index a string i = i // 10 return resint_to_str(89445)方法二:def i.
2020-08-28 15:48:14 465
原创 关于win10 系统Anaconda中环境变量与pytorch的安装
关于win10 系统Anaconda中环境变量与pytorch的安装首先python 2 已经于2020年停止跟新与维护, 望果断放弃安装。安照官网安装anacondaanaconda 最新版自带Jupyter, spider.win10不需要匹配环境变量打开anaconda prompt, 直接安装https://pytorch.org/get-started/locally/#mac-pythonRun this Command:conda install pytorch torchv
2020-08-28 12:27:29 239
原创 深度学习-如何最优化训练线性模型-举例 loss function
import numpy as np import matplotlib .pyplot as pltx_data = [1.0, 2.0, 3.0] # training list inputy_data = [2.0, 4.0, 6.0] # training list inputdef forward(x): # linear model return x * wdef loss(x, y): # loss function y_pred = forward(x)
2020-08-27 20:39:50 379
原创 损失函数 loss function
加入有以下数据集如何预测x = 4 时, y 的值?实际函数为y = 2x, 如果按照y = 3x, 预测:会得到以下结果:损失函数前面系数加 1/2 为了积分运算方便。损失函数计算结果决定学习的情况, mean值越小, 学习越接近实际值。...
2020-08-27 19:10:51 557
原创 python 游戏开发jumpy platform 终板
# pygame template - skeleton for a new python project# Jumpy: a platform game# file I/Oimport pygame as pgimport randomimport osvec= pg.math.Vector2from os import pathfrom random import choice, randrangeWIDTH = 900 # 360HEIGHT = 800 # 480# F
2020-08-27 16:31:45 171
原创 python跳跃平台类游戏开发实例(三)
接python跳跃平台类游戏开发实例(二)增加视窗滚动功能在这里插入代码片```# pygame template - skeleton for a new python projectimport pygame as pgimport randomimport osvec= pg.math.Vector2WIDTH = 800 # 360HEIGHT = 800 # 480# FRAME PER SECONDFPS = 60 # define colorsPLAYE
2020-08-27 15:39:41 287
原创 python跳跃平台类游戏开发实例(二)
接python跳跃平台类游戏开发实例(一)增加移动角色和平台调用功能# pygame template - skeleton for a new python projectimport pygame as pgimport osvec= pg.math.Vector2WIDTH = 800 # 360HEIGHT = 800 # 480# FRAME PER SECONDFPS = 60 # define colorsPLAYER_ACC = 0.5PLAYER_FR
2020-08-27 15:11:31 248
原创 python跳跃平台类游戏开发实例(一)
首先引入pygame 和 游戏最常用的 random 方法运行后达到以下结果:# pygame template - skeleton for a new python projectimport pygameimport random具体pygame 版本可到官网安装:pygame 1.9.6Hello from the pygame community. https://www.pygame.org/contribute.htmlwindow初始化, 默认为黑色WIDT.
2020-08-27 15:00:51 656
原创 python游戏 pygame- STARSHIP BASICS
设计游戏标题与游戏框背景与大小# define screen size: pixelsimport pygameWIDTH = 800 HEIGHT = 600 # define framesFPS = 30 # define colorsWHITE = (255, 255, 255)BLACK = (0, 0, 0)RED = (255, 0, 0)GREEN = (0, 255, 255)BLUE = (0, 0, 255)# initialize pygame and.
2020-08-27 14:14:10 89
原创 python游戏-space shooter
第一步:构建基本框架当前需要达到基本的模型:2.构建屏幕大小,可移动敌人与可移动游戏角色。# pygame template - skeleton for a new python project, shmup gameimport pygameimport random# define screen sizeWIDTH = 480 # 360HEIGHT = 600 # 480# FRAME PER SECONDFPS = 60 # define colorsWHI
2020-08-27 13:53:56 322
原创 如何构建神经网络中的神经元(pytorch 前置知识)
构建最简单的perceptrons首先需要对生物学里的神经元有一个基本理解对于深度学习, 只需知道神经细胞的两大部分, 轴突和树突, 了解它们之间是如何传递信息的, 因为感知器是完全按照这一逻辑构建, 虽然无法达到人类的神经细胞全部功能, 但是目前最好的, 最简单的数学模型。轴突和树突之间要进行信号的传递, 即为输入和输出,传递的结果可能被激活也可能没有。单一神经元模型输入为x1, x2, 1, 当然也可以有几百几千个输入, 输入的每一个值需要乘以相应的权重, w1, w2, w0, 其中w
2020-08-27 10:27:51 1098
原创 关于deep learning 的概率论与性息理论知识(一)
关于deep learning 的概率论与性息理论知识学习概率论的原因:分析为什么要选择这样的deep learning 模型判断选择该种模型为什么得出这样的结果。概率论相关知识:为什么要学习概率论:在一般的软件或程序运行中, CPU的计算速率或者代码的输入值基本是固定的,输出也基本固定, 或者可用Big-Oh分析。但在机器学习或深度学习的过程中, 会考虑到CPU故障, 机器故障等参数, 这些参数大部分是可变的, 所以通过概率的引入更能够模拟实际中的情况。比如:Inherent sto
2020-08-26 16:16:04 173
原创 关于deep learning的线性代数
如果精通线性代数, 可以跳过本部分。构建神经网路首先需要构建感知器, 感知器即为最基本的神经元, 为线性模型, 需要基本线性代数知识。通过多重神经网络的构建即可达到深度学习的目的。scalers, vectors, matrix and tensors. 分别为scalers: 代表一个数字常量vectors: 向量matrix:tensors: 表示二维以上空间中的点Ai,j,k矩阵的转置, 相乘, 点积转置:相乘:基本公式:向量点积:矩阵乘积转置:线性方程三种
2020-08-25 22:35:31 125
原创 关于Anaconda中pytorch的安装
关于Anaconda中pytorch的安装 学习deeplearning 的第一步应该是安装主流的Pytorch, 主要是在Python 3 环境下更容易入手。对于初学python, 如果要向AI方向发展, 建议安装anaconda, 安装后如果Python没有激活conda, 需要安装一下步骤激活:学习deeplearning 的第一步应该是安装主流的Pytorch, 主要是在Python 3 环境下更容易入手。对于初学python, 如果要向AI方向发展, 建议安装anaconda, 安装后如果Py
2020-08-25 21:38:07 498
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人