Beispiel #1
0
def test_orthogonalize():
    # --
    # np
    # --
    # Two lines:
    dm1 = np.vstack([np.arange(10), np.arange(10)]).T
    dmo = dm.orthogonalize(dm1, [0,1])
    
    # Col 0 is unchanged
    # Orth col 1 is all zeros as all 
    # variance was assigned to 0.
    assert np.allclose(dmo[:,0], dm1[:,0])
    assert np.allclose(dmo[:,1], np.zeros_like(dmo[:,1]))

    # -----------------    
    # repeat for pandas
    # -----------------
    dm1 = pd.DataFrame(dm1, columns=['0', '1'])
    dmo = dm.orthogonalize(dm1, ['0','1'])
    assert np.allclose(dmo['0'].values, dm1['0'].values)
    assert np.allclose(dmo['1'].values, np.zeros_like(dmo['1'].values))
    
    
Beispiel #2
0
                )
    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)

            smo = smf.ols(model, data=df).fit()
            print(smo.summary2())
            
            stato = None
            if test == 't':
                    )
            
            # 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(
                            df_pred, orth
                            )[orth[1]]

                # Hold bold constant in the predictor loops                
                df_pred['bold'] = df_bold['bold']
                
                # Finally! Get modeling.
                for model_name, model, test, hypoth in zip(*model_configs):
                    
                    # Regress
                    smo = smf.ols(model, data=df_pred).fit()
                    print(smo.summary2())
            
                    # Hypoth
                    stato = None
                    if test == 't':
                                          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(df_pred,
                                                            orth)[orth[1]]

                # Hold bold constant in the predictor loops
                df_pred['bold'] = df_bold['bold']

                # Finally! Get modeling.
                for model_name, model, test, hypoth in zip(*model_configs):

                    # Regress
                    smo = smf.ols(model, data=df_pred).fit()
                    print(smo.summary2())

                    # Hypoth
                    stato = None
                    if test == 't':
                        stato = smo.t_test(hypoth)
                )
    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)

            # Regress
            smo = smf.ols(model, data=df).fit()
            print(smo.summary2())