import math


def cosine_decay_restarts(
    steps_for_cycle,
    max_epochs,
    increase_restart_interval_factor=2,
):
    """Learning rate factors for cyclic schedule with restarts."""
    lr_factors = []

    step = 0
    cycle = 0

    for _ in range(0, max_epochs + 1):
        step += 1
        completed_fraction = step / steps_for_cycle
        cosine_decayed = 0.5 * (1 + math.cos(math.pi * completed_fraction))
        lr_factors.append(cosine_decayed)

        if completed_fraction == 1:
            step = 0
            cycle += 1
            steps_for_cycle = steps_for_cycle * increase_restart_interval_factor

    return lr_factors