CS231n Optimization: Stochastic Gradient Descent

loss function

loss function是优化的源泉,不同的loss function会有不同的效果,比如说svm的loss和softmax,svm相当于就是点到为止,经过映射之后,只要两者的差距要比delta大,那么其实就满足了,而softmax永不满足,一个概率分布,只要错误的概率有一点概率的话,其实都是有可能的。

optimization

第一个是在所有的参数空间随机搜索,俗话说,女人心海底针,不过这种方法和海底捞针差不多。

第二个方法是在局部空间随机搜索,也就是首先rand一个随机的起点,然后在邻域中随机搜索,比上一个要稍微好一些,上一个在每一步是在跳动的,但是这一个至少是局部的,跳动的幅度稍微小了一点。

第三个方法是梯度下降
梯度下降的方法实际上更有用一些,因为每一步都可以靠向最优解。

computing the gradient

计算梯度有两种方法,分别是数值计算梯度和通过微积分来计算

感觉其实和cs229有重叠的地方。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The stochastic gradient descent (SGD) algorithm is a popular optimization algorithm used in machine learning. It is an iterative algorithm that updates the model parameters in small steps based on the gradient of the loss function with respect to the parameters. The algorithm works as follows: 1. Initialize the model parameters randomly. 2. Set the learning rate, which determines the step size of the updates. 3. For each training example: - Compute the gradient of the loss function with respect to the parameters using the current example. - Update the model parameters by subtracting the gradient multiplied by the learning rate. The key difference between SGD and regular gradient descent is that in SGD, the gradient is computed and the parameters are updated for each training example, rather than for the entire training set. This makes the algorithm faster and more scalable for large datasets. The stochastic aspect of the algorithm comes from the fact that the training examples are sampled randomly from the training set, rather than being processed in a fixed order. This randomness can help the algorithm escape from local minima and find better solutions. Here is the pseudocode for the SGD algorithm: ``` Input: Training set (X, Y), learning rate α, number of iterations T Output: Model parameters θ Initialize θ randomly for t = 1 to T do Sample a training example (x, y) from (X, Y) randomly Compute the gradient ∇θ L(θ; x, y) using the current example Update the parameters: θ ← θ - α * ∇θ L(θ; x, y) end for return θ ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值