深度学习与PyTorch入门实战 - 18.2 LOSS及其梯度Error ## Cross Entropy Loss binary multi-class +softmax Leave it to Logistic Regression Part ## MSE $$ \begin{aligned} ■ loss=\sum[y-(xw+b)]^{2}\end{aligned} $$ $$ \left.\begin{array}{l}L2-norm x=torch.ones(1) In [17]: w=torch.full([1],2) In [19]: mse=F.mse_loss(torch.ones(1), x*w) Out[20]: tensor(1.) In [21]: torch.autograd.grad(mse,[w]) #RuntimeError: element 0 of tensors does not require autograd.grad(mse,[w]) #RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn In [24]: mse=F.mse_loss(torch.ones(1), x*w) In [25]: torch.autograd.grad(mse, [w]) Out[25]:0 码力 | 14 页 | 989.18 KB | 2 年前3
PyTorch Tutorial(monitor training) • PyTorchViz (visualise computation graph) • Various other functions • loss (MSE, CE etc...) • optimizers ## Prepare Train Input Data Evaluate Model Model • Load data • Train • L1, MSE, Cross Entropy ..... a = torch.randn(1, requires_grad=True, dtype=torch.float, device=device) b = torch.randn(1, requires_grad=True, dtype=torch.float, device=device) # Defines a MSE loss function device=device) b = torch.randn(1, requires_grad=True, dtype=torch.float, device=device) # Defines a MSE loss function loss_fn = nn.MSELoss(reduction='mean') optimizer = optim.SGD([a, b], lr=lr) for0 码力 | 38 页 | 4.09 MB | 2 年前3
Swift for TensorFlow - 莲叔sim(i_m, i_b) r_{b,k}}{\sum_{i_b} \left| sim(i_m, i_b) \right|} $$ • Compare with test data $$ mse=\frac{1}{N}\sum_{i}\left(x_{i}-x_{i}'\right)^{2} $$ ## Load Data func loadData(path : String) let result = (rating • similarity / part) return result ## V alidation $$ mse=\frac{1}{N}\sum_{i}\left(x_{i}-x_{i}'\right)^{2} $$ • We sliced 25% of the data into the test predicted before will give us a reasonable measurement for the algorithm func mse(pred : [Float], truth : [Float]) -> Float { var mse:Float = 0.0 var count = 0 = zip(Range(NSMakeRange(0, pred.count)), truth)0 码力 | 56 页 | 3.03 MB | 2 年前3
云原生微服务最佳实践jpg) 可变运行时 Dubbo+Nacos/Envoy+Istio 控制流量提升系统高可用 容器 不可变基础设施 K8s 调度提高资源利用率 ## Function / SAE MSE 微服务(中心) ACK 业务 Serverless平台 K8s(张北1) 微服务(优酷) 微服务(考拉) K8s(张北2) K8s(张北3) ## 微服务的价值和挑战  ## 解法 - 提供完整微服务产品矩阵 - 通过 MSE 解决微服务最核心服务发现和配置管理,通过服务治理提升高可用 - 通过 ACK 解决运维成本 - 通过 ARMS 解决定位成本 - 通过 AHAS 解决技术风险 - 通过 PTS 解决容量风险 • 网关最佳实践 ## 微服务最佳实践 微服务引擎(Micro Service Engine,简称 MSE)是一个面向业界主流开源微服务生态的一站式微服务平台 三位一体:阿里微服务 DNS 开源最佳实践 + 产品灵活组合 & 开箱即用 + 经过阿里双十一考验的默认高可用能力 MSE微服务引擎 Ingress (Envoy) 云原生网关 ) AS MSE FROM SELECT evalMLMethod(model, trip_distance) - total_amount AS diff FROM trips_merge_tree_third LEFT JOIN models ON year = toYear(pickup_datetime) MSE 4.145554613376103 sqrt(avg(diff * diff)) AS MSE FROM SELECT modelEvaluate('trip_price', ...) - total_amount AS diff FROM trips WHERE <...> MSE 3.8519197052953755 ## Models comparison ||MSE| |---|---| |simp ## TODO ## List of features it is good to implement: > Loss functions (as aggregate function): MSE, MAE, logloss, ... > Shuffle for minibatches (as table function) > Table function to sample0 码力 | 64 页 | 1.38 MB | 2 年前3
0. Machine Learning with ClickHouse sqrt(avg(diff * diff)) AS MSE FROM SELECT evalMLMethod(model, trip_distance) - total_amount AS diff FROM trips_merge_tree_third LEFT JOIN models ON year = toYear(pickup_datetime) MSE 4.145554613376103 sqrt(avg(diff * diff)) AS MSE FROM SELECT modelEvaluate('trip_price', ...) - total_amount AS diff FROM trips WHERE <...> MSE 3.8519197052953755 ## Models comparison ||MSE| |---|---| |simp ## TODO ## List of features it is good to implement: > Loss functions (as aggregate function): MSE, MAE, logloss, ... > Shuffle for minibatches (as table function) > Table function to sample0 码力 | 64 页 | 1.38 MB | 2 年前3
【PyTorch深度学习-龙龙老师】-测试版202112i=1}^{n}\left(w x^{(i)}+b-y^{(i)}\right)^{2} $$ 其中n表示采样点的个数。这种误差计算方法称为均方误差(Mean Squared Error,简称MSE)。 ### 2.2 优化方法 现在来小结一下上述方案:目标是估计参数w和b,使得输入和输出满足线性关系 $ y^{(i)}=wx^{(i)}+b,i\in[1,n] $ 。但是由于观测误差 $ 计算误差 循环计算函数在每个点 $ \left(x^{(i)},y^{(i)}\right) $ 处的预测值与真实值之间差的平方并累加,从而获得训练集上的均方误差损失值。代码如下: def mse(b, w, points): # 根据当前的 w,b 参数计算均方差损失 # 计算差的平方,并累加 totalError += (y - (w * x + b)) ** 2 # 将累加的误差求平均,得到均方差 range(num_iterations): # 计算梯度并更新一次 b, w = step_gradient(b, w, np.array(points), lr) loss = mse(b, w, points) # 计算当前的均方差,用于监控训练进度 if step % 50 == 0: # 打印误差和实时的 w, b 值 print0 码力 | 439 页 | 29.91 MB | 2 年前3
深度学习与PyTorch入门实战 - 25 交叉熵## PyTorch ## 交叉熵 主讲人:龙良曲 ## Why not MSE? |Label|predict|correct| |---|---|---| |3|\[0.3, 0.3, 0.4]|yes| |2|\[0.3, 0.4, 0.3]|yes| |1|\[0.1, 0.2, 0.7]|no| |Label|predict|correct| |---|---|---| |3|\[0 0.7]|yes| |2|\[0.1, 0.7, 0.2]|yes| |1|\[0.3, 0.4, 0.3]|no| 0.54 0.34 ## Loss for classification MSE Cross Entropy Loss Hinge Loss $$ \sum_{i}max(0,1-y_{i}*h_{\theta}(x_{i})) $$ \\&=-\log0.98\\&\approx0.02\\ \end{aligned} $$ ## why not use MSE ■ gradient vanish - converge slower But, sometimes e.g. meta-learning  $$ \mathrm{MSE}=\frac{1}{m}\sum_{i=1}^{m}(y^{(i)}-\widehat{y}^{(i)})^{2} $$ 平均绝对误差(Mean Absolute Error i)}-\widehat{y}^{(i)})^{2}/m}{\sum_{i=1}^{m}(y^{(i)}-\overline{y})^{2}/m}\\ &=1-\frac{\mathrm{MSE}}{\mathrm{Var}}\\ \end{aligned} $$ $$ SSR = \sum_{i=1}^{m} (\widehat{y}^{(i)} - \overline{y})^20 码力 | 33 页 | 1.50 MB | 2 年前3
深度学习与PyTorch入门实战 - 24. Logistic Regression
of correct is not continuous ### Q2. why call logistic regression use sigmoid - Controversial! MSE => regression - Cross Entropy => classification 0.7 0.7 0.3 ## Binary Classification $$ p(y=1|x)\end{aligned} $$ • if $ p(y = 1|x) > 0.5 $ , predict as 1 - else predict as 0 minimize MSE ## confused? http://www.fharrell.com/post/classification/ ## Multi-class classification $$ \be0 码力 | 12 页 | 798.46 KB | 2 年前3
共 36 条
- 1
- 2
- 3
- 4













