def param_apply_map(param, deep=True, memo=None, **map):
    """Recursively re-map the values within the nested dictionary.

    Parameters
    ----------
    param : dict
        The dictionary of parameters.

    deep : bool, default=True
        Whether to recursively copy the nested dictionaries.

    memo : dict, default=None
        Internally used service dictionary to keep track of visited nested
        dictionaries.

    **map : keyworded functions
        The key-function mapping, applied to non-dictionary elements.

    Returns
    -------
    out : dict
        A shallow or deep modified copy of the original parameter dictionary.

    Details
    -------
    If `map` is provided, then produces a modified copy of the original
    dictionary, maintaining is key ordering.
    """
    if not map:
        return param

    # keep track of visited nested dictionaries by their `id(...)`
    if memo is None:
        memo = {}

    # nested self reference: return the previously computed dictionary
    if id(param) in memo:
        return memo[id(param)]

    out = {}
    memo[id(param)] = out  # reference the dynamically created dictionary

    # make an elementwise copy of the dictionary
    for key in param:
        value = param[key]
        # prioritize dfs, then pass the nested result through the map
        if isinstance(value, dict) and deep:
            value = param_apply_map(value, deep=True, memo=memo, **map)

        out[key] = value

    # map all non None values using the supplied map
    for key in out:
        value = out[key]
        if key in map and value is not None:
            out[key] = map[key](value)

    return out