Project: s41467-024-48578-6 | Function: cross_order_gap_function_two_orders (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Implementation of cross-order gap function measuring asymmetries in temporal dependencies between hyperedges of different orders, quantifying directional preferences in group nucleation and fragmentation dynamics through normalized correlation differences

**KEY TERMS:** {
  "cross_order_correlation_function_d1_d2": "c^(d₁,d₂)(τ) forward correlation function",
  "cross_order_correlation_function_d2_d1": "c^(d₂,d₁)(τ) backward correlation function",
  "normalization": "2√(σ^(d₁)σ^(d₂)) normalization factor using standard deviations",
  "cross_order_gap": "δ^(d₁,d₂)(τ) asymmetry measure",
  "order1": "d₁ first hyperedge order",
  "order2": "d₂ second hyperedge order"
}

**CONTEXT CODE:**     """
    correlation_functions = dict()
    if max_order == None:
        max_order = max(adjacency_matrices_all_orders.keys())

    if normalized:
        sigmas = intra_order_correlation_functions_all_orders(
            adjacency_matrices_all_orders,
            annealed_adjacency_matrices_all_orders,
            max_order,
            tau=0,
        )

    for order1 in range(1, max_order + 1):
        for order2 in range(order1, max_order + 1):
            # order1 before order2
            correlation_function = cross_order_correlation_function_two_orders(
                adjacency_matrices_all_orders,
                annealed_adjacency_matrices_all_orders,
                order1,
                order2,
                tau,
            )
            correlation_functions[(order1, order2)] = correlation_function

            # order2 before order1
            if not order1 == order2:
                correlation_function = cross_order_correlation_function_two_orders(
                    adjacency_matrices_all_orders,
                    annealed_adjacency_matrices_all_orders,
                    order1,
                    order2,
                    tau,
                )
                correlation_functions[(order2, order1)] = correlation_function

            # normalization
            if normalized:
                normalization = 2 * np.sqrt(sigmas[order1] * sigmas[order2])
                correlation_functions[(order1, order2)] = (
                    correlation_functions[(order1, order2)] / normalization
                )
                if not order1 == order2:
                    correlation_functions[(order2, order1)] = (
                        correlation_functions[(order2, order1)] / normalization
                    )

    return correlation_functions


def cross_order_gap_function_two_orders(
    adjacency_matrices_all_orders: Dict[int, Dict[int, sparse.csc_array]],
    annealed_adjacency_matrices_all_orders=None,
    order1=1,
    order2=1,
    tau=0,
) -> float:
    """Compute the cross-order gap function between hyperedges of order d1 and d2, at time lag tau.

    Parameters
    ----------
    adjacency_matrices_all_orders: a dictionary {order : {time : adjacency matrix}}.
    annealed_adjacency_matrices_all_orders: a dictionary {order : annealed adjacency matrix}.
    order1: the first order.
    order2: the second order.
    tau: the temporal lag.

    Returns
    -------
    The cross-order gap function between orders d1 and d2, at time lag tau.
    """
    raise NotImplementedError("Function has been masked for testing purposes")


def cross_order_gap_functions_all_orders(
    adjacency_matrices_all_orders: Dict[int, Dict[int, sparse.csc_array]],
    annealed_adjacency_matrices_all_orders=None,
    max_order=None,
    tau=0,
) -> float:
    """Compute the cross-order gap functions between each couple of orders, at time lag tau.

    Parameters
    ----------
    adjacency_matrices_all_orders: a dictionary {order : {time : adjacency matrix}}.
    annealed_adjacency_matrices_all_orders: a dictionary {order : annealed adjacency matrix}.
    max_order: the maximum order.
    tau: the temporal lag.

    Returns
    -------
    The cross-order gap functions between each couple of orders, at time lag tau,
    as a dictionary {(d1, d2 : function)}
    """
    gap_functions = dict()
    if max_order == None:
        max_order = max(adjacency_matrices_all_orders.keys())
    for order1 in range(1, max_order + 1):
        for order2 in range(order1, max_order + 1):
            if order1 == order2:
                gap_functions[(order1, order2)] = 0
            else:
                gap_function = cross_order_gap_function_two_orders(
                    adjacency_matrices_all_orders,
                    annealed_adjacency_matrices_all_orders,
                    order1,
                    order2,
                    tau,
                )
                gap_functions[(order1, order2)] = gap_function
                gap_functions[(order2, order1)] = -1 * gap_function

    return gap_functions


Complete the function implementation replacing "raise NotImplementedError".