Ignore:
Timestamp:
07/19/15 15:05:42 (9 years ago)
Author:
tim
Message:

.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/nanownlib/stats.py

    r11 r13  
    166166    #return statistics.mean((l1,l2,l3,m,r3,r2,r1))
    167167
     168   
     169def septasummary(values, distance=25):
     170    left2 = 50-distance
     171    left3 = 50-(distance/2.0)
     172    left1 = left2/2.0
     173    right2 = 50+distance
     174    right3 = 50+(distance/2.0)
     175    right1 = (right2+100)/2.0
     176    l1,l2,l3,m,r3,r2,r1 = numpy.percentile(values, (left1,left2,left3,50,right3,right2,right1))
     177    return (l1+l2+l3+m+r3+r2+r1)/7.0
     178
    168179
    169180def tsvalwmean(subseries):
     
    254265ubersummaryTest = functools.partial(summaryTest, ubersummary)
    255266quadsummaryTest = functools.partial(summaryTest, quadsummary)
     267septasummaryTest = functools.partial(summaryTest, septasummary)
    256268
    257269def rmse(expected, measurements):
     
    327339        else:
    328340            return 0
     341
     342
     343from pykalman import KalmanFilter
     344def pyKalman4DTest(params, greater, samples):
     345    kp = params['kparams']
     346    #kp['initial_state_mean']=[quadsummary([s['unusual_packet'] for s in samples]),
     347    #                          quadsummary([s['other_packet'] for s in samples]),
     348    #                          numpy.mean([s['unusual_tsval'] for s in samples]),
     349    #                          numpy.mean([s['other_tsval'] for s in samples])]
     350    kf = KalmanFilter(n_dim_obs=4, n_dim_state=4, **kp)
     351    smooth,covariance = kf.smooth([(s['unusual_packet'],s['other_packet'],s['unusual_tsval'],s['other_tsval'])
     352                                   for s in samples])
     353    m = numpy.mean(smooth)
     354    if greater:
     355        if m > params['threshold']:
     356            return 1
     357        else:
     358            return 0
     359    else:
     360        if m < params['threshold']:
     361            return 1
     362        else:
     363            return 0
     364   
Note: See TracChangeset for help on using the changeset viewer.