Ejemplo n.º 1
0
    args, unknown = argparser.parse_known_args()

    p = Config(args.config_path)
    models = p.model_list[:]
    lm_formula = p.models['LMnoS_noRE']['formula']

    preds = get_preds(lm_formula)
    preds = list(preds)
    preds.sort(reverse=True, key=lambda x: len(x))
    n_pred = len(preds)

    perms = list(itertools.product(range(0, 4), repeat=n_pred))

    forms = permute_spillover(lm_formula, preds, perms)

    dtsr_formula_list = [Formula(p.models[m]['formula']) for m in p.model_list if m.startswith('DTSR')]
    dtsr_formula_name_list = [m for m in p.model_list if m.startswith('DTSR')]
    X, y = read_data(p.X_train, p.y_train, p.series_ids, categorical_columns=list(set(p.series_ids + [v for x in dtsr_formula_list for v in x.rangf])))
    X, y, select, X_2d_predictor_names, X_2d_predictors = preprocess_data(X, y, p, dtsr_formula_list, compute_history=False)

    from dtsr.baselines import py2ri
    X['splitID'] = compute_splitID(X, p.split_ids)
    part = compute_partition(X, p.modulus, 3)
    part_select = part[0]
    X_baseline = X[part_select]
    X_baseline = X_baseline.reset_index(drop=True)[select]

    n_train_sample = len(y)

    sys.stderr.write('\nNumber of training samples: %d\n' %n_train_sample)
Ejemplo n.º 2
0
    p = Config(args.config_path)
    if len(args.models) > 0:
        models = args.models
    else:
        models = p.model_list[:]

    run_baseline = False
    run_dtsr = False
    for m in models:
        if not run_baseline and m.startswith('LM') or m.startswith('GAM'):
            run_baseline = True
        elif not run_dtsr and m.startswith('DTSR'):
            run_dtsr = True

    dtsr_formula_list = [
        Formula(p.models[m]['formula']) for m in p.model_list
        if m.startswith('DTSR')
    ]
    dtsr_formula_name_list = [m for m in p.model_list if m.startswith('DTSR')]
    if args.partition == 'train':
        X, y = read_data(
            p.X_train,
            p.y_train,
            p.series_ids,
            categorical_columns=list(
                set(p.split_ids + p.series_ids +
                    [v for x in dtsr_formula_list for v in x.rangf])))
    elif args.partition == 'dev':
        X, y = read_data(
            p.X_dev,
            p.y_dev,
Ejemplo n.º 3
0
    default_irf_str = impulse_to_irf['default']
else:
    default_irf_str = 'ShiftedGammaShapeGT1(alpha=2, beta=5, delta=-0.2, ran=T)'

impulse_to_transform = {}
if 'impulse_to_transform' in config:
    for key in config['impulse_to_transform']:
        impulse_to_transform[key] = config['impulse_to_transform'][key]

baseline_found = False
for name in config:
    if name.startswith('model_DTSR') and name.endswith('_BASELINE'):
        baseline_found = True
        new_name = name[:-9]
        model_template = config[name]
        f = Formula(model_template['formula'])

        for effect in main_effects:
            irf_str = impulse_to_irf.get(effect, default_irf_str)
            effect_name = effect
            transform = impulse_to_transform.get(effect, ['s'])
            if transform == 'None':
                transform = []
            elif isinstance(transform, basestring):
                transform = transform.strip().split()
            for t in reversed(transform):
                effect_name = t + '(' + effect_name + ')'

            f.insert_impulses(effect_name, irf_str, rangf=['subject'])

        config[new_name] = dict(config[name]).copy()
    default_irf_str = impulse_to_irf['default']
else:
    default_irf_str = 'ShiftedGammaShapeGT1(alpha=2, beta=5, delta=-0.2, ran=T)'

impulse_to_transform = {}
if 'impulse_to_transform' in config:
    for key in config['impulse_to_transform']:
        impulse_to_transform[key] = config['impulse_to_transform'][key]

baseline_found = False
for name in config:
    if name.startswith('model_DTSR') and name.endswith('_BASELINE'):
        baseline_found = True
        new_name = name[:-9]
        model_template = config[name]
        f = Formula(model_template['formula'])

        for effect in main_effects:
            irf_str = impulse_to_irf.get(effect, default_irf_str)
            effect_name = effect
            transform = impulse_to_transform.get(effect, ['s'])
            if transform == 'None':
                transform = []
            elif isinstance(transform, basestring):
                transform = transform.strip().split()
            for t in reversed(transform):
                effect_name = t + '(' + effect_name + ')'
           
            f.insert_impulses(effect_name, irf_str, rangf=['subject'])

        config[new_name] = dict(config[name]).copy()
impulse_to_transform = {}
if 'impulse_to_transform' in config:
    for key in config['impulse_to_transform']:
        impulse_to_transform[key] = config['impulse_to_transform'][key]

newpred_rangf = ['subject']
if 'newpred_rangf' in config:
    newpred_rangf = config['newpred_rangf']['rangf'].strip().split()

baseline_found = False
for name in config:
    if name.startswith('model_DTSR') and name.endswith('_BASELINE'):
        baseline_found = True
        new_name = name[:-9]
        model_template = config[name]
        f = Formula(model_template['formula'])

        for effect in main_effects:
            if effect.startswith('~'):
                ablate = True
                effect = effect[1:]
            else:
                ablate = False

            irf_str = impulse_to_irf.get(effect, default_irf_str)
            effect_name = effect
            transform = impulse_to_transform.get(effect, ['s'])
            if transform == 'None':
                transform = []
            elif isinstance(transform, str):
                transform = transform.strip().split()
impulse_to_transform = {}
if 'impulse_to_transform' in config:
    for key in config['impulse_to_transform']:
        impulse_to_transform[key] = config['impulse_to_transform'][key]

newpred_rangf = ['subject']
if 'newpred_rangf' in config:
    newpred_rangf = config['newpred_rangf']['rangf'].strip().split()

baseline_found = False
for name in config:
    if name.startswith('model_DTSR') and name.endswith('_BASELINE'):
        baseline_found = True
        new_name = name[:-9]
        model_template = config[name]
        f = Formula(model_template['formula'])

        for effect in main_effects:
            if effect.startswith('~'):
                ablate = True
                effect = effect[1:]
            else:
                ablate = False

            irf_str = impulse_to_irf.get(effect, default_irf_str)
            effect_name = effect
            transform = impulse_to_transform.get(effect, ['s'])
            if transform == 'None':
                transform = []
            elif isinstance(transform, str):
                transform = transform.strip().split()
import sys
import configparser

sys.path.append(sys.argv[1])
from dtsr.formula import Formula

config = configparser.ConfigParser()
config.optionxform = str
config.readfp(sys.stdin)

cols = ['word', 'time', 'subject']
cols += config['data']['series_ids'].strip().split()
if 'split_ids' in config['data']:
    cols += config['data']['split_ids'].strip().split()
for m in [x for x in config if x.startswith('model_DTSR')]:
    formula = Formula(config[m]['formula'])
    cols.append(formula.dv_term.id)
    for impulse in formula.t.impulses():
        cols.append(impulse.id)

cols = sorted(list(set(cols)))
print(' '.join(cols))