Exemple #1
0
out_dir = getResultFN("%(dfn)s" % {"dfn": dat_fn})
if not os.access(out_dir, os.F_OK):
    os.mkdir(out_dir)
out_dir = getResultFN("%(dfn)s/%(lbl)d" % {"dfn": dat_fn, "lbl": label})
if not os.access(out_dir, os.F_OK):
    os.mkdir(out_dir)

col_n0 = 0  #  current
col_n1 = 0  #  previous

#  can't directly use hnd_dat, as it condX are discontinuous,

stay_win, wekr_win, strg_win, \
     stay_tie, wekr_tie, strg_tie, \
     stay_los, wekr_los, strg_los, \
     win_cond, tie_cond, los_cond = _rd.get_ME_WTL(hnd_dat, tr0, tr1)
#  p(stay | W)

nWins = len(win_cond)
nTies = len(tie_cond)
nLoss = len(los_cond)

cond_events = [[stay_win, wekr_win, strg_win], [stay_tie, wekr_tie, strg_tie],
               [stay_los, wekr_los, strg_los]]

off_cond_events = [[
    union_arrs(wekr_win, strg_win),
    union_arrs(stay_win, strg_win),
    union_arrs(stay_win, wekr_win)
],
                   [

if not know_gt:
    hnd_dat = _rt.return_hnd_dat(dat_fn)
else:
    hnd_dat = _N.loadtxt(
        "/Users/arai/nctc/Workspace/AIiRPS_SimDat/rpsm_%s.dat" % dat_fn,
        dtype=_N.int)

SHUFFLE = 500
stds = _N.empty((SHUFFLE + 1, 9))
means = _N.empty((SHUFFLE + 1, 9))
lvs = _N.empty((SHUFFLE + 1, 9))
lens = _N.zeros((SHUFFLE + 1, 9), dtype=_N.int)

win_st, win_dn, win_up, tie_st, tie_dn, tie_up, los_st, los_dn, los_up, wins, ties, loss = _rt.get_ME_WTL(
    hnd_dat, 0, hnd_dat.shape[0])

win_cons, _win_st_cons, _win_dn_cons, _win_up_cons = one_condition(
    _N.sort(wins), win_st, win_dn, win_up)
tie_cons, _tie_st_cons, _tie_dn_cons, _tie_up_cons = one_condition(
    _N.sort(ties), tie_st, tie_dn, tie_up)
los_cons, _los_st_cons, _los_dn_cons, _los_up_cons = one_condition(
    _N.sort(loss), los_st, los_dn, los_up)

stays = _N.zeros((SHUFFLE + 1, 9))
for shf in range(SHUFFLE + 1):
    if shf == SHUFFLE:
        win_st_cons = _win_st_cons
        win_dn_cons = _win_dn_cons
        win_up_cons = _win_up_cons
        tie_st_cons = _tie_st_cons
Exemple #3
0
def kernel_NGS(dat, SHUF=0, kerwin=3):
    _td = _rt.return_hnd_dat(dat)
    Tgame = _td.shape[0]
    cprobs = _N.zeros((3, 3, Tgame - 1))

    stay_win, dn_win, up_win, stay_tie, dn_tie, up_tie, stay_los, dn_los, up_los, win_cond, tie_cond, los_cond = _rt.get_ME_WTL(
        _td, 0, Tgame)

    gk = _Am.gauKer(kerwin)
    gk /= _N.sum(gk)
    all_cnd_tr = _N.zeros((3, 3, Tgame - 1))
    ker_all_cnd_tr = _N.ones((3, 3, Tgame - 1)) * -100

    all_cnd_tr[0, 0, stay_win] = 1
    all_cnd_tr[0, 1, dn_win] = 1
    all_cnd_tr[0, 2, up_win] = 1
    all_cnd_tr[1, 0, stay_tie] = 1
    all_cnd_tr[1, 1, dn_tie] = 1
    all_cnd_tr[1, 2, up_tie] = 1
    all_cnd_tr[2, 0, stay_los] = 1
    all_cnd_tr[2, 1, dn_los] = 1
    all_cnd_tr[2, 2, up_los] = 1

    for iw in range(3):
        if iw == 0:
            cond = _N.sort(win_cond)
        elif iw == 1:
            cond = _N.sort(tie_cond)
        elif iw == 2:
            cond = _N.sort(los_cond)

        for it in range(3):
            print(all_cnd_tr[iw, it, cond])
            ker_all_cnd_tr[iw, it, cond] = _N.convolve(all_cnd_tr[iw, it,
                                                                  cond],
                                                       gk,
                                                       mode="same")
            for n in range(1, Tgame - 1):
                if ker_all_cnd_tr[iw, it, n] == -100:
                    ker_all_cnd_tr[iw, it, n] = ker_all_cnd_tr[iw, it, n - 1]
            n = 0
            while ker_all_cnd_tr[iw, it, n] == -100:
                n += 1
            ker_all_cnd_tr[iw, it, 0:n] = ker_all_cnd_tr[iw, it, n]

    for iw in range(3):
        for_cond = _N.sum(ker_all_cnd_tr[iw], axis=0)
        for it in range(3):
            print(ker_all_cnd_tr[iw, it].shape)
            ker_all_cnd_tr[iw, it] /= for_cond

    return ker_all_cnd_tr