Ejemplo n.º 1
0
def load(id_, cfg_id, base_cfg_id, return_dict):
    return_dict[id_] = (-1, (0, 0))
    # base_paths = ['models', 'modelsDec10-14']
    base_paths = ['models']
    res = []
    for base_path in base_paths:
        ids_ = [
            '../' + base_path + "/%s-*-F-m1",
            '../' + base_path + "/%s-*-6-m1"
        ]
        for id__ in ids_:
            print(id__ % cfg_id)
            res.extend(list(glob.glob(id__ % cfg_id)))
    print('####################')
    print(id_)
    print(res)

    stuns = []
    for fname in res:
        fname = fname[:-3]
        # print(fname)
        for _ in range(20):
            exp = Experiment(base_cfg_id, show_gui=False, dump_cfg=False)
            exp.load_eval(fname, steps=3000, initial_survival_time=3000)
            stuns.append(exp.env.n_stuns)

    if stuns:
        ci = st.t.interval(0.95, len(stuns)-1, loc=np.mean(stuns), scale=st.sem(stuns))
        print('avg_stuns:%d' % np.mean(stuns), stuns)
        return_dict[id_] = (np.mean(stuns), ci)
    else:
        return_dict[id_] = (0, (0, 0))
Ejemplo n.º 2
0
def load(fname, scenario, ret_steps_til_first_kill, ret_fish_pop):
    for _ in range(10):
        exp = Experiment(BASE_CFG, show_gui=False, dump_cfg=False)
        exp.env.select_fish_types(0, scenario, 0)
        _, _ = exp.load_eval(fname, steps=MAX_STEPS, initial_survival_time=3000)
        ret_steps_til_first_kill.append(exp.env.steps_til_first_kill)
        ret_fish_pop.append(len(exp.env.fishes))
def load(id_, cfg_id, base_cfg_id, return_dict):
    base_paths = ['../modelsDec21-31', '../modelsJan01-10', '../modelsRest']
    res = []
    for base_path in base_paths:
        ids_ = [
            base_path + "/%s-*-F-m1",
            base_path + "/%s_sp200-*-F-m1",
            base_path + "/%s-*-6-m1",
            base_path + "/%s_sp200-*-6-m1"
        ]
        for id__ in ids_:
            print(id__ % cfg_id)
            res.extend(list(glob.glob(id__ % cfg_id)))
    print('####################')
    print(id_)
    print(res)

    failures = 0
    total = 0
    coop_ratios = []
    herding_counter = 0
    for fname in res:
        fname = fname[:-3]
        print(fname)
        try:
            for _ in range(20):
                exp = Experiment(base_cfg_id, show_gui=False, dump_cfg=False)
                Fish.PROCREATE_AFTER_N_STEPS = 500
                exp.env.select_fish_types(0, 2, 0)
                exp.env.max_fish = 10
                Shark.FRICTION = 0.1
                Shark.MAX_SPEED_CHANGE = 0.06
                fish_pop_hist, _ = exp.load_eval(fname, steps=3000, initial_survival_time=3000)

                kpi = fish_pop_hist[-1]
                if kpi >= 1 and kpi < 10:
                    herding_counter += 1

                if exp.env.dead_fishes != 0:
                    coop_ratios.append(exp.env.coop_kills / exp.env.dead_fishes)
                else:
                    failures += 1
                    print('#### NO dead fishes! ####')
                total += 1
        except Exception as ex:
            print('wtf.', ex)
            return_dict['fails'] += 1

    if coop_ratios:
        ci = st.t.interval(0.95, len(coop_ratios)-1, loc=np.mean(coop_ratios), scale=st.sem(coop_ratios))
        print('avg_coop_ratio:%d' % np.mean(coop_ratios))
        return_dict[id_] = (np.mean(coop_ratios), ci, failures / float(total), herding_counter / float(total))
    else:
        return_dict[id_] = (0, (0, 0), 0, 0)
    print('Saving', id_)
    print(return_dict)
def load(id_, cfg_id, base_cfg_id, return_dict, use_full, shared):
    print('Actually starting', id_)
    suffix = '-m1'
    if shared:
        cfg_id = cfg_id.replace('n_net3', 'shared_net3')
        base_cfg_id = base_cfg_id.replace('n_net3', 'shared_net3')
        suffix = ''

    return_dict[id_] = (-1, (0, 0), -1)
    # base_paths = ['models', 'modelsDec10-14']
    base_paths = ['models']
    res = []
    for base_path in base_paths:
        ids_ = [
            '../' + base_path + "/%s-*-F" + suffix,
            '../' + base_path + "/%s-*-6" + suffix
        ]
        # print(ids_)
        for id__ in ids_:
            print(id__ % cfg_id)
            res.extend(list(glob.glob(id__ % cfg_id)))
    print('Now doing', id_)

    dead_fishes = []
    coop_ratios = []
    failures = []
    for fname in res:
        if not shared:
            fname = fname[:-3]
        for _ in range(10):
            exp = Experiment(base_cfg_id, show_gui=False, dump_cfg=False)
            exp.load_eval(fname, steps=3000, initial_survival_time=3000)
            if exp.env.dead_fishes != 0:
                if use_full:
                    coop_ratios.append(exp.env.full_coop_kills / exp.env.dead_fishes)
                else:
                    coop_ratios.append(exp.env.coop_kills / exp.env.dead_fishes)
                dead_fishes.append(exp.env.dead_fishes)
                failures.append(0.)
            else:
                failures.append(1.)

    len_ = len(coop_ratios)
    coop_ratios_old = coop_ratios[:]
    if coop_ratios:
        ci = st.t.interval(0.95, len_ - 1, loc=np.mean(coop_ratios), scale=st.sem(coop_ratios_old))
        print('avg_coop_ratio:%f' % np.mean(coop_ratios))
        ci_fail = st.t.interval(0.95, len(failures)-1, loc=np.mean(failures), scale=st.sem(failures))
        print('avg_fail_ratio:%f' % np.mean(failures))
        ci_dead = st.t.interval(0.95, len(dead_fishes)-1, loc=np.mean(dead_fishes), scale=st.sem(dead_fishes))
        print('avg_dead_ratio:%f' % np.mean(dead_fishes))
        return_dict[id_] = (np.mean(coop_ratios), ci, np.mean(failures), ci_fail, np.mean(dead_fishes), ci_dead)
    else:
        return_dict[id_] = (0, (0, 0), 0, (0, 0), 0, (0, 0))
Ejemplo n.º 5
0
def load(fname, scenario, ret_dead_fishes, ret_last_pops):
    xx = []
    for _ in range(100):
        exp = Experiment(BASE_CFG, show_gui=False, dump_cfg=False)
        exp.env.select_fish_types(0, scenario, 0)
        _, _ = exp.load_eval(fname, steps=MAX_STEPS, initial_survival_time=3000)
        ret_dead_fishes.append(exp.env.dead_fishes)
        ret_last_pops.append(len(exp.env.fishes))

        xx.append(exp.env.dead_fishes)
    print(fname, xx)
Ejemplo n.º 6
0
def load(id_, cfg_id, base_cfg_id, return_dict):
    base_paths = ['models', 'modelsDec10-14', 'modelsDec15-20']
    base_paths = ['models']
    res = []
    for base_path in base_paths:
        ids_ = [
            '../' + base_path + "/%s-*-F-m1",
            '../' + base_path + "/%s_sp200-*-F-m1",
            '../' + base_path + "/%s-*-6-m1",
            '../' + base_path + "/%s_sp200-*-6-m1"
        ]
        for id__ in ids_:
            print(id__ % cfg_id)
            res.extend(list(glob.glob(id__ % cfg_id)))
    print('####################')
    print(id_)
    print(res)

    failures = 0
    total = 0
    coop_ratios = []
    for fname in res:
        fname = fname[:-3]
        print(fname)
        try:
            for _ in range(20):
                exp = Experiment(base_cfg_id, show_gui=False, dump_cfg=False)
                exp.load_eval(fname, steps=3000, initial_survival_time=3000)
                if exp.env.dead_fishes != 0:
                    coop_ratios.append(exp.env.coop_kills /
                                       exp.env.dead_fishes)
                else:
                    failures += 1
                    print('#### NO dead fishes! ####')
                total += 1
        except Exception as ex:
            print('wtf.', ex)
            return_dict['fails'] += 1

    if coop_ratios:
        ci = st.t.interval(0.95,
                           len(coop_ratios) - 1,
                           loc=np.mean(coop_ratios),
                           scale=st.sem(coop_ratios))
        print('avg_coop_ratio:%d' % np.mean(coop_ratios))
        return_dict[id_] = (np.mean(coop_ratios), ci, failures / float(total))
    else:
        return_dict[id_] = (0, (0, 0), 0)
    print('Saving', id_)
    print(return_dict)
Ejemplo n.º 7
0
def load(scenario, return_dict, wait):
    dead_fishes = []
    last_pops = []
    tot_rewards = []

    for _ in range(100):
        exp = Experiment(BASE_CFG, show_gui=False, dump_cfg=False)
        exp.env.select_fish_types(0, scenario, 0)
        if wait:
            rewards = exp.evaluate_static_wait(steps=MAX_STEPS, initial_survival_time=3000)
        else:
            rewards = exp.evaluate_static(steps=MAX_STEPS, initial_survival_time=3000)
        tot_rewards.append(sum(rewards))
        dead_fishes.append(exp.env.dead_fishes)
        last_pops.append(len(exp.env.fishes))

    return_dict[scenario] = (dead_fishes, last_pops)
def load(id_, cfg_id, base_cfg_id, return_dict):
    return_dict[id_] = (-1, (0, 0))
    # base_paths = ['models', 'modelsDec10-14']
    base_paths = ['models']
    res = []
    for base_path in base_paths:
        ids_ = [
            '../' + base_path + "/%s-*-F-m1",
            '../' + base_path + "/%s-*-6-m1"
        ]
        for id__ in ids_:
            print(id__ % cfg_id)
            res.extend(list(glob.glob(id__ % cfg_id)))
    print('####################')
    print(id_)
    print(res)

    coop_ratios = []
    failures = []
    for fname in res:
        fname = fname[:-3]
        # print(fname)
        for _ in range(20):
            exp = Experiment(base_cfg_id, show_gui=False, dump_cfg=False)
            exp.load_eval(fname, steps=3000, initial_survival_time=3000)
            if exp.env.dead_fishes != 0:
                print(exp.env.coop_kills, exp.env.dead_fishes)
                coop_ratios.append(exp.env.coop_kills / exp.env.dead_fishes)
                failures.append(0.)
            else:
                failures.append(1.)
                print('####### NO dead fishes! #######')
                # TODO DUBIOUS! Should we maybe add a [0] if there's no dead fishes?
                # lets try.
                coop_ratios.append(0)

    if coop_ratios:
        ci = st.t.interval(0.95, len(coop_ratios)-1, loc=np.mean(coop_ratios), scale=st.sem(coop_ratios))
        print('avg_coop_ratio:%d' % np.mean(coop_ratios))
        ci_fail = st.t.interval(0.95, len(failures)-1, loc=np.mean(failures), scale=st.sem(failures))
        print('avg_fail_ratio:%d' % np.mean(failures))
        return_dict[id_] = (np.mean(coop_ratios), ci, np.mean(failures), ci_fail)
    else:
        return_dict[id_] = (0, (0, 0), 0)
Ejemplo n.º 9
0
def load(id_, cfg_id, return_dict):
    # base_cfg_id = 'ma3_obs'  # for i10, i5 (sp600)
    # base_cfg_id = 'ma3_obs_sp100'  # for i2
    # base_cfg_id = 'ma3_obs'
    base_cfg_id = 'ma3_obs_eval'  # sp100
    base_paths = ['models']
    res = []
    two_net = 'two_net' in cfg_id
    for base_path in base_paths:
        id__ = '../' + base_path + "/%s-*-F"
        if two_net:
            id__ = '../' + base_path + "/%s-*-F-m1"
        res.extend(list(glob.glob(id__ % cfg_id)))
    counter_coop = 0.
    counter_fail = 0.
    counter_greedy = 0.
    for fname in res:
        if two_net:
            fname = fname[:-3]
        print('#############################')
        print(fname)
        for _ in range(3):
            exp = Experiment(base_cfg_id, show_gui=False, dump_cfg=False)
            fish_pop_hist, _ = exp.load_eval(fname, steps=5000)
            if fish_pop_hist[-1] > 0 and fish_pop_hist[-1] < 10:
                counter_coop += 1
            if fish_pop_hist[-1] == 0:
                counter_greedy += 1
            if fish_pop_hist[-1] >= 10:
                counter_fail += 1

            # TODO: For i2 !
            # if fish_pop_hist[-1] > 0 and exp.env.dead_fishes > 0:
            #     counter_coop += 1
            # print(exp.env.dead_fishes)

        total = counter_coop + counter_greedy + counter_fail
        print('c:%d' % counter_coop, 'f:%d' % counter_fail,
              'g:%d' % counter_greedy, 't:%d' % total)

    print('coop', counter_coop / total)
    print('greedy', counter_greedy / total)
    print('fail', counter_fail / total)
    return_dict[id_] = (counter_coop / total, total)
Ejemplo n.º 10
0
def load(fname, scenario, ret_dead_fishes, ret_last_pops):
    static = fname == 'static'
    static_wait = fname == 'static_wait'

    temp = []
    for _ in range(100):
        exp = Experiment(BASE_CFG, show_gui=False, dump_cfg=False)
        # exp.env.select_fish_types(0, scenario, 0)
        if static_wait:
            _ = exp.evaluate_static_wait(steps=MAX_STEPS,
                                         initial_survival_time=3000)
        elif static:
            _ = exp.evaluate_static(steps=MAX_STEPS,
                                    initial_survival_time=3000)
        else:
            _, _ = exp.load_eval(fname,
                                 steps=MAX_STEPS,
                                 initial_survival_time=3000)
        temp.append(exp.env.dead_fishes)
        ret_dead_fishes.append(exp.env.dead_fishes)
        ret_last_pops.append(len(exp.env.fishes))
    print(fname, temp)
Ejemplo n.º 11
0
def run():
    cfg_id = 'dbg_n_net3_s035_i25_50x50'
    Experiment(cfg_id).train()
Ejemplo n.º 12
0
def new_exp():
    return Experiment(conf=None, backend='tiny', read_only=True)