Exemplo n.º 1
0
def r_igraph_max_ave_degree(g):
    """
  Compute local triangle count of graph g and save as necessary
  *Global graph attributes can only be stored in the graph*

  @param g: The igraph graph loaded via Rpy2 i.e. an R object

  @return: Same graph an input but with added invariant as an attribute
  """

    mad = r_igraph_get_attr(
        g, "eigvals",
        "g")  # See if we already have computed eigenvalues for the graph
    if mad == NULL:  # Ok then compute top 1 eig ourself
        mad = r_igraph_eigs(g, 1, return_eigs=True, save_fn=None)[0]
    else:
        mad = float(mad[0].split(",")[0]
                    [1:])  # The largest eigenvalue is held at index 0

    if mad is not None:
        g = r_igraph_set_graph_attribute(g, "max_ave_degree", mad)
    else:  # More than likely ran out of memory
        print "Failed to estimate max ave degree because eigensolver failed ..."

    return g  # return so we can use for other attributes
Exemplo n.º 2
0
            inv_dict["k"] = min(100,
                                r_igraph_vcount(G, False) -
                                3)  # Max of 100 eigenvalues

        # Test if graph is too big for invariants
        print "Computing eigen decompositon ..."

        lcc = True if r_igraph_ecount(G, False) > 500000 else False
        if sep_save:
            inv_dict["eigvl_fn"] = os.path.join(inv_dict["save_dir"], "Eigen", \
                                      getBaseName(inv_dict["graph_fn"]) + "_eigvl.npy")
            inv_dict["eigvect_fn"] = os.path.join(inv_dict["save_dir"], "Eigen", \
                                      getBaseName(inv_dict["graph_fn"]) + "_eigvect.npy")
            G = r_igraph_eigs(G,
                              inv_dict['k'],
                              save_fn=(inv_dict["eigvl_fn"],
                                       inv_dict["eigvect_fn"]),
                              lcc=lcc)

        else:
            G = r_igraph_eigs(G, inv_dict['k'], save_fn=None, lcc=lcc)
        #else: G = r_igraph_eigs(G, 4, save_fn=None, lcc=True)

    if inv_dict.get("mad", False) != False:
        if r_igraph_vcount(
                G, False) < 1000000:  # Cannot compute eigs on very big graphs
            if sep_save:
                inv_dict["mad_fn"] = os.path.join(inv_dict["save_dir"], "MAD", \
                                          getBaseName(inv_dict["graph_fn"]) + "_mad.npy")
            print "Computing MAD ..."
            G = r_igraph_max_ave_degree(G)
Exemplo n.º 3
0
        if inv_dict.get("k") is None:
            inv_dict["k"] = min(100, r_igraph_vcount(G, False) - 3)  # Max of 100 eigenvalues

        # Test if graph is too big for invariants
        print "Computing eigen decompositon ..."

        lcc = True if r_igraph_ecount(G, False) > 500000 else False
        if sep_save:
            inv_dict["eigvl_fn"] = os.path.join(
                inv_dict["save_dir"], "Eigen", getBaseName(inv_dict["graph_fn"]) + "_eigvl.npy"
            )
            inv_dict["eigvect_fn"] = os.path.join(
                inv_dict["save_dir"], "Eigen", getBaseName(inv_dict["graph_fn"]) + "_eigvect.npy"
            )
            G = r_igraph_eigs(G, inv_dict["k"], save_fn=(inv_dict["eigvl_fn"], inv_dict["eigvect_fn"]), lcc=lcc)

        else:
            G = r_igraph_eigs(G, inv_dict["k"], save_fn=None, lcc=lcc)
        # else: G = r_igraph_eigs(G, 4, save_fn=None, lcc=True)

    if inv_dict.get("mad", False) != False:
        if r_igraph_vcount(G, False) < 1000000:  # Cannot compute eigs on very big graphs
            if sep_save:
                inv_dict["mad_fn"] = os.path.join(
                    inv_dict["save_dir"], "MAD", getBaseName(inv_dict["graph_fn"]) + "_mad.npy"
                )
            print "Computing MAD ..."
            G = r_igraph_max_ave_degree(G)
        else:
            print "Graph too big to compute spectral embedding"