Changeset 6 for trunk/bin/train


Ignore:
Timestamp:
07/09/15 12:27:04 (9 years ago)
Author:
tim
Message:

.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/train

    r4 r6  
    290290
    291291
    292 def trainMidhinge(db, unusual_case, greater, subsample_size):
     292def trainMidhinge(db, unusual_case, greater, subseries_size):
    293293
    294294    def trainAux(distance, threshold, num_trials):
    295         estimator = functools.partial(midhingeTest, {'distance':distance,'threshold':threshold}, unusual_case, greater)
    296         estimates = bootstrap2(estimator, db, 'train', subsample_size, num_trials)
    297         null_estimates = bootstrap2(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)
    298298
    299299        bad_estimates = len([e for e in estimates if e != 1])
     
    306306    #determine expected delta based on differences
    307307    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)]
    309309    threshold = trimean(mean_diffs)/2.0
    310310    print("initial threshold:", threshold)
     
    313313    print("trimean threshold:", trimean(mean_diffs)/2.0)
    314314   
    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)]
    316316    print(len(mean_diffs))
    317317    print("null mean:", statistics.mean(mean_diffs))
     
    323323   
    324324    start = time.time()
    325     wt = WorkerThreads(1, trainAux)
    326    
    327     num_trials = 200
     325    wt = WorkerThreads(2, trainAux)
     326   
     327    num_trials = 20
    328328    performance = []
    329329    #for distance in range(1,46,4):
     
    335335        fp,fn = errors
    336336        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   
    337342    performance.sort()
    338343    pprint.pprint(performance)
     
    342347
    343348   
    344     num_trials = 200
     349    num_trials = 20
    345350    start = time.time()
    346351    performance = []
     
    359364
    360365   
    361     num_trials = 200
     366    num_trials = 20
    362367    start = time.time()
    363368    performance = []
     
    374379    best_distance = performance[0][1]
    375380    print("best_distance:",best_distance)
    376 
    377     num_trials = 200
     381   
     382    num_trials = 20
    378383    start = time.time()
    379384    performance = []
     
    394399    return {'algorithm':"midhinge",
    395400            'params':params,
    396             'sample_size':subsample_size,
     401            'sample_size':subseries_size,
    397402            'num_trials':num_trials,
    398403            'trial_type':"train",
     
    421426print(":", end-start)
    422427
     428import cProfile
     429
    423430start = time.time()
    424 results = trainMidhinge(db, unusual_case, greater, 6000)
    425 db.addClassifierResults(results)
     431#cProfile.run('results = trainMidhinge(db, unusual_case, greater, 100)')
     432results = trainMidhinge(db, unusual_case, greater, 100)
     433#db.addClassifierResults(results)
    426434print("midhinge result:", results)
    427435end = time.time()
    428436print(":", end-start)
     437
     438sys.exit(0)
    429439
    430440start = time.time()
Note: See TracChangeset for help on using the changeset viewer.