Exemple #1
0
def init_files(trace_type = ' ', task_type='CLASSIFICATION', topo_type='b4', 
                x_var = 'FLOWNUM', p=0.01
    ):
    file_name1, file_name2 = cf.init_files(trace_type=trace_type, 
                task_type=task_type, topo_type=topo_type, 
                x_var=x_var, p=p)
            
    return file_name1, file_name2    
Exemple #2
0
def init_files(trace_type=' ',
               task_type='CLASSIFICATION',
               topo_type='b4',
               x_var='FLOWNUM',
               p=0.01):
    file_name1, file_name2 = cf.init_files(trace_type=trace_type,
                                           task_type=task_type,
                                           topo_type=topo_type,
                                           x_var=x_var,
                                           p=p)

    f1 = open(file_name1, 'w')
    if task_type == 'APPLICATION':
        f1.write((
            "#flows,iteration,r_threshold,imr_threshold,p_t,topk,is_correlated,#case_detect,len(class_dict)\n"
        ))
    else:
        if task_type == 'CLASSIFICATION':
            f1.write((
                "#flows,iteration,epsilon,r_threshold,is_correlated,#correlated_detect,#non-uniform_detect,#all_cases\n"
            ))
        elif task_type == 'RANKING':
            f1.write((
                "#flows,iteration,epsilon,r_threshold,is_correlated,#correlated_detect\n"
            ))
        else:
            f1.write((
                "#flows,iteration,r_threshold,imr_threshold,is_correlated,#correlated_detect,#non-uniform_detect,#all_cases\n"
            ))

    f2 = open(file_name2, 'w')
    if task_type == 'CLASSIFICATION':
        f2.write('#flows,iteration,time,epsilon,r_threshold,' +
                 'is_correlated,' + 'key,count_chern,byte_chern,pred,true\n')
    elif task_type == 'RANKING':
        f2.write('#flows,iteration,time,epsilon,r_threshold,' +
                 'is_correlated,' + 'key,#pres,o_f,count_chern[0]\n')

    elif task_type == 'APPLICATION':
        f2.write('#flows,iteration,time,r_threshold,imr_threshold,p_t,topk,' +
                 'is_correlated,' + 'drop_id,key,pred,true,imr0,imr1,imr2\n')
    print(file_name1, '\n', file_name2)
    f1.close()
    f2.close()
def init_files(trace_type=' ',
               task_type='CLASSIFICATION',
               topo_type='b4',
               x_var='FLOWNUM',
               p=0.01):
    """file_name1 = ('../outputs/zout_'
            +topo_type.lower()+'_'+ task_type.lower() + '_' 
            + x_var.lower() + '_trace'+trace_type+'.csv')
    file_name2 = ('../outputs/zout_'
            +topo_type.lower()+'_'+ task_type.lower() + '_' 
            + x_var.lower() + '_chern_trace'+trace_type+'.csv')"""

    file_name1, file_name2 = cf.init_files(trace_type=trace_type,
                                           task_type=task_type,
                                           topo_type=topo_type,
                                           x_var=x_var,
                                           p=p)

    return file_name1, file_name2
Exemple #4
0
                    black_hole=black_hole,
                    links=links,
                    metric_type=x_var,
                    exc_time=exc_time,
                    app_exc_time=app_exc_time,
                    flow_paths=flow_paths)

    print('trues, ests, select_len, est_pairs, exc_time, app_exc_time',
          len(trues), len(ests), min_len, est_pairs, exc_time, app_exc_time)
    classification_alg(true_byte_dict, epsilon=0.005, epsilon_pb=epsilon)

    # Write to fsile
    select_len = min_len
    file_name1, file_name2 = cf.init_files(trace_type=trace_type,
                                           task_type=task_type,
                                           topo_type=topo_type,
                                           x_var=x_var,
                                           p=0.01)

    f1 = open(file_name1, 'a')
    f2 = open(file_name2, 'a')
    if task_type == "CLASSIFICATION":
        for key in true_byte_dict:
            true_class = is_correlated
            if drop_id <= 0:
                true_class = -1
                is_correlated = -1
            f2.write(
                str(select_len) + ',' + str(exc_time) + ',' + str(epsilon) +
                ',' + str(r_threshold) + ',' + str(int(is_correlated)) + ',' +
                key + ',' + str(true_byte_dict[key][0]) + ',' +
Exemple #5
0
def app_classification(app_flows1,
                       app_flows2,
                       app_flows3,
                       x_var='',
                       key='',
                       iteration=0,
                       is_correlated=0,
                       imr_threshold=0.1,
                       select_len=1,
                       app_exc_time=0,
                       r_threshold=0.1,
                       x_type=1,
                       p_t=0.01,
                       topk=1):

    app1 = sorted(
        Counter([randint(0, 8) for p in range(0, app_flows1)]).values())
    app2 = sorted(
        Counter([randint(0, 8) for p in range(0, app_flows2)]).values())
    app3 = sorted(
        Counter([randint(0, 8) for p in range(0, app_flows3)]).values())
    #print 'r_threshold', r_threshold
    drop_id = 3

    if is_correlated == 0 and x_type == 2:
        drop_link_id = randint(0, 8)
        app_x = app3
        app_x[drop_link_id] = int(app_x[drop_link_id] * (1 - r_threshold))
        app_x = sorted(app_x)
        app3 = app_x
    elif is_correlated == 1 and x_type == 1:
        for i in range(4):
            app1[i], app2[i], app3[i] = 0.1, 0.1, 0.1

    topk = topk
    app_top1 = app1[0:topk] + app1[-topk:]
    app_top2 = app2[0:topk] + app2[-topk:]
    app_top3 = app3[0:topk] + app3[-topk:]

    app_link_table = []
    app_link_table.append(app_top1)
    app_link_table.append(app_top2)
    app_link_table.append(app_top3)

    app_link_table = np.transpose(np.array(app_link_table))
    top_apps = [1, 2, 3]
    app_df = pd.DataFrame(app_link_table,
                          columns=['a' + str(x) for x in top_apps])

    app_imrs = iset.independentCluster(app_df, p_t)

    class_dict = {}
    appl.appClassification(len(app_imrs),
                           app_imrs[0][2],
                           key=key,
                           imr_threshold=0.1,
                           class_dict=class_dict)

    imrs = [x[2] for x in app_imrs]

    file_name1, file_name2 = cf.init_files(trace_type='ABC',
                                           task_type='APPLICATION',
                                           topo_type='JUPITER',
                                           x_var=x_var,
                                           p=0.01)

    f1 = open(file_name1, 'a')
    f2 = open(file_name2, 'a')

    if task_type == "APPLICATION":
        # Ranking result
        true_num = 0
        for key in class_dict:
            true_class = 0
            true_class = x_type
            f2.write(
                str(select_len) + ',' + str(iteration) + ',' +
                str(app_exc_time) + ',' + str(r_threshold) + ',' +
                str(imr_threshold) + ',' + str(p_t) + ',' + str(topk) + ',' +
                str(int(is_correlated)) + ',' + str(int(drop_id)) + ',' + key +
                ',' + str(class_dict[key]) + ',' + str(true_class) + ',' +
                ','.join([str(x) for x in imrs]) + '\n')

            if true_class == class_dict[key]:
                true_num += 1

        f1.write(','.join([
            str(x) for x in [
                select_len, iteration, r_threshold, imr_threshold, p_t, topk,
                int(is_correlated), true_num,
                len(class_dict)
            ]
        ]) + '\n')