示例#1
0
def costFunction1(varsNum, Truthtable, dicIndexList):
    walshSqureList = []
    walshResList = walshCompute(varsNum, Truthtable)
    # print(walshResList)

    for ele in walshResList:
        walshSqureList.append(ele**2)
    # print(walshSqureList)
    oneTermResTmpList = []
    for ele in walshSqureList:
        oneTermResTmpList.append(pow((ele - pow(2, varsNum)), 3))
    # print(oneTermResTmpList)

    oneTermRes = 0
    for ele in oneTermResTmpList:
        oneTermRes = ele + oneTermRes
    # print(oneTermRes)  # 28731506688
    twoTermRes = autocorrelationSelect(varsNum, Truthtable, dicIndexList)
    # print(twoTermRes)

    costOneRes = oneTermRes - twoTermRes
    return costOneRes
def xiao_messay(varsNum, TruthTable, allTruthTable):
    oneNumStatic = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0}
    for ele in allTruthTable:
        num = ele.count(1)
        oneNumStatic[num] = oneNumStatic[num] + 1

    walshVec = walshCompute(varsNum, TruthTable)
    zeroVec = []
    for i in range(len(walshVec)):
        if walshVec[i] == 0:
            zeroVec.append(i)
    truthTableVec = []
    for ele in zeroVec:
        truthTableVec.append(allTruthTable[ele].count(1))
    # print(oneNumStatic)
    # print(truthTableVec)
    oneNumStatic.pop(0)
    autoDeg = 0
    for k, v in oneNumStatic.items():
        if truthTableVec.count(k) == v:
            autoDeg = k
        else:
            break
    return autoDeg