コード例 #1
0
def selectJ(i, oS, Ei):
    maxK = -1
    maxDeltaE = 0
    Ej = 0
    #set corresponding cached value as valid
    oS.eCache[i] = [1,Ei]
    #return the corresponding alpha of non-zero E
    validEcacheList = nonzero(oS.eCache[:,0].A)[0]

    #select the alpha j that maximum abs(Ei - Ek)
    if(len(validEcacheList)) > 1:
        for k in validEcacheList:
            if k == i:
                continue
            Ek = calcEk(oS, k)
            deltaE = abs(Ei - Ek)
            if(deltaE > maxDeltaE):
                maxK = k; maxDeltaE = deltaE; Ej = Ek
        return maxK, Ej

    #if there is no such j, random select a j
    else:
        j = smo.selectJrand(i, oS.m)
        Ej = calcEk(oS,j)
    return j, Ej
コード例 #2
0
def selectJ(i, oS, Ei):
    maxK = -1
    maxDeltaE = 0
    Ej = 0
    #set corresponding cached value as valid
    oS.eCache[i] = [1, Ei]
    #return the corresponding alpha of non-zero E
    validEcacheList = nonzero(oS.eCache[:, 0].A)[0]

    #select the alpha j that maximum abs(Ei - Ek)
    if (len(validEcacheList)) > 1:
        for k in validEcacheList:
            if k == i:
                continue
            Ek = calcEk(oS, k)
            deltaE = abs(Ei - Ek)
            if (deltaE > maxDeltaE):
                maxK = k
                maxDeltaE = deltaE
                Ej = Ek
        return maxK, Ej

    #if there is no such j, random select a j
    else:
        j = smo.selectJrand(i, oS.m)
        Ej = calcEk(oS, j)
    return j, Ej
コード例 #3
0
def selectJ(i, oS, Ei):
    maxK = -1
    maxDeltaE = 0
    Ej = 0
    oS.eCache[i] = [1, Ei]  #eCahe是所有误差的缓存区
    vaildEcacheList = nonzero(oS.eCache[:, 0].A)[0]
    #.A表示转化为array,注意nonzero返回的成对的值,这里validEcache返回的是第一列非零的行索引.见博客:https://blog.csdn.net/qq_28773183/article/details/81013226
    if (len(vaildEcacheList)) > 1:
        for k in vaildEcacheList:
            if k == i: continue
            Ek = calcEk(oS, k)  #计算Ek,有索引k即可
            deltaE = abs(Ei - Ek)
            if (deltaE > maxDeltaE):
                maxK = k
                maxDeltaE = deltaE
                Ej = Ek
        return maxK, Ej
    else:  #随机选择alphaJ
        j = SMO.selectJrand(i, oS.m)
        Ej = calcEk(oS, j)
    return j, Ej