Changeset 6 for trunk/bin/train
- Timestamp:
- 07/09/15 12:27:04 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/train
r4 r6 290 290 291 291 292 def trainMidhinge(db, unusual_case, greater, subs ample_size):292 def trainMidhinge(db, unusual_case, greater, subseries_size): 293 293 294 294 def trainAux(distance, threshold, num_trials): 295 estimator = functools.partial(midhingeTest, {'distance':distance,'threshold':threshold}, unusual_case,greater)296 estimates = bootstrap 2(estimator, db, 'train', subsample_size, num_trials)297 null_estimates = bootstrap 2(estimator, db, 'train_null', subsample_size, num_trials)295 estimator = functools.partial(midhingeTest, {'distance':distance,'threshold':threshold}, greater) 296 estimates = bootstrap3(estimator, db, 'train', unusual_case, subseries_size, num_trials) 297 null_estimates = bootstrap3(estimator, db, 'train_null', unusual_case, subseries_size, num_trials) 298 298 299 299 bad_estimates = len([e for e in estimates if e != 1]) … … 306 306 #determine expected delta based on differences 307 307 start = time.time() 308 mean_diffs = list(samples2MeanDiffs(subsample(db, 'train'), 'packet_rtt', unusual_case))308 mean_diffs = [s['unusual_case']-s['other_cases'] for s in subseries(db, 'train', unusual_case)] 309 309 threshold = trimean(mean_diffs)/2.0 310 310 print("initial threshold:", threshold) … … 313 313 print("trimean threshold:", trimean(mean_diffs)/2.0) 314 314 315 mean_diffs = list(samples2MeanDiffs(subsample(db, 'train_null'), 'packet_rtt', unusual_case))315 mean_diffs = [s['unusual_case']-s['other_cases'] for s in subseries(db, 'train_null', unusual_case)] 316 316 print(len(mean_diffs)) 317 317 print("null mean:", statistics.mean(mean_diffs)) … … 323 323 324 324 start = time.time() 325 wt = WorkerThreads( 1, trainAux)326 327 num_trials = 20 0325 wt = WorkerThreads(2, trainAux) 326 327 num_trials = 20 328 328 performance = [] 329 329 #for distance in range(1,46,4): … … 335 335 fp,fn = errors 336 336 performance.append(((fp+fn)/2.0, job_id, fn, fp)) 337 #for distance in range(25,46,4): 338 # job_id = distance 339 # fp,fn = trainAux(distance, threshold, num_trials) 340 # performance.append(((fp+fn)/2.0, job_id, fn, fp)) 341 337 342 performance.sort() 338 343 pprint.pprint(performance) … … 342 347 343 348 344 num_trials = 20 0349 num_trials = 20 345 350 start = time.time() 346 351 performance = [] … … 359 364 360 365 361 num_trials = 20 0366 num_trials = 20 362 367 start = time.time() 363 368 performance = [] … … 374 379 best_distance = performance[0][1] 375 380 print("best_distance:",best_distance) 376 377 num_trials = 20 0381 382 num_trials = 20 378 383 start = time.time() 379 384 performance = [] … … 394 399 return {'algorithm':"midhinge", 395 400 'params':params, 396 'sample_size':subs ample_size,401 'sample_size':subseries_size, 397 402 'num_trials':num_trials, 398 403 'trial_type':"train", … … 421 426 print(":", end-start) 422 427 428 import cProfile 429 423 430 start = time.time() 424 results = trainMidhinge(db, unusual_case, greater, 6000) 425 db.addClassifierResults(results) 431 #cProfile.run('results = trainMidhinge(db, unusual_case, greater, 100)') 432 results = trainMidhinge(db, unusual_case, greater, 100) 433 #db.addClassifierResults(results) 426 434 print("midhinge result:", results) 427 435 end = time.time() 428 436 print(":", end-start) 437 438 sys.exit(0) 429 439 430 440 start = time.time()
Note: See TracChangeset
for help on using the changeset viewer.