def WalshCofLinearLinklist(self): """ compute the Walsh Coefficients in a liner time with linear space """ subW = [] # subW is a N * 2^K matrix for i in range(self.n): """ Compute coefficients for each sub-functions """ subWone = wal.computeW(self.Kbits, self.func[i]) subW.append(subWone) """ use dict to represent all non-zero Walsh Coefficients""" w = dict() for i in range(self.n): # i: index of sub-function if len(self.neighs)!=0: interBits = self.neighs[i][:] else: interBits = [] interBits.append(i) interBits.sort() for j in range(int(math.pow(2, self.k+1))): # j: index of substrings indexW = self.composeFullBitStr(i, j, interBits, self.n) if w.has_key(indexW): w[indexW] = w[indexW] + subW[i][j] else: w[indexW] = subW[i][j] for k in w.keys(): w[k] = w[k]/float(self.n) self.w = w return w
def WalCof(self): """ compute the Walsh coefficients """ subW = [] # subW is a N*2^K matrix for i in range(self.n): """ 1. Compute coefficients for each sub-functions """ subWone = wal.computeW(self.Kbits, self.func[i]) subW.append(subWone) w = np.zeros(math.pow(2,self.n)) for i in range(int(math.pow(2,self.n))): # for every candidate solution iStr = bin(i) iStr = iStr[2:] if len(iStr) < self.n: iStr = (self.n - len(iStr))*'0' + iStr for j in range(self.n): # for every sub-function maskJ = self.neighs[j][:] maskJ.append(j) maskJ.sort() # pack iStr to a (k+1) length one maskStr = [iStr[k] for k in maskJ] maskStr = ''.join(maskStr) occurOneBit = self.indexOneBit(iStr) if self.checkInclude(occurOneBit, maskJ) == True : extractBit = maskStr w[i] = w[i] + subW[j][int(extractBit, 2)] return w
def WalCofLinear(self): """ compute the Walsh coefficients in a linear time """ subW = [] # subW is a N*2^K matrix for i in range(self.n): """ Compute coefficients for each sub-functions """ subWone = wal.computeW(self.Kbits, self.func[i]) subW.append(subWone) print 'len', math.pow(2,self.n) w = np.zeros(math.pow(2,self.n)) for i in range(self.n): # i: index of subfunction interBits = self.neighs[i][:] interBits.append(i) interBits.sort() for j in range(int(math.pow(2, self.k+1))): # j: index of substrings indexW = self.composeFullStr(i, j, interBits, self.n) w[indexW] = w[indexW] + subW[i][j] return w/float(self.n)