Commit 8a82f3c9 authored by Jan Kiene's avatar Jan Kiene
Browse files

make random patterns reproducable even when no seed is given

parent 7ac849f1
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -91,20 +91,24 @@ def create_br_switching_pattern(
    seed - for "exhaustive" and "random" strategies: inject seed for shuffling/choosing from array
    starting_br - for "exhaustive" and "random" strategies: start pattern with given bitrate, has to be contained in bitrates
    """
    assert strategy in ["from_array", "exhaustive", "random"]
    STRATEGIES = ["from_array", "exhaustive", "random"]
    assert strategy in STRATEGIES
    assert starting_br is None or starting_br in bitrates

    seed_str = f"_{seed}" if strategy == "random" or strategy == "exhaustive" else ""
    length_str = f"-l{length_frames}" if length_frames > 0 else ""
    fname = f"br_sw_pattern-{strategy}{seed_str}-{switch_time}{length_str}"

    # TODO: maybe calculate seed based on given parameter to automatically have reproducibility
    if seed is not None:
    brs = np.asarray(bitrates)

    # if no seed given, compute it from other parameters, so that same params => same seed
    if seed is None:
        seed = brs.sum() + STRATEGIES.index(strategy) + switch_time + length_frames
        if starting_br is not None:
            seed += starting_br
    random.seed(seed)

    if strategy == "from_array":
        brs = bitrates
    elif strategy == "exhaustive":
    if strategy == "exhaustive":
        # TODO: review, probably needs more work to be really exhaustive...
        n = len(brs) - 1
        permuts = list(permutations(bitrates, 2))