Ejemplo n.º 1
0
from jb.jbutil import merge_first
from pandas import DataFrame, read_pickle
from fit_to_EI import ei_subject
import ggplot as gg
import pdb

OUTFOLDER = '/Users/jsb/Documents/drilling/analyses/bayesOpt_a/output/'
RAWFOLDER = '/Users/jsb/Documents/drilling/analyses/bayesOpt_a/raw/'

DF_NAME = 'df_bayesOpt_e_062515.pkl'
# name of pickled df with lenscales that best fit EI prediction of sub data
DF_FIT_NAME = 'df_lsfit_062615.pkl'

df = read_pickle(RAWFOLDER + DF_NAME)
df_lsfits = read_pickle(OUTFOLDER + DF_FIT_NAME)  # load
df = merge_first(df, df_lsfits, 'fit_ls', 'workerid')  # add fit_ls to exp data
df.rename(columns={'LENSCALE': 'exp_ls'}, inplace=True)
df_xDiff_wrt_fitls = df.groupby('workerid')\
            .apply(lambda dfs: ei_subject(dfs, dfs.fit_ls.iat[0]))\
            .reset_index(drop=True)\

df_xDiff_wrt_fitls.to_pickle(OUTFOLDER + 'df_xDiff_wrt_fitls_062615.pkl')

df_xDiff_wrt_fitls.groupby('workerid').std()
Ejemplo n.º 2
0
from glob import glob
from pandas import Series, DataFrame, concat, merge, read_pickle
from jb.jbutil import merge_first
import pdb


def stitch_pickled(critstring):
    assert critsting[-4:] == ".pkl" or critsting[-7:] == ".pickle", "critsting must end in pickle extension"
    subpkls = glob(critstring)
    subfits = [read_pickle(subpkl) for subpkl in subpkls]
    stitched_df = DataFrame(subfits)
    return stitched_df


df_lsfit = merge_first(df_lsfit, df, "LENSCALE", "workerid")
df_lsfit.rename(columns={"LENSCALE": "exp_ls"}, inplace=True)
Ejemplo n.º 3
0
import load_and_prep
# import prep_bayesOpt

# RUN fit_ls_eiregret_sub_runner.py FOR ALL SUBJECTS BEFORE RUNNING THIS SCRIPT!
print 'RUN fit_ls_eiregret_sub_runner.py FOR ALL SUBJECTS BEFORE RUNNING THIS SCRIPT!'

EXPNAME = 'noChoice_exp0'
EXPDATE = '072415'  # date that the raw data was pulled from database
BASEFOLDER = './'
# FIXME: not actually raw; processed by prep_bayesOpt.load_*
RAWFOLDER = BASEFOLDER + 'raw/'  # where data pulled from database is.
PREPPEDFOLDER = BASEFOLDER + 'prepped/'  # dfs prepped after extracting from db
OUTFOLDER = BASEFOLDER + 'output/'  # where results will be saved
SUBSERIES_FNAME = '_'.join(['series_lsfit_regret', EXPNAME, EXPDATE])  # template for the name of the output of the analysis
OUT_DF_NAME = '_'.join(['df_lsfit_regret', EXPNAME, EXPDATE])
PICKLED_DF_NAME = '_'.join(['df', EXPNAME, EXPDATE]) + '.pkl'

# stitch into a df
df_lsfits = stitch_pickled(OUTFOLDER+SUBSERIES_FNAME+'*.pkl')
# unpickle raw
dfprepped = unpickle(PREPPEDFOLDER + PICKLED_DF_NAME)
# merge experiment condition
merge_first(df_lsfits, dfprepped, 'LENSCALE', 'workerid')
merge_first(df_lsfits, dfprepped, 'counterbalance', 'workerid')
df_lsfits.rename(columns={'LENSCALE': 'exp_ls'}, inplace=True)

# save to csv for analysis in r
df_lsfits.to_csv(OUTFOLDER+OUT_DF_NAME+'.csv', index=False)
df_lsfits.to_pickle(OUTFOLDER+OUT_DF_NAME+'.pkl')