How to use the kmapper.visuals.init_color_function function in kmapper

To help you get started, we’ve selected a few kmapper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-tda / kepler-mapper / test / test_visuals.py View on Github external
def test_color_function_type(self):
        nodes = {"a": [1, 2, 3], "b": [4, 5, 6]}
        graph = {"nodes": nodes}

        color_function = init_color_function(graph)

        assert type(color_function) == np.ndarray
        assert min(color_function) == 0
        assert max(color_function) == 1
github scikit-tda / kepler-mapper / test / test_visuals.py View on Github external
def test_color_function_size(self):
        nodes = {"a": [1, 2, 3], "b": [4, 5, 6, 7, 8, 9]}
        graph = {"nodes": nodes}

        color_function = init_color_function(graph)

        assert len(color_function) == len(nodes["a"]) + len(nodes["b"]) + 1
github scikit-tda / kepler-mapper / test / test_visuals.py View on Github external
def test_color_function_scaled(self):
        nodes = {"a": [1, 2, 3], "b": [4, 5, 6]}
        graph = {"nodes": nodes}

        cf = np.array([6, 5, 4, 3, 2, 1])
        color_function = init_color_function(graph, cf)

        # np.testing.assert_almost_equal(min(color_function), 0)
        # np.testing.assert_almost_equal(
        #     max(color_function), 1
        # ), "Scaler might have floating point issues, 1.0000...0002"

        # build_histogram in visuals.py assumes/needs this
        assert min(color_function) == 0
        assert max(color_function) == 1
github scikit-tda / kepler-mapper / kmapper / plotlyviz.py View on Github external
-------
    the graph dictionary in a json representation, the mapper summary
    and the node_distribution

    Example
    -------

    >>> kmgraph,  mapper_summary, n_distribution = get_mapper_graph(simplicial_complex)

    """
    if not len(simplicial_complex["nodes"]) > 0:
        raise Exception(
            "A mapper graph should have more than 0 nodes. This might be because your clustering algorithm might be too sensitive and be classifying all points as noise."
        )

    color_function = init_color_function(simplicial_complex, color_function)

    json_graph = scomplex_to_graph(
        simplicial_complex,
        color_function,
        X,
        X_names,
        lens,
        lens_names,
        custom_tooltips,
        colorscale=colorscale,
    )
    colorf_distribution = graph_data_distribution(
        simplicial_complex, color_function, colorscale
    )
    mapper_summary = format_meta(
        simplicial_complex,
github scikit-tda / kepler-mapper / kmapper / kmapper.py View on Github external
"""

        # TODO:
        #   - Make color functions more intuitive. How do they even work?
        #   - Allow multiple color functions that can be toggled on and off.

        if not len(graph["nodes"]) > 0:
            raise Exception(
                "Visualize requires a mapper with more than 0 nodes. \nIt is possible that the constructed mapper could have been constructed with bad parameters. This can occasionally happens when using the default clustering algorithm. Try changing `eps` or `min_samples` in the DBSCAN clustering algorithm."
            )

        # Find the module absolute path and locate templates
        module_root = os.path.join(os.path.dirname(__file__), "templates")
        env = Environment(loader=FileSystemLoader(module_root))
        # Color function is a vector of colors?
        color_function = init_color_function(graph, color_function)

        if X_names is None:
            X_names = []

        if lens_names is None:
            lens_names = []

        mapper_data = format_mapper_data(
            graph,
            color_function,
            X,
            X_names,
            lens,
            lens_names,
            custom_tooltips,
            env,