示例#1
0
        net_features_dir = os.path.join(features_dir, 'net%d' % i)
        dump_features(net_features, net_features_dir)

        features.append(net_features)

predictions = []
for i, net_features in enumerate(features):
    print 'Using features from network %d...' % i
    if stim_type == 'grating':
        tr_features, te_features = train_test_split_grating(net_features,
                                                            grating_train_idxs)
    else:
        tr_features, te_features = train_test_split(net_features)

    print 'Creating classifier...'
    classifier = DTWClassifier(10)
    classifier.fit(tr_features)

    print 'Prediction from simulated responses...'
    pred = classifier.predict(te_features)
    cm = confusion_matrix(pred)
    # cm = confusion_matrix_grating(pred, grating_train_idxs)
    print cm, cm_goodness(cm, stim_type)
    
    predictions.append(pred)
    pred_outpath = os.path.join(predictions_dir, 'pred_%d.pickle' % i)
    if not os.path.isdir(predictions_dir):
        os.makedirs(predictions_dir)
    with open(pred_outpath, 'w') as pred_out:
        pickle.dump((pred, cm), pred_out)
for i, response in enumerate(responses):
    name = response.name
    print 'Mouse %s' % name

    print 'Splitting out training and test data...'
    tr_rsp, te_rsp, tr_mov, te_mov = train_test_splits[i]
    # tr_rsp, te_rsp = train_test_splits[i]
    
    print 'Fitting template-matching model...'
    model = AverageTemplate()
    model.fit(tr_rsp)
    print 'Decoding movie indices from test responses...'
    pred_movies = model.predict(te_rsp)
    cm = confusion_matrix(pred_movies)
    # cm = confusion_matrix_grating(pred_movies)
    print cm, cm_goodness(cm, exp_type)
    """
    print 'Fitting DTW model...'
    model = DTWClassifier(3)
    tr_data = [[tr_rsp.data[s,:,:,tr].T for tr in range(tr_rsp.data.shape[3])]
               for s in range(tr_rsp.data.shape[0])]
    model.fit(tr_data)
    te_data = [[te_rsp.data[s,:,:,tr].T for tr in range(te_rsp.data.shape[3])]
               for s in range(te_rsp.data.shape[0])]
    pred_movies = model.predict(te_data)
    cm = confusion_matrix(np.array(pred_movies))
    # cm = confusion_matrix_grating(pred_movies)
    print cm, cm_goodness(cm, exp_type)
    """
示例#3
0
for i, response in enumerate(responses):
    name = response.name
    print 'Mouse %s' % name

    print 'Splitting out training and test data...'
    tr_rsp, te_rsp, tr_mov, te_mov = train_test_splits[i]
    # tr_rsp, te_rsp = train_test_splits[i]

    print 'Fitting template-matching model...'
    model = AverageTemplate()
    model.fit(tr_rsp)
    print 'Decoding movie indices from test responses...'
    pred_movies = model.predict(te_rsp)
    cm = confusion_matrix(pred_movies)
    # cm = confusion_matrix_grating(pred_movies)
    print cm, cm_goodness(cm, exp_type)
    """
    print 'Fitting DTW model...'
    model = DTWClassifier(3)
    tr_data = [[tr_rsp.data[s,:,:,tr].T for tr in range(tr_rsp.data.shape[3])]
               for s in range(tr_rsp.data.shape[0])]
    model.fit(tr_data)
    te_data = [[te_rsp.data[s,:,:,tr].T for tr in range(te_rsp.data.shape[3])]
               for s in range(te_rsp.data.shape[0])]
    pred_movies = model.predict(te_data)
    cm = confusion_matrix(np.array(pred_movies))
    # cm = confusion_matrix_grating(pred_movies)
    print cm, cm_goodness(cm, exp_type)
    """