Example #1
0

if __name__ == '__main__':
    print("Reading file ...")

    X_df, y_df = read_data(filename)

    #no training, use all sample for test:
    skf = ShuffleSplit(len(y_df), n_iter=1, test_size=0.99, random_state=57)
    print("Training file ...")
    for train_is, test_is in skf:
        print '--------------------------'

        # use dummy clustering
        #tracker = Tracking.HitToTrackAssignment()
        tracker = Clustering.ClusterDBSCAN(eps=0.5, rscale=0.001)

        X_train_df = X_df.iloc[train_is].copy()
        y_train_df = y_df.iloc[train_is].copy()
        X_test_df = X_df.iloc[test_is].copy()
        y_test_df = y_df.iloc[test_is].copy()

        # Temporarily bypass splitting (need to avoid shuffling events)
        X_test_df = X_df.copy()
        y_test_df = y_df.copy()

        tracker.fit(X_train_df.values, y_train_df.values)
        y_predicted = tracker.predict(X_test_df.values)

        # Score the result
        total_score = 0.
Example #2
0
        'pt': [0.],
        'phi': [0.],
        'xVtx': [0.],
        'yVtx': [0.]
    })
    data_track = data_track.drop(data_track.index[[0]])

    df = pd.read_csv("hits_" + str(N) + ".csv")
    y_df = df[['particle']]
    #    X_df = df.drop(['hit','layer','particle','event'], axis=1)
    X_df = df.drop(['particle', 'layer', 'iphi'], axis=1)

    #replace particle with 100000000*event+particle

    y_train = df['particle'].values + df['event'].values * 1000
    tracker = trk.ClusterDBSCAN(eps=0.004, rscale=0.001)

    tracker.fit(X_df.values[:1000], y_train[:1000])

    df_result = df.drop(['particle'], axis=1)
    y_predicted = tracker.predict(df_result.values)

    df_result = pd.concat(
        [df_result, pd.DataFrame({'track': y_predicted})], axis=1)
    for col in ['event', 'track']:
        df_result[col] = df_result[col].astype('int32')
    df_result_truth = pd.concat(
        [df_result, pd.DataFrame({'particle': y_train})], axis=1)
    df_result_truth['particle'] = df_result_truth['particle'].astype('int32')

    df_result.to_csv("result_" + str(N) + ".csv",