def add_staircase_noisy(epsilon, sensitivity, top):
    re = staircase.randomise(epsilon, sensitivity)
    T = 100
    while T > 0 and re > top:
        T -= 1
        re = staircase.randomise(epsilon, sensitivity)
    if T == 0:
        re = 0
    return re
def get_real_trails(myTrie, segNum, choiceNum, centers, labels, epsilon, alpha,
                    beta):
    newTrails = []
    newCnt = 0
    newSum = 0
    for i in range(choiceNum):
        newTrail = []
        newCenterTrail = []
        for j in range(segNum):
            la = labels[i][j]
            ce = centers[la][j]
            newTrail.append(la)
            newCenterTrail.append(ce)
        rea = myTrie.query(newTrail)
        if rea > 0:
            newSum += rea
            newCnt += 1
            myTrie.update(newTrail, -rea - 1)
            real_noisy = rea + staircase.randomise(epsilon, 1)
            if real_noisy < alpha * rea:
                real_noisy = alpha * rea
            elif real_noisy > beta * rea:
                real_noisy = beta * rea
            newTrails.append(
                Trail(newCenterTrail, newTrail, rea, int(real_noisy)))
    newTrails.sort()
    return newTrails, newCnt, newSum
Esempio n. 3
0
def get_real_trails(myTrie, segNum, choiceNum, centers, labels, epsilon, alpha,
                    beta):
    newTrails = []
    newCnt = 0
    newSum = 0
    for i in range(choiceNum):
        newTrail = []
        newCenterTrail = []
        for j in range(segNum):
            la = labels[i][j]
            ce = centers[la][j]
            newTrail.append(la)
            newCenterTrail.append(ce)
        rea = myTrie.query(newTrail)
        if rea > 0:
            '''
            for j in range(segNum):
                if math.isnan(newCenterTrail[j][0]) or math.isnan(newCenterTrail[j][1]):
                    la = labels[i][j]
                    ce = centers[la][j]
                    print('nan','label=',la,'center=',ce)
            '''
            newSum += rea
            newCnt += 1
            myTrie.update(newTrail, -rea - 1)
            real_noisy = rea + staircase.randomise(epsilon, 1)
            if real_noisy < alpha * rea:
                real_noisy = alpha * rea
            elif real_noisy > beta * rea:
                real_noisy = beta * rea
            newTrails.append(
                Trail(newCenterTrail, newTrail, rea, int(real_noisy)))
    '''
    for i in newTrails:
        for j in i.trail:
            if math.isnan(j[0]) or math.isnan(j[1]) :
                print(j,'nan')
    '''

    newTrails.sort()
    return newTrails, newCnt, newSum