SMO算法,platt论文的原始算法及优化算法

[复制链接]
发表于 2026-2-16 04:26:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
 platt论文:[PDF] Sequential Minimal Optimization : A Fast Algorithm for Training Support Vector Machines | Semantic Scholar
算法优化:[PDF] Improvements to Platt's SMO Algorithm for SVM Classifier Design | Semantic Scholar
包罗个人platt版SMO代码实现、SMO 优化算法、libsvm:yanzhi0922/SVM: 2024.07.12 (github.com)
数据集获取:LIBSVM Data: Classification, Regression, and Multi-label (ntu.edu.tw)
platt原论文SMO伪代码:
  1. target = desired output vector
  2. point = training point matrix
  3. procedure takeStep(i1,i2)
  4.     if (i1 == i2) return 0
  5.     alph1 = Lagrange multiplier for i1
  6.     y1 = target[i1]
  7.     E1 = SVM output on point[i1] – y1 (check in error cache)
  8.     s = y1*y2
  9.     Compute L, H via equations (13) and (14)
  10.     if (L == H)
  11.         return 0
  12.     k11 = kernel(point[i1],point[i1])
  13.     k12 = kernel(point[i1],point[i2])
  14.     k22 = kernel(point[i2],point[i2])
  15.     eta = k11+k22-2*k12
  16.     if (eta > 0)
  17.     {
  18.         a2 = alph2 + y2*(E1-E2)/eta
  19.         if (a2 < L) a2 = L
  20.         else if (a2 > H) a2 = H
  21.     }
  22.     else
  23.     {
  24.         Lobj = objective function at a2=L
  25.         Hobj = objective function at a2=H
  26.         if (Lobj < Hobj-eps)
  27.             a2 = L
  28.         else if (Lobj > Hobj+eps)
  29.             a2 = H
  30.         else
  31.             a2 = alph2
  32.     }
  33.     if (|a2-alph2| < eps*(a2+alph2+eps))
  34.         return 0
  35.     a1 = alph1+s*(alph2-a2)
  36.     Update threshold to reflect change in Lagrange multipliers
  37.     Update weight vector to reflect change in a1 & a2, if SVM is linear
  38.     Update error cache using new Lagrange multipliers
  39.     Store a1 in the alpha array
  40.     Store a2 in the alpha array
  41.     return 1
  42. endprocedure
  43. procedure examineExample(i2)
  44.     y2 = target[i2]
  45.     alph2 = Lagrange multiplier for i2
  46.     E2 = SVM output on point[i2] – y2 (check in error cache)
  47.     r2 = E2*y2
  48.     if ((r2 < -tol && alph2 < C) || (r2 > tol && alph2 > 0))
  49.     {
  50.         if (number of non-zero & non-C alpha > 1)
  51.         {
  52.             i1 = result of second choice heuristic (section 2.2)
  53.             if takeStep(i1,i2)
  54.                 return 1
  55.         }
  56.         loop over all non-zero and non-C alpha, starting at a random point
  57.         {
  58.             i1 = identity of current alpha
  59.             if takeStep(i1,i2)
  60.                 return 1
  61.         }
  62.         loop over all possible i1, starting at a random point
  63.         {
  64.             i1 = loop variable
  65.             if (takeStep(i1,i2)
  66.                 return 1
  67.         }
  68.     }
  69.     return 0
  70. endprocedure
  71. main routine:
  72.     numChanged = 0;
  73.     examineAll = 1;
  74.     while (numChanged > 0 | examineAll)
  75.     {
  76.         numChanged = 0;
  77.         if (examineAll)
  78.             loop I over all training examples
  79.                 numChanged += examineExample(I)
  80.         else
  81.             loop I over examples where alpha is not 0 & not C
  82.                 numChanged += examineExample(I)
  83.         if (examineAll == 1)
  84.             examineAll = 0
  85.         else if (numChanged == 0)
  86.             examineAll = 1
  87. }
复制代码
以上算法根本原理雷同,效果雷同,优化是时间复杂度上的优化 ,libsvm时间复杂度最优


回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表