网站技术培训班有哪些种类,阿里云零基础网站建设教学,网站开发工程师 能做什么,重庆公司建网站流程#x1f3af;要点
#x1f3af;衍射光学卷积算法模拟 | #x1f3af;模拟或数字电子计算之前加入一层光学计算 | #x1f3af;前馈卷积神经网络计算成像系统对输入图像进行分类 | #x1f3af;相位掩模利用线性空间不变成像系统执行固有卷积
#x1f4dc;用例 Python非…要点
衍射光学卷积算法模拟 | 模拟或数字电子计算之前加入一层光学计算 | 前馈卷积神经网络计算成像系统对输入图像进行分类 | 相位掩模利用线性空间不变成像系统执行固有卷积
用例 Python非线性光学映射数据压缩算法
语言内容分比 Python随机梯度下降算法
成本函数或损失函数是通过改变决策变量来最小化或最大化的函数。许多机器学习方法都在解决表面下的优化问题。它们倾向于通过调整模型参数如神经网络的权重和偏差、随机森林或梯度提升的决策规则等来最小化实际输出和预测输出之间的差异。
在回归问题中通常具有输入变量 x ( x 1 , … , x r ) x \left(x_1, \ldots, x_r\right) x(x1,…,xr) 的向量和实际输出 y y y。您想要找到一个将 x x x 映射到预测响应 f ( x ) f( x ) f(x) 的模型以便 f ( x ) f( x ) f(x) 尽可能接近 y y y。例如您可能想要根据某人在公司工作的年数或教育水平等输入来预测某人的工资等输出。
您的目标是最小化预测 f ( x ) f( x ) f(x) 与实际数据 y y y 之间的差异。这种差异称为残差。在此类问题中您希望最小化残差平方和其残差平方和 Σ i ( y i − f ( x i ) ) 2 \Sigma_{ i }\left(y_{ i }-f\left( x _{ i }\right)\right )^2 Σi(yi−f(xi))2 对于所有观测值 i 1 , … , n i1, \ldots, n i1,…,n其中 n n n 是观测值总数。或者您可以使用均方误差 (MSE SSR / n ) \operatorname{SSR} / n) SSR/n) 代替残差平方和。
最小化残差平方和和均方误差都使用实际输出和预测输出之差的平方。差异越小预测越准确。差异为零表示预测与实际数据相同。
通过调整模型参数来最小化残差平方和或均方误差。例如在线性回归中你想要找到函数 f ( x ) b 0 b 1 x 1 ⋯ b r x r f( x )b_0b_1 x_1\cdotsb_{ r } x_{ r } f(x)b0b1x1⋯brxr因此你需要确定权重 b 0 , b 1 , … , b r b_0, b_1, \ldots , b_{ r } b0,b1,…,br 最小化残差平方和或均方误差。
在分类问题中输出 y y y 是分类的通常为 0 或 1 。例如您可能尝试预测电子邮件是否是垃圾邮件。在二进制输出的情况下可以方便地最小化交叉熵函数该函数也取决于实际输出 y i y_{ i } yi 和相应的预测 p ( x i ) p\left( x _{ i }\right) p(xi) H − ∑ i ( y i log ( p ( x i ) ) ( 1 − y i ) log ( 1 − p ( x i ) ) ) H-\sum_i\left(y_i \log \left(p\left( x _i\right)\right)\left(1-y_i\right) \log \left(1-p\left( x _i\right)\right)\right) H−i∑(yilog(p(xi))(1−yi)log(1−p(xi))) 在常用于解决分类问题的逻辑回归中函数 p ( x ) p( x ) p(x) 和 f ( x ) f( x ) f(x) 定义如下 p ( x ) 1 1 exp ( − f ( x ) ) f ( x ) b 0 b 1 x 1 ⋯ b r x r \begin{gathered} p( x )\frac{1}{1\exp (-f( x ))} \\ f( x )b_0b_1 x_1\cdotsb_r x_r \end{gathered} p(x)1exp(−f(x))1f(x)b0b1x1⋯brxr 同样您需要找到权重 b 0 、 b 1 、 … 、 b r b_0、b_1、\ldots、b_r b0、b1、…、br但这一次它们应该最小化交叉熵函数。
在微积分中函数的导数显示当您修改其参数时值的变化量。导数对于优化很重要因为零导数可能表示最小值、最大值或鞍点。
多个自变量 v 1 , … , v r v_1, \ldots, v_{ r } v1,…,vr 的函数 C C C 的梯度用 ∇ C ( v 1 , … , v r ) \nabla C\left(v_1, \ldots, v_{ r }\right) ∇C(v1,…,vr) 表示并定义为 C C C 对每个自变量的偏导数的向量函数 ∇ C ( ∂ C / ∂ v 1 , … , ∂ C / v r ) \nabla C\left(\partial C / \partial v_1, \ldots, \partial C / v_r\right) ∇C(∂C/∂v1,…,∂C/vr)。符号 ∇ \nabla ∇ 称为 nabla。
函数 C C C 在给定点的梯度的非零值定义了 C C C 最快增长的方向和速率。使用梯度下降时您对成本函数下降最快的方向感兴趣。该方向由负梯度 − ∇ C -\nabla C −∇C 确定。
基本梯度下降
这是该算法的基本实现从任意点开始迭代地将其移向最小值并返回一个有望达到或接近最小值的点
def gradient_descent(gradient, start, learn_rate, n_iter):vector startfor _ in range(n_iter):diff -learn_rate * gradient(vector)vector diffreturn vector在应用gradient_descent()之前您可以添加另一个终止条件
import numpy as npdef gradient_descent(gradient, start, learn_rate, n_iter50, tolerance1e-06
):vector startfor _ in range(n_iter):diff -learn_rate * gradient(vector)if np.all(np.abs(diff) tolerance):breakvector diffreturn vector您只需要一条语句来测试梯度下降实现 gradient_descent(
... gradientlambda v: 2 * v, start10.0, learn_rate0.2
... )
2.210739197207331e-06随机梯度下降算法
随机梯度下降算法是梯度下降的一种改进。在随机梯度下降中您仅使用观测值的随机一小部分而不是全部来计算梯度。在某些情况下这种方法可以减少计算时间。
import numpy as npdef sgd(gradient, x, y, start, learn_rate0.1, batch_size1, n_iter50,tolerance1e-06, dtypefloat64, random_stateNone
):if not callable(gradient):raise TypeError(gradient must be callable)dtype_ np.dtype(dtype)x, y np.array(x, dtypedtype_), np.array(y, dtypedtype_)n_obs x.shape[0]if n_obs ! y.shape[0]:raise ValueError(x and y lengths do not match)xy np.c_[x.reshape(n_obs, -1), y.reshape(n_obs, 1)]seed None if random_state is None else int(random_state)rng np.random.default_rng(seedseed)vector np.array(start, dtypedtype_)learn_rate np.array(learn_rate, dtypedtype_)if np.any(learn_rate 0):raise ValueError(learn_rate must be greater than zero)batch_size int(batch_size)if not 0 batch_size n_obs:raise ValueError(batch_size must be greater than zero and less than or equal to the number of observations)n_iter int(n_iter)if n_iter 0:raise ValueError(n_iter must be greater than zero)tolerance np.array(tolerance, dtypedtype_)if np.any(tolerance 0):raise ValueError(tolerance must be greater than zero)for _ in range(n_iter):rng.shuffle(xy)for start in range(0, n_obs, batch_size):stop start batch_sizex_batch, y_batch xy[start:stop, :-1], xy[start:stop, -1:]grad np.array(gradient(x_batch, y_batch, vector), dtype_)diff -learn_rate * gradif np.all(np.abs(diff) tolerance):breakvector diffreturn vector if vector.shape else vector.item()随机梯度下降的动量
import numpy as npdef sgd(gradient, x, y, start, learn_rate0.1, decay_rate0.0, batch_size1,n_iter50, tolerance1e-06, dtypefloat64, random_stateNone
):if not callable(gradient):raise TypeError(gradient must be callable)dtype_ np.dtype(dtype)x, y np.array(x, dtypedtype_), np.array(y, dtypedtype_)n_obs x.shape[0]if n_obs ! y.shape[0]:raise ValueError(x and y lengths do not match)xy np.c_[x.reshape(n_obs, -1), y.reshape(n_obs, 1)]seed None if random_state is None else int(random_state)rng np.random.default_rng(seedseed)vector np.array(start, dtypedtype_)learn_rate np.array(learn_rate, dtypedtype_)if np.any(learn_rate 0):raise ValueError(learn_rate must be greater than zero)decay_rate np.array(decay_rate, dtypedtype_)if np.any(decay_rate 0) or np.any(decay_rate 1):raise ValueError(decay_rate must be between zero and one)batch_size int(batch_size)if not 0 batch_size n_obs:raise ValueError(batch_size must be greater than zero and less than or equal to the number of observations)n_iter int(n_iter)if n_iter 0:raise ValueError(n_iter must be greater than zero)tolerance np.array(tolerance, dtypedtype_)if np.any(tolerance 0):raise ValueError(tolerance must be greater than zero)diff 0for _ in range(n_iter):# Shuffle x and yrng.shuffle(xy)for start in range(0, n_obs, batch_size):stop start batch_sizex_batch, y_batch xy[start:stop, :-1], xy[start:stop, -1:]grad np.array(gradient(x_batch, y_batch, vector), dtype_)diff decay_rate * diff - learn_rate * gradif np.all(np.abs(diff) tolerance):breakvector diffreturn vector if vector.shape else vector.item()参阅、更新计算思维 | 亚图跨际 文章转载自: http://www.morning.fbzdn.cn.gov.cn.fbzdn.cn http://www.morning.btrfm.cn.gov.cn.btrfm.cn http://www.morning.bfgbz.cn.gov.cn.bfgbz.cn http://www.morning.dyxlj.cn.gov.cn.dyxlj.cn http://www.morning.fbxdp.cn.gov.cn.fbxdp.cn http://www.morning.xlmgq.cn.gov.cn.xlmgq.cn http://www.morning.hfrbt.cn.gov.cn.hfrbt.cn http://www.morning.kdgcx.cn.gov.cn.kdgcx.cn http://www.morning.nffwl.cn.gov.cn.nffwl.cn http://www.morning.jbfjp.cn.gov.cn.jbfjp.cn http://www.morning.ptslx.cn.gov.cn.ptslx.cn http://www.morning.xinyishufa.cn.gov.cn.xinyishufa.cn http://www.morning.hrkth.cn.gov.cn.hrkth.cn http://www.morning.bnzjx.cn.gov.cn.bnzjx.cn http://www.morning.nbwyk.cn.gov.cn.nbwyk.cn http://www.morning.jrhmh.cn.gov.cn.jrhmh.cn http://www.morning.bxrlt.cn.gov.cn.bxrlt.cn http://www.morning.pxmyw.cn.gov.cn.pxmyw.cn http://www.morning.sfrw.cn.gov.cn.sfrw.cn http://www.morning.qxlgt.cn.gov.cn.qxlgt.cn http://www.morning.zrgx.cn.gov.cn.zrgx.cn http://www.morning.ckctj.cn.gov.cn.ckctj.cn http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn http://www.morning.rxwnc.cn.gov.cn.rxwnc.cn http://www.morning.wrlxy.cn.gov.cn.wrlxy.cn http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn http://www.morning.gbsfs.com.gov.cn.gbsfs.com http://www.morning.rjkfj.cn.gov.cn.rjkfj.cn http://www.morning.bbrf.cn.gov.cn.bbrf.cn http://www.morning.lffgs.cn.gov.cn.lffgs.cn http://www.morning.kpbq.cn.gov.cn.kpbq.cn http://www.morning.leeong.com.gov.cn.leeong.com http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.nkhdt.cn.gov.cn.nkhdt.cn http://www.morning.dddcfr.cn.gov.cn.dddcfr.cn http://www.morning.qyglt.cn.gov.cn.qyglt.cn http://www.morning.mlwpr.cn.gov.cn.mlwpr.cn http://www.morning.wnkqt.cn.gov.cn.wnkqt.cn http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.dodoking.cn.gov.cn.dodoking.cn http://www.morning.gtxrw.cn.gov.cn.gtxrw.cn http://www.morning.gfnsh.cn.gov.cn.gfnsh.cn http://www.morning.zxqqx.cn.gov.cn.zxqqx.cn http://www.morning.vibwp.cn.gov.cn.vibwp.cn http://www.morning.bmjfp.cn.gov.cn.bmjfp.cn http://www.morning.ngjpt.cn.gov.cn.ngjpt.cn http://www.morning.zlff.cn.gov.cn.zlff.cn http://www.morning.mbbgk.com.gov.cn.mbbgk.com http://www.morning.ztjhz.cn.gov.cn.ztjhz.cn http://www.morning.rnrwq.cn.gov.cn.rnrwq.cn http://www.morning.gjqwt.cn.gov.cn.gjqwt.cn http://www.morning.rmfh.cn.gov.cn.rmfh.cn http://www.morning.wmsgt.cn.gov.cn.wmsgt.cn http://www.morning.ccsdx.cn.gov.cn.ccsdx.cn http://www.morning.jqpq.cn.gov.cn.jqpq.cn http://www.morning.fqqcd.cn.gov.cn.fqqcd.cn http://www.morning.nrgdc.cn.gov.cn.nrgdc.cn http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn http://www.morning.cnyqj.cn.gov.cn.cnyqj.cn http://www.morning.dshxj.cn.gov.cn.dshxj.cn http://www.morning.qfplp.cn.gov.cn.qfplp.cn http://www.morning.plpqf.cn.gov.cn.plpqf.cn http://www.morning.qhtlq.cn.gov.cn.qhtlq.cn http://www.morning.ykklw.cn.gov.cn.ykklw.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.sqqdy.cn.gov.cn.sqqdy.cn http://www.morning.xmnlc.cn.gov.cn.xmnlc.cn http://www.morning.lhytw.cn.gov.cn.lhytw.cn http://www.morning.dkbgg.cn.gov.cn.dkbgg.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.grryh.cn.gov.cn.grryh.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.rxpp.cn.gov.cn.rxpp.cn http://www.morning.zhghd.cn.gov.cn.zhghd.cn http://www.morning.crrmg.cn.gov.cn.crrmg.cn http://www.morning.xbrxk.cn.gov.cn.xbrxk.cn http://www.morning.smygl.cn.gov.cn.smygl.cn