Skip to content

Commit

Permalink
添加6.SVM视频中2个问题的注释
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangzhonglian committed Apr 19, 2017
1 parent 90154ca commit 3cb8b37
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/python/6.SVM/svm-complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ def innerL(i, oS):
return 0

# eta是alphas[j]的最优修改量,如果eta==0,需要退出for循环的当前迭代过程
# 如果ETA为0,那么计算新的alphas[j]就比较麻烦了, 为什么呢? 因为2个值一样。
# 2ab <= a^2 + b^2
# 类似:2ab <= a^2 + b^2
eta = 2.0 * oS.K[i, j] - oS.K[i, i] - oS.K[j, j] # changed for kernel
if eta >= 0:
print("eta>=0")
Expand All @@ -274,6 +273,7 @@ def innerL(i, oS):
# 在对alpha[i], alpha[j] 进行优化之后,给这两个alpha值设置一个常数b。
# w= Σ[1~n] ai*yi*xi => b = yi- Σ[1~n] ai*yi(xi*xj)
# 所以: b1 - b = (y1-y) - Σ[1~n] yi*(a1-a)*(xi*x1)
# 为什么减2遍? 因为是 减去Σ[1~n],当好2个变量i和j,所以减2遍
b1 = oS.b - Ei - oS.labelMat[i] * (oS.alphas[i] - alphaIold) * oS.K[i, i] - oS.labelMat[j] * (oS.alphas[j] - alphaJold) * oS.K[i, j]
b2 = oS.b - Ej - oS.labelMat[i] * (oS.alphas[i] - alphaIold) * oS.K[i, j] - oS.labelMat[j] * (oS.alphas[j] - alphaJold) * oS.K[j, j]
if (0 < oS.alphas[i]) and (oS.C > oS.alphas[i]):
Expand Down
4 changes: 2 additions & 2 deletions src/python/6.SVM/svm-complete_Non-Kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ def innerL(i, oS):
return 0

# eta是alphas[j]的最优修改量,如果eta==0,需要退出for循环的当前迭代过程
# 如果ETA为0,那么计算新的alphas[j]就比较麻烦了, 为什么呢? 因为2个值一样。
# 2ab <= a^2 + b^2
# 类似:2ab <= a^2 + b^2
eta = 2.0 * oS.X[i, :] * oS.X[j, :].T - oS.X[i, :] * oS.X[i, :].T - oS.X[j, :] * oS.X[j, :].T
if eta >= 0:
print("eta>=0")
Expand All @@ -223,6 +222,7 @@ def innerL(i, oS):
# 在对alpha[i], alpha[j] 进行优化之后,给这两个alpha值设置一个常数b。
# w= Σ[1~n] ai*yi*xi => b = yj Σ[1~n] ai*yi(xi*xj)
# 所以: b1 - b = (y1-y) - Σ[1~n] yi*(a1-a)*(xi*x1)
# 为什么减2遍? 因为是 减去Σ[1~n],当好2个变量i和j,所以减2遍
b1 = oS.b - Ei - oS.labelMat[i] * (oS.alphas[i] - alphaIold) * oS.X[i, :] * oS.X[i, :].T - oS.labelMat[j] * (oS.alphas[j] - alphaJold) * oS.X[i, :] * oS.X[j, :].T
b2 = oS.b - Ej - oS.labelMat[i] * (oS.alphas[i] - alphaIold) * oS.X[i, :] * oS.X[j, :].T - oS.labelMat[j] * (oS.alphas[j] - alphaJold) * oS.X[j, :] * oS.X[j, :].T
if (0 < oS.alphas[i]) and (oS.C > oS.alphas[i]):
Expand Down
4 changes: 2 additions & 2 deletions src/python/6.SVM/svm-simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def smoSimple(dataMatIn, classLabels, C, toler, maxIter):
continue

# eta是alphas[j]的最优修改量,如果eta==0,需要退出for循环的当前迭代过程
# 如果ETA为0,那么计算新的alphas[j]就比较麻烦了, 为什么呢? 因为2个值一样。
# 2ab <= a^2 + b^2
# 类似:2ab <= a^2 + b^2
eta = 2.0 * dataMatrix[i, :]*dataMatrix[j, :].T - dataMatrix[i, :]*dataMatrix[i,:].T - dataMatrix[j, :]*dataMatrix[j, :].T
if eta >= 0:
print("eta>=0")
Expand All @@ -147,6 +146,7 @@ def smoSimple(dataMatIn, classLabels, C, toler, maxIter):
# 在对alpha[i], alpha[j] 进行优化之后,给这两个alpha值设置一个常数b。
# w= Σ[1~n] ai*yi*xi => b = yj- Σ[1~n] ai*yi(xi*xj)
# 所以: b1 - b = (y1-y) - Σ[1~n] yi*(a1-a)*(xi*x1)
# 为什么减2遍? 因为是 减去Σ[1~n],当好2个变量i和j,所以减2遍
b1 = b - Ei- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[i,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[i,:]*dataMatrix[j,:].T
b2 = b - Ej- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[j,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[j,:]*dataMatrix[j,:].T
if (0 < alphas[i]) and (C > alphas[i]):
Expand Down

0 comments on commit 3cb8b37

Please sign in to comment.