Changeset 13 for trunk/lib/nanownlib/stats.py
- Timestamp:
- 07/19/15 15:05:42 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/nanownlib/stats.py
r11 r13 166 166 #return statistics.mean((l1,l2,l3,m,r3,r2,r1)) 167 167 168 169 def 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 168 179 169 180 def tsvalwmean(subseries): … … 254 265 ubersummaryTest = functools.partial(summaryTest, ubersummary) 255 266 quadsummaryTest = functools.partial(summaryTest, quadsummary) 267 septasummaryTest = functools.partial(summaryTest, septasummary) 256 268 257 269 def rmse(expected, measurements): … … 327 339 else: 328 340 return 0 341 342 343 from pykalman import KalmanFilter 344 def 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.