예제 #1
0
def computeAndPlotCDFforVibUse(analysis, n, end):
    #computes cdf for number of days people used vibration on the device

    earlyDate='2015-08-31' #assume data from users is good after this date

    #assume users are not lost until cutOff number of days after last use
    cutOff=10
    userCount_old=numpy.zeros((n,1))
    new_userCount=numpy.zeros((cutOff,1))
    for ch in analysis.values():
        if ch.start_date!=None and ch.end_date>earlyDate:
            #print ch.end_date, end
            if dateDiff(ch.start_date, end)>=cutOff:
                #if ch.start_date>'2015-09-01':
                index=len(ch.vibration_use)
                userCount_old[index]+=1
            else:
                index=len(ch.vibration_use)
                if index>cutOff:
                    print "problem with vibration use logic", ch.start_date
                new_userCount[index]+=1
        elif len(ch.vibration_use)>0:
            print 'issue with data, id=', ch.child_id
        else:
            index=len(ch.vibration_use)
            userCount_old[index]+=1
    print  'number of old users using vibration', sum(userCount_old)
    cdf_old=numpy.zeros((n,1))
    cdf_new=numpy.zeros((cutOff,1))
    for i in range(1,n):
        cdf_old[i]=sum(userCount_old[:i])
    for i in range(1, cutOff):
        cdf_new[i]=sum(new_userCount[:i])
    diff_old=numpy.zeros((n,1))
    for i in range(1,n):
        diff_old[i]=cdf_old[i]-cdf_old[i-1]
    diff_new=numpy.zeros((cutOff,1))
    for i in range(1, cutOff):
        diff_new[i]=cdf_new[i]-cdf_new[i-1]
    print 'new users', userCount_old[-1], 'old diff', numpy.transpose(diff_old[:50])
    print 'new diff', numpy.transpose(diff_new)
    plt.figure()
    plt.bar(range(n), cdf_old/sum(userCount_old), align='center')
    plt.title('cdf: number of people who stopped using the device')
    plt.xlabel('days')
    plt.ylabel('% of all users')
    plt.figure()

    plt.plot(diff_old, 'g*--')
    plt.title('number of people lost for >'+str(cutOff))
    plt.ylabel('number of people')
    plt.xlabel('days')
    plt.show()
예제 #2
0
def plotDevRateVsImprov(analysis):
    #plots dev rate vs biggest improvement in dist event rate
    improvement=[]
    reactgood_rate=[]
    for ch in analysis.values():
        if len(ch.biggest_improvement)>0:
            improvement.append(ch.biggest_improvement[0])
            reactgood_rate.append(ch.devRate['ReactGood'])
    plt.figure()
    plt.plot(reactgood_rate, improvement, 'gs')
    plt.title('sussessful device use rate vs improvement')
    plt.ylabel('improvement in distuption events')
    plt.xlabel('rate of correct reaction')
    plt.show()
예제 #3
0
def plotUseRateVsBestRate(analysis):
    #shows plot of use rate vs best dist event rate from biggest improvement
    use_rate=[]
    best_rate=[]
    for ch in analysis.values():
        if len(ch.use)>20:
            if len(ch.biggest_improvement):
                use_rate.append(ch.use_rate)
                best_rate.append(ch.biggest_improvement[2])
    plt.figure()
    plt.title('best rate vs use freq in 4 weeks prior to best rate')
    plt.xlabel('best rate')
    plt.ylabel('use freq in 4 weeks')
    plt.plot(best_rate, use_rate, 'bo')
    plt.show()
예제 #4
0
def plotCorrVsOffset(analysis):
    #plots correlation between dist event to reactgood and offset for start of company's device
    correlation=[]
    std_offset=[]
    mean_offset=[]
    for ch in analysis.values():
        if len(ch.use)>0:
            reactgood= ch.corr_dev_reactgood
            std_off=ch.std_offset_for_device_start
            mean=ch.avg_offset_for_device_start
            if reactgood!=None and not numpy.isnan(std_off):
                correlation.append(reactgood)
                std_offset.append(std_off)
                mean_offset.append(mean)
    plt.figure()
    plt.plot(correlation, std_offset, 'b*')
    plt.figure()
    plt.plot(correlation, mean_offset, 'r*')
    plt.figure()
    plt.plot(mean_offset, std_offset, 'g*')
    plt.show()         
예제 #5
0
def plotUseRateVsImprovRate(analysis):
    #shows plot of use rate vs biggest improvement diff rate for distuption events
    use_rate=[]
    improv_diff=[]
    best_rate=[]
    for ch in analysis.values():
        if len(ch.use)>20:
            if len(ch.biggest_improvement):
                use_rate.append(ch.use_rate)
                improv_diff.append(ch.biggest_improvement[0])
                best_rate.append(ch.biggest_improvement[2])


    imdiffLp6=[]
    imdiffBp6=[]
    brateLp6=[]
    brateBp6=[]
    for i in range(len( use_rate)):
        if use_rate[i]<.6:
            imdiffLp6.append(improv_diff[i])
            brateLp6.append(best_rate[i])
        else:
            imdiffBp6.append(improv_diff[i])
            brateBp6.append(best_rate[i])

    print '******Report 2******'
    print 'for users with use rate <.6, improvement stats: mean', numpy.mean(imdiffLp6), 'std', numpy.std(imdiffLp6)
    print 'for users with use rate <.6, best rate stats: mean', numpy.mean(brateLp6), 'std', numpy.std(brateLp6)
    print 'for users with use rate >=.6, improvement stats: mean', numpy.mean(imdiffBp6), 'std', numpy.std(imdiffBp6)
    print 'for users with use rate >=.6, best rate stats: mean', numpy.mean(brateBp6), 'std', numpy.std(brateBp6)

    plt.figure()
    plt.title('improvement difference vs use freq in 4 weeks prior to best rate')
    plt.xlabel('improvement difference')
    plt.ylabel('use freq in 4 weeks')
    plt.plot(improv_diff, use_rate, 'bo')
    plt.show()
예제 #6
0
def computeAndPlotCDF(analysis, n, end):
    #computes cdf for number of days people used the app
    userCount=numpy.zeros((n,1))
    for ch in analysis.values():
        index=len(ch.use)
        userCount[index]+=1
    cdf=numpy.zeros((n,1))
    for i in range(1,n):
        cdf[i]=sum(userCount[:i])
    diff=numpy.zeros((n,1))
    for i in range(1,n):
        diff[i]=cdf[i]-cdf[i-1]
    print 'all users',  numpy.transpose(diff[:50])
    print 'max', max(cdf), sum(userCount)
    plt.figure()
    plt.bar(range(n), cdf*1.0/sum(userCount), align='center')
    plt.title('cdf: number of people who stopped using the app')
    plt.xlabel('days')
    plt.ylabel('% of all users')
    plt.figure()

    plt.plot(diff, 'g*--')
    plt.title('number of people lost')
    plt.ylabel('number of people')
    plt.xlabel('days')
    #assume users are not lost until "cutOff" days after last use
    cutOff=10
    userCount_old=numpy.zeros((n,1))
    new_userCount=numpy.zeros((cutOff,1))
    for ch in analysis.values():
        if ch.start_date!=None:
            #print ch.end_date, end
            if dateDiff(ch.start_date, end)>=cutOff:
                if ch.start_date>'2015-08-31':
                    index=len(ch.use)
                    userCount_old[index]+=1
            else:
                userCount_old[-1]+=1
                index=len(ch.use)
                if index>10:
                    print ch.start_date
                new_userCount[index]+=1
        elif len(ch.use)>0:
            print 'issue with data, id=', ch.child_id
        else:
            index=len(ch.use)
            userCount_old[index]+=1
    print 'number of all users', len(analysis), 'number of old users', sum(userCount_old), sum(userCount)
    cdf_old=numpy.zeros((n,1))
    cdf_new=numpy.zeros((cutOff,1))
    for i in range(1,n):
        cdf_old[i]=sum(userCount_old[:i])
    for i in range(1, cutOff):
        cdf_new[i]=sum(new_userCount[:i])
    diff_old=numpy.zeros((n,1))
    for i in range(1,n):
        diff_old[i]=cdf_old[i]-cdf_old[i-1]
    diff_new=numpy.zeros((cutOff,1))
    for i in range(1, cutOff):
        diff_new[i]=cdf_new[i]-cdf_new[i-1]
    print 'new users', userCount_old[-1], 'old diff', numpy.transpose(diff_old[:50])
    print 'new diff', numpy.transpose(diff_new)
    plt.figure()
    plt.bar(range(n), cdf_old/sum(userCount_old), align='center')
    plt.title('cdf: number of people who stopped using device for >'+str(cutOff))
    plt.xlabel('days')
    plt.ylabel('number of people')

    plt.figure()
    #plt.plot(range(n), 1-cdf*1.0/sum(userCount_old),'b-', ls='steps',linewidth=4.0)
    plt.plot(range(n), 1-cdf_old/sum(userCount_old),'b-',ls='steps', linewidth=4.0)
    plt.title('Remaining Users')
    plt.xlabel('days')
    plt.xlim((0,50))
    plt.ylabel('fraction of all users')
    #matplotlib.rcParams.update({'font.size': 22})

    plt.figure()
    plt.plot(diff_old, 'g*--')
    plt.title('number of people lost for >'+str(cutOff))
    plt.ylabel('number of people')
    plt.xlabel('days')
    plt.show()
예제 #7
0
import analysis

# A list of irreducible polynomials and constants
# http://www.sciencedirect.com/science/article/pii/S2212017313006051
irreducibles = [
    0x11B, 0x11D, 0x12B, 0x12D, 0x139, 0x13F, 0x14D, 0x15F, 0x163, 0x165,
    0x169, 0x171, 0x177, 0x17B, 0x187, 0x18B, 0x18D, 0x19F, 0x1A3, 0x1A9,
    0x1B1, 0x1BD, 0x1C3, 0x1CF, 0x1D7, 0x1DD, 0x1E7, 0x1F3, 0x1F5, 0x1F9
]

constants = [
    0x0A, 0x0F, 0x15, 0x2A, 0x2B, 0x31, 0x32, 0x35, 0x38, 0x40, 0x4A, 0x4E,
    0x54, 0x5E, 0x62, 0x6E, 0x74, 0x7E, 0xF5, 0xF0, 0xEA, 0xD5, 0xD4, 0xCE,
    0xCD, 0xCA, 0xC7, 0xBF, 0xB5, 0xB1, 0xAB, 0xA1, 0x9D, 0x91, 0x2B, 0x81
]

for p in irreducibles:
    reduced = core._B2I(core._I2B(p)[1:])

    for c in constants:

        sbox = []

        for elem in range(256):
            sbox.append(
                core.affine(core.inverse(elem, reduced), u=0x1F, v=0x63))

        val = analysis.values(sbox)
        out = "Polynomial: %02x, Constant: %02x, NL: %d, DP: %d"
        print(out % (p, c, val[0], val[1]))