def test_extract_trial_features_real():
    csvs = [
            "./data/fh_pca_space_merge_Insula_rt_fast.csv",
            "./data/fh_pca_space_merge_Insula_rt_slow.csv"
            ]

    # load_dimreduce_data_fromcl(csvs, feature_cols, label_col, cv_col, trial_tr_col)
    feature_col = range(0,3)
    label_col = 5
    cv_col = 6
    trial_tr_col = 7
    Xs, ys, indices, cvcodes = load_dimreduce_data_fromcl(
            csvs, feature_col, label_col, cv_col, trial_tr_col
            )
    
    X = np.concatenate(Xs)
    y = create_y(np.concatenate(ys)) 
    trials = np.concatenate(indices)
    windowstr = '0:10'
    window =  range(*[int(i) for i in windowstr.split(':')])

    Xfea, indexfea, otherfea = extract_trial_features(
            X, trials, window, [trials], None
            )
    yea = otherfea[0]
    
    # Xmax, Xmin, Xdiff, Xmean, Xslope
    print("Xmax\n{0}".format(Xfea[:,0:3]))
    print("Xmin\n{0}".format(Xfea[:,3:6]))
    print("Xdiff\n{0}".format(Xfea[:,6:9]))
    print("Xmean\n{0}".format(Xfea[:,9:12]))
    print("Xslope\n{0}".format(Xfea[:,12:15]))
def test_load_dimreduce_data_fromcl():
    csvs = [
            "/data/data2/meta_accumulate//fh/mvpa/fh_pca_space_merge_Insula_rt_fast.csv",
            "/data/data2/meta_accumulate//fh/mvpa/fh_pca_space_merge_Insula_rt_slow.csv"
            ]

    # load_dimreduce_data_fromcl(csvs, feature_cols, label_col, cv_col, trial_tr_col)
    feature_col = range(0,3)
    label_col = 5
    cv_col = 6
    trial_tr_col = 7
    Xs, ys, indices, cvcodes = load_dimreduce_data_fromcl(
            csvs, feature_col, label_col, cv_col, trial_tr_col
            )
    assert len(Xs) == 2, "Xs wrong len"
    assert len(ys) == 2, "ys wrong len"
    assert len(indices) == 2, "indices wrong len"
    assert len(cvcodes) == 2, "cvcodes wrong len"
    assert Xs[0].shape == (210, 3), "X0 wrong shape"
    assert Xs[1].shape == (210, 3), "X1 wrong shape"
    assert Xs[0].shape[0] == ys[0].shape[0], "X0 y0 mistmatch"
    assert Xs[1].shape[0] == ys[1].shape[0], "X0 y0 mistmatch"
    assert ys[0].shape == indices[0].shape, "y0 i0 mistmatch"
    assert ys[1].shape == indices[1].shape, "y1 i1 mistmatch"
    assert ys[0].shape == cvcodes[0].shape, "y0 cv0 mistmatch"
    assert ys[1].shape == cvcodes[1].shape, "y1 cv1 mistmatch"

    print("X0, the first few rows\n{0}".format(Xs[0][:5,:]))
    print("y0, the first few elements {0}".format(ys[0][:5]))
    print("index0, the first few elements {0}".format(indices[0][:5]))
    print("cv0, the first few elements {0}".format(cvcodes[0][:5]))
Example #3
0
def _data(csvs, feature_index, window, label_col, trial_tr_col):
    """Data loading and feature selection helper."""
    Xs, ys, indices, cvcodes = load_dimreduce_data_fromcl(
            csvs, feature_index, label_col, 
            label_col, trial_tr_col
            )

    X = np.concatenate(Xs)
    y = create_y(np.concatenate(ys)) 
    index = np.concatenate(indices)
    cvcode = np.concatenate(cvcodes)

    X, index, othermeta = extract_trial_features(X, index,  
            window, [y, cvcode], None
            )
    y, _ = othermeta  ## toss cvcode, not applicable
        
    return X, y
Example #4
0
parser.add_argument(
        "--clf", default="RandomForestClassifier", type=str,
        help="Select a classfier"
        )
args = parser.parse_args()
prng = np.random.RandomState(42)


# ----
# Load and preprocess data
feature_index = range(*[int(i) for i in args.data.split(':')])

csvs = args.t
# load_dimreduce_data_fromcl(csvs, feature_cols, label_col, cv_col, trial_tr_col)
Xs, ys, indices, cvcodes = load_dimreduce_data_fromcl(
        csvs, feature_index, args.labels, 
        args.cv, args.trial_tr
        )
X = np.concatenate(Xs)
y = create_y(np.concatenate(ys)) 
index = np.concatenate(indices)
cvcode = np.concatenate(cvcodes)

window =  range(*[int(i) for i in args.window.split(':')])
X, index, othermeta = extract_trial_features(
        X, index,  window, [y, cvcode], None
        )
y, cvcode = othermeta

assert X.shape[0] == y.shape[0], "X and y length mismatch"

# ----