Exemple #1
0
def _load_experiment(ex_dir: pyrado.PathLike):
    # Load the algorithm
    algo = Algorithm.load_snapshot(ex_dir)
    if not isinstance(algo, (NPDR, BayesSim)):
        raise pyrado.TypeErr(given=algo, expected_type=(NPDR, BayesSim))

    # Load the prior and the data
    prior = pyrado.load("prior.pt", ex_dir)
    data_real = pyrado.load("data_real.pt", ex_dir)

    # Load the posteriors
    posteriors = [
        SBIBase.load_posterior(ex_dir, idx_round=i, verbose=True)
        for i in range(algo.num_sbi_rounds)
    ]
    posteriors = remove_none_from_list(
        posteriors)  # in case the algorithm terminated early

    if data_real.shape[0] > len(posteriors):
        print_cbt(
            f"Found {data_real.shape[0]} data sets but {len(posteriors)} posteriors. Truncated the superfluous data.",
            "y",
        )
        data_real = data_real[:len(posteriors), :]

    # Artificially repeat the data (which was the same for every round) to later be able to use the same code
    data_real = data_real.repeat(len(posteriors), 1)
    assert data_real.shape[0] == len(posteriors)

    return algo, prior, data_real, posteriors
Exemple #2
0
    env_sim, policy, kwout = load_experiment(ex_dir, args)
    env_real = pyrado.load("env_real.pkl", ex_dir)
    prior = kwout["prior"]
    posterior = kwout["posterior"]
    data_real = kwout["data_real"]

    if args.mode.lower() == "evolution-round" and args.iter == -1:
        args.iter = algo.curr_iter
        print_cbt(
            "Set the evaluation iteration to the latest iteration of the algorithm.",
            "y")

    # Load the sequence of posteriors if desired
    if args.mode.lower() == "evolution-iter":
        posterior = [
            SBIBase.load_posterior(ex_dir, idx_iter=i, verbose=True)
            for i in range(algo.max_iter)
        ]
        posterior = remove_none_from_list(
            posterior)  # in case the algorithm terminated early
    elif args.mode.lower() == "evolution-round":
        posterior = [
            SBIBase.load_posterior(ex_dir, idx_round=i, verbose=True)
            for i in range(algo.num_sbi_rounds)
        ]
        posterior = remove_none_from_list(
            posterior)  # in case the algorithm terminated early

    if "evolution" in args.mode.lower(
    ) and data_real.shape[0] > len(posterior):
        print_cbt(