Exemple #1
0
    # Create data
    if args.behave == 'learn':
        trials, acc, p, prng = behave.learn(
                n_cond, args.n_trials, 
                loc=prng.normal(3, .3), prng=prng
                )
    elif args.behave == 'random':
        trials, acc, p, prng = behave.random(
                n_cond, args.n_trials, prng=prng
                )
    else:
        raise ValueError('--behave not understood')
    df, rlpars = reinforce.rescorla_wagner(trials, acc, p, prng=prng)

    # Convolve with HRF
    df = convolve_hrf(df, dg(), asbold)
    
    # Orth select regressors
    to_orth = [['box', bold] for bold in asbold if bold != 'box']
    for orth in to_orth:
        df[orth[1]+'_o'] = orthogonalize(df, orth)[orth[1]]
    
    # Do the regressions    
    n_results = {}
    for model_name, model, test, hypoth in zip(*model_configs):
        for bold_name in asbold:
            l = df.shape[0]
            noi, prng = white(l, prng=prng)

            df['bold'] = create_bold([df[bold_name].values], None, noi)
    # creates the BOLD.  The second creates
    # the predictors.
    for alpha_bold in alphas:            
        # Create all bold options
        df_bold, _ = reinforce.rescorla_wagner(
                trials, acc, p, 
                alpha=alpha_bold, prng=prng
                )
        
        # Iter options
        for bold_name in asbold:
            l = df_bold.shape[0]
            noi, prng = white(l, prng=prng)
            
            df_bold['bold'] = create_bold(
                    [df_bold[bold_name].values], dg(), noi
                    )
            
            # Create predictor
            for alpha_pred in alphas:
                df_pred, _ = reinforce.rescorla_wagner(
                        trials, acc, p, 
                        alpha=alpha_pred, prng=prng
                        )

                df_pred = convolve_hrf(df_pred, dg(), asbold)
                
                # Orth select predictors
                to_orth = [['box', too] for too in asbold if too != 'box']
                for orth in to_orth:
                    df_pred[orth[1]+'_o'] = orthogonalize(
        trial, acc, p, prng = behave.learn(
                args.n_cond, args.n_trials, 
                loc=prng.normal(3, .3), prng=prng
                )
    elif args.behave == 'random':
        trial, acc, p, prng = behave.random(
                args.n_cond, args.n_trials, prng=prng
                )
    else:
        raise ValueError('--behave not understood')
    
    df, rlpars = reinforce.rescorla_wagner(
            trial, acc, p, alpha=args.alpha, prng=prng
            )
    del df['rand']
    
    l = trial.shape[0]
    df['count'] = np.repeat(n, l)
    df['index'] = np.arange(l, dtype=np.int)
    
    dfs.append(df)
df = pd.concat(dfs, axis=0)

if args.convolve:
    tocon = ['box', 'acc', 'p', 'rpe', 'value']
    condf = convolve_hrf(df, dg(), tocon)
    for con in tocon:
        df[con] = condf[con]
    
df.to_csv(args.name, index=False, float_format='%.8f')
    # creates the BOLD.  The second creates
    # the predictors.
    for alpha_bold in alphas:
        # Create all bold options
        df_bold, _ = reinforce.rescorla_wagner(trials,
                                               acc,
                                               p,
                                               alpha=alpha_bold,
                                               prng=prng)

        # Iter options
        for bold_name in asbold:
            l = df_bold.shape[0]
            noi, prng = white(l, prng=prng)

            df_bold['bold'] = create_bold([df_bold[bold_name].values], dg(),
                                          noi)

            # Create predictor
            for alpha_pred in alphas:
                df_pred, _ = reinforce.rescorla_wagner(trials,
                                                       acc,
                                                       p,
                                                       alpha=alpha_pred,
                                                       prng=prng)

                df_pred = convolve_hrf(df_pred, dg(), asbold)

                # Orth select predictors
                to_orth = [['box', too] for too in asbold if too != 'box']
                for orth in to_orth:
    # Create data
    if args.behave == 'learn':
        trials, acc, p, prng = behave.learn(
                n_cond, args.n_trials, 
                loc=prng.normal(3, .3), prng=prng
                )
    elif args.behave == 'random':
        trials, acc, p, prng = behave.random(
                n_cond, args.n_trials, prng=prng
                )
    else:
        raise ValueError('--behave not understood')
    df, rlpars = reinforce.rescorla_wagner(trials, acc, p, prng=prng)

    # Convolve with HRF
    df = convolve_hrf(df, dg(), asbold)
    
    # Orth select regressors
    to_orth = [['box', too] for too in asbold if too != 'box']
    for orth in to_orth:
        df[orth[1]+'_o'] = orthogonalize(df, orth)[orth[1]]
    
    # Do the regressions    
    n_results = {}
    for model_name, model, test, hypoth in zip(*model_configs):
        for bold_name in asbold:
            l = df.shape[0]
            noi, prng = white(l, prng=prng)

            # Make bold
            df['bold'] = create_bold([df[bold_name].values], None, noi)