def epoch_init(M, i, j, w):
    """
    Initialize epoch index from daily period, day of week and week of cycle.

    :param M: Model
    :param i: period of day
    :param j: day of week
    :param w: week of cycle
    :return: period of cycle in 1..n_prds_per_cycle
    """
    return (w - 1) * M.n_days_per_week() * M.n_prds_per_day() + (j - 1) * M.n_prds_per_day() + i