Esempio n. 1
0
def workload_characterization():
    '''path = r'/Users/rachananarayanacharya/MLbasedDBMStuning/Data/'  # use your path
    all_files = glob.glob(path + "/*.csv")
    li = []
    for filename in all_files:
        df = pd.read_csv(filename, index_col=None, header=0)
        li.append(df)

    df = pd.concat(li, axis=0, ignore_index=True)
    train_df, test_df = train_test_split(df, test_size=0.2)'''

    #train_df=pd.read_pickle("../../Data/WorkloadFiles/workload_11.pkl",compression=None)
    train_df3=pd.read_csv("../../Data/CSVFiles/Online_workloadB_preprocessed.csv")
    #train_df1=pd.read_csv("../../Data/CSVFiles/Online_workloadC_preprocessed.csv")
    train_df2=pd.read_csv("../../Data/CSVFiles/Offline_workload_preprocessed.csv")
    frames = [train_df2, train_df3]

    train_df = pd.concat(frames)

    train_df=train_df.fillna(0)
    model = FA()

    X=train_df.to_numpy()
    print("Shape of the data:",X.shape)
    n_rows, n_cols = X.shape
    model=model._fit(X, 50, 10000)

    components = model.components_.T.copy()
    print("After Components: ",components.shape)
    c_algo="kmeans" # kmeans or em
    clustering_model, det=select_clustering_model(c_algo)
    clustering_model.fit(components, min_cluster=1,
                      max_cluster=min(n_cols - 1, 20),
                      estimator_params={'n_init': 50})
    
    det.fit(components, clustering_model.cluster_map_)
    print("Optimal no of clusters:",det.optimal_num_clusters_)
    #print(clustering_model.cluster_map_)
    pruned_metrics = clustering_model.cluster_map_[det.optimal_num_clusters_].get_closest_samples()
    print("pruned metrics:",pruned_metrics)
    idx_set = columnsToPrune(pruned_metrics)
    cols_rem = []
    for i in range(14,373):
        if i not in idx_set:
            cols_rem.append(i)
    print(len(idx_set))
    print_pruned_metrics(idx_set, train_df, c_algo)
    loadWorkLoadRemCols(cols_rem)
    writeCSV("pruned_metric.csv",pruned_metrics)
Esempio n. 2
0
 def make_nfa(self):
     """make NFA from the state graph"""
     nfa = FA()
     for current in self.all_states(self.start):
         for edge in current.move:
             for next_node in current.move[edge]:
                 nfa.connect(current.name, next_node.name, edge)
     nfa.set_start(self.start.name)
     nfa.add_final(self.final.name)
     return nfa
Esempio n. 3
0
 def output_plain(this):
     FA.output_plain(this, "NFA", "Thompson NFA")
Esempio n. 4
0
 def output_dot(this):
     FA.output_dot(this, "NFA")
Esempio n. 5
0
def to_fa(otatable, n):
    """Given an ota table, build a finite automaton.
    """
    ### First, need to transform the resettimedwords of the elements in S_U_R
    ### to clock valuation timedwords with reset informations.
    #S_U_R = [s for s in otatable.S] + [r for r in otatable.R]
    #table_elements = [Element(dRTWs_to_lRTWs(e.tws), e.value) for e in S_U_R]
    table_elements = [s for s in otatable.S] + [r for r in otatable.R]
    ### build a finite automaton
    ## FAStates
    rtw_alphabet = []
    states = []
    initstate_name = ""
    accept_names = []
    value_name_dict = {}
    sink_name = ""
    for s, i in zip(otatable.S, range(1, len(otatable.S) + 1)):
        name = str(i)
        value_name_dict[s.whichstate()] = name
        init = False
        accept = False
        if s.tws == []:
            init = True
            initstate_name = name
        if s.value[0] == 1:
            accept = True
            accept_names.append(name)
        if s.value[0] == -1:
            sink_name = name
        temp_state = FAState(name, init, accept)
        states.append(temp_state)
    ## FATrans
    trans_number = 0
    trans = []
    for r in table_elements:
        if r.tws == []:
            continue
        resettimedwords = [tw for tw in r.tws]
        w = resettimedwords[:-1]
        a = resettimedwords[len(resettimedwords) - 1]
        if a not in rtw_alphabet:
            rtw_alphabet.append(a)
        source = ""
        target = ""
        #label = [a]
        for element in table_elements:
            if w == element.tws:
                source = value_name_dict[element.whichstate()]
            if resettimedwords == element.tws:
                target = value_name_dict[element.whichstate()]
        need_newtran = True
        for tran in trans:
            if source == tran.source and target == tran.target:
                if a.action == tran.label[0].action and a.reset == tran.label[
                        0].reset:
                    need_newtran = False
                    if a not in tran.label:
                        tran.label.append(a)
                    break
        if need_newtran == True:
            temp_tran = FATran(trans_number, source, target, [a])
            trans.append(temp_tran)
            trans_number = trans_number + 1
    fa = FA("FA_" + str(n), rtw_alphabet, states, trans, initstate_name,
            accept_names)
    return fa, sink_name