コード例 #1
0
def do_simulation(path):
    """
    Uses a model identified by path to run a naive and a trained simulation
    :param path: The model path
    :return:
        [0]: The facing angle bin centers
        [1]: The occupancy of the naive model
        [2]: The occupancy of the trained model
    """
    global std_pt
    bins = np.linspace(-np.pi, np.pi, 100)
    # bin-centers in degress
    bcenters = bins[:-1] + np.diff(bins) / 2
    # naive simulation
    mdata = c.ModelData(path)
    model_naive = c.ZfGpNetworkModel()
    model_naive.load(mdata.ModelDefinition, mdata.FirstCheckpoint)
    model_trained = c.ZfGpNetworkModel()
    model_trained.load(mdata.ModelDefinition, mdata.LastCheckpoint)
    sim = MoTypes(False).pt_sim(model_naive, std_pt, 100)
    pos_naive = sim.run_simulation(GlobalDefs.n_steps)
    h_naive = a.bin_simulation_pt(pos_naive, bins)
    sim = MoTypes(False).pt_sim(model_trained, std_pt, 100)
    pos_trained = sim.run_simulation(GlobalDefs.n_steps)
    h_trained = a.bin_simulation_pt(pos_trained, bins)
    return bcenters, h_naive, h_trained
コード例 #2
0
def run_flat_gradient(model_path, drop_list=None):
    mdata = c.ModelData(model_path)
    gpn = MoTypes(False).network_model()
    gpn.load(mdata.ModelDefinition, mdata.LastCheckpoint)
    flt_params = GlobalDefs.circle_sim_params.copy()
    flt_params["t_max"] = flt_params["t_min"]
    sim = MoTypes(False).rad_sim(gpn, std, **flt_params)
    sim.t_max = sim.t_min  # reset gradient to be flat
    sim.remove = drop_list
    evo_path = model_path + '/evolve/generation_weights.npy'
    evo_weights = np.load(evo_path)
    w = np.mean(evo_weights[-1, :, :], 0)
    sim.bf_weights = w
    return sim.run_simulation(GlobalDefs.n_steps, False)