• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
华东 博客
17年国科大博士毕业,曾就职于三星电子,清华博后,目前在某大模型创业公司工作,研究方向大模型、智能体 新浪博客: http://blog.sina.com.cn/u/2463286753
博客园    首页    新随笔    联系   管理    订阅  订阅
MATLAB 损失函数画图

损失函数画图

  • Hinge loss function:

\[H(z) = max(0,1-z)\]

  • $\psi$-learning loss function: 

\[{\phi _s}(z) = \left\{ {\begin{array}{*{20}{c}}
s&{z < 0}\\
0&{z \ge 0}
\end{array}} \right.\]

  • Normalized Sigmoid loss:

\[{P_t}(z) = 1 - \tanh (tz)\]

  • Ramp loss function:

\[{R_s}(z) = \left\{ {\begin{array}{*{20}{c}}
0&{z > 0}\\
{1 - z}&{0 \le z \le 1}\\
{1 - s}&{z > 1}
\end{array}} \right.\]

 

%plot loss function

%define the loss function
H = @(z)max(0,1-z) ; %Hinge loss function
P = @(z)(2*(z<0)+0*(z>=0)); %\psi-learning loss function
S = @(z)(1-tanh(2*z)); %Normalized Sigmoid loss function
R = @(z)(1*(z<0)+(1-z).*(z>=0&z<1)+0*(z>=1)); % ramp loss

z=-2:0.01:2;
subplot(1,4,1) % plot the 1st figure of 1-4
plot(z,H(z),'-','linewidth',2);
xlabel('z');
title('Hinge loss','fontweight','normal','fontsize',10);
axis([-2,2 0 3])

subplot(1,4,2)
plot(z,P(z),'g-','linewidth',2);
xlabel('z');
title('\psi-learnig loss','fontweight','normal','fontsize',10);
axis([-2,2 0 3])

subplot(1,4,3)
plot(z,S(z),'r-','linewidth',2);
xlabel('z');
title('Normalized Sigmoid loss','fontweight','normal','fontsize',10);
axis([-2,2 0 3])

subplot(1,4,4)
plot(z,R(z),'b-','linewidth',2);
xlabel('z');
title('Ramp loss','fontweight','normal','fontsize',10);
axis([-2,2 0 3])

  

posted on 2016-01-13 14:20  华东博客  阅读(6004)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3