def fatigue(raw_activities, energies, fatigue_rate=0.0003, recharge_rate=0.0001
    ):
    """
    Limit the frequency and intensity of activities with a model of fatigue.

    @param raw_activities: array of floats
        The activities before fatigue has been applied.
    @param energies: array of floats
        The accumulated energy a channel has at its disposal.
    @param fatigue_rate
        The rate at which energy is depleted when a channel is active.
    @param recharge_rate:
        The rate at which energy is re-accumulated.

    @return activities: array of floats
        The activities after fatigue has been applied.
    """
    energies -= fatigue_rate * raw_activities * energies
    energies += recharge_rate * (1.0 - raw_activities) * (1.0 - energies)
    activities = raw_activities * energies
    return activities
