Skip to content

filter

Functions:

threshold_connected

threshold_connected(
    K: SimsMat, bin: bool = True
) -> SimsMat

filter edge-weights until the graph is (barely) connected.

Uses binary search to efficiently find maximum threshold, and cardinality of a breadth-first search to check for connectivity (must be at least same edges as a spanning tree)

Parameters:

  • K

    (SimsMat) –

    square matrix (e.g. kernel) to be thresholded

  • bin

    (bool, default: True ) –

    whether to binarize the output, or cut-off only.

Source code in affinis/filter.py
def threshold_connected(K:SimsMat, bin:bool=True)->SimsMat:
    """filter edge-weights until the graph is (barely) connected.

    Uses binary search to efficiently find maximum threshold,
    and cardinality of a breadth-first search to check for
    connectivity (must be at least same edges as a spanning tree)

    Args:
      K: square matrix (e.g. kernel) to be thresholded 
      bin: whether to binarize the output, or cut-off only. 

    """
    edges = _sq(K)
    edges_masked = min_connected_filter(edges)

    if bin:
        return _sq((~edges_masked.mask).astype(int))
    else:
        return _sq(edges_masked.filled(0))

threshold_value

threshold_value(
    K: SimsMat, t: float, bin: bool = True
) -> SimsMat

Filter edge-weights below a given value.

Parameters:

  • K

    (SimsMat) –

    square matrix (e.g. kernel) to be thresholded

  • t

    (float) –

    cutoff-value

  • bin

    (bool, default: True ) –

    whether to binarize the output, or cut-off only.

Source code in affinis/filter.py
def threshold_value(K:SimsMat, t:float, bin:bool=True)->SimsMat:
    """Filter edge-weights below a given value.

    Args:
      K: square matrix (e.g. kernel) to be thresholded 
      t: cutoff-value
      bin: whether to binarize the output, or cut-off only. 
    """
    edges = _sq(K)
    edges_masked = threshold_edges_filter(edges, t)

    if bin:
        return _sq((~edges_masked.mask).astype(int))
    else:
        return _sq(edges_masked.filled(0))