{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"nnconvexity This package contains the documentation for the nnconvexity Python package. See also the code for the paper containing a demo for using this package. If you use our code, please cite the paper T\u011btkov\u00e1, L., Br\u00fcsch, T., Dorszewski, T. et al. On convex decision regions in deep network representations. Nat Commun 16, 5419 (2025). https://doi.org/10.1038/s41467-025-60809-y. We support two ways to compute convexity: Euclidean using [nnconvexity.euclidean][] graph using [nnconvexity.graph][] nnconvexity.euclidean.compute_euclidean_convexity(representations, labels, predict_from_middle, layer, n_pairs=5000, n_sampled=10) Compute Euclidean convexity (in %) for given representations and labels. Parameters: representations ( ndarray ) \u2013 (n_data, n_tokens, n_features) Latent representations. labels ( ndarray ) \u2013 (n_data,) Labels. predict_from_middle ( function ) \u2013 Function that takes features as input and returns predictions. Inputs: features (shape (n_interpolated data, n_tokens, n_features)), layer (int). Output: predictions (shape n_interpolated data). layer ( int ) \u2013 Layer to compute Euclidean convexity for. n_pairs ( int , default: 5000 ) \u2013 Maximum number of pairs within a concept used for evaluation. n_sampled ( int , default: 10 ) \u2013 Number of points sampled on each segment. Returns: float ( float ) \u2013 Mean Euclidean convexity (in %) over all pairs. Dict [ int , float ] \u2013 Dict[int, float]: Dictionary mapping concept label to Euclidean convexity (in %) of that concept. nnconvexity.graph.compute_graph_convexity(representations, labels, n_neighbors=10, max_n_paths=5000, n_parallel=1) Compute graph convexity (in %) for given representations and labels. Parameters: representations ( ndarray ) \u2013 (n_data, n_features) latent representations labels ( ndarray ) \u2013 (n_data,) labels n_neighbors ( int , default: 10 ) \u2013 number of nearest neighbors max_n_paths ( int , default: 5000 ) \u2013 maximum number of paths used for evaluation n_parallel ( int , default: 1 ) \u2013 number of parallel jobs Returns: float ( float ) \u2013 mean graph convexity (in %) over all paths Dict [ int , float ] \u2013 Dict[int, float]: dictionary mapping concept label to graph convexity (in %) of that concept","title":"Home"},{"location":"#nnconvexity","text":"This package contains the documentation for the nnconvexity Python package. See also the code for the paper containing a demo for using this package. If you use our code, please cite the paper T\u011btkov\u00e1, L., Br\u00fcsch, T., Dorszewski, T. et al. On convex decision regions in deep network representations. Nat Commun 16, 5419 (2025). https://doi.org/10.1038/s41467-025-60809-y. We support two ways to compute convexity: Euclidean using [nnconvexity.euclidean][] graph using [nnconvexity.graph][]","title":"nnconvexity"},{"location":"#nnconvexity.euclidean.compute_euclidean_convexity","text":"Compute Euclidean convexity (in %) for given representations and labels. Parameters: representations ( ndarray ) \u2013 (n_data, n_tokens, n_features) Latent representations. labels ( ndarray ) \u2013 (n_data,) Labels. predict_from_middle ( function ) \u2013 Function that takes features as input and returns predictions. Inputs: features (shape (n_interpolated data, n_tokens, n_features)), layer (int). Output: predictions (shape n_interpolated data). layer ( int ) \u2013 Layer to compute Euclidean convexity for. n_pairs ( int , default: 5000 ) \u2013 Maximum number of pairs within a concept used for evaluation. n_sampled ( int , default: 10 ) \u2013 Number of points sampled on each segment. Returns: float ( float ) \u2013 Mean Euclidean convexity (in %) over all pairs. Dict [ int , float ] \u2013 Dict[int, float]: Dictionary mapping concept label to Euclidean convexity (in %) of that concept.","title":"compute_euclidean_convexity"},{"location":"#nnconvexity.graph.compute_graph_convexity","text":"Compute graph convexity (in %) for given representations and labels. Parameters: representations ( ndarray ) \u2013 (n_data, n_features) latent representations labels ( ndarray ) \u2013 (n_data,) labels n_neighbors ( int , default: 10 ) \u2013 number of nearest neighbors max_n_paths ( int , default: 5000 ) \u2013 maximum number of paths used for evaluation n_parallel ( int , default: 1 ) \u2013 number of parallel jobs Returns: float ( float ) \u2013 mean graph convexity (in %) over all paths Dict [ int , float ] \u2013 Dict[int, float]: dictionary mapping concept label to graph convexity (in %) of that concept","title":"compute_graph_convexity"}]}