def algo_head_tail_bisearch(edges, x, costs, g, root, s_low, s_high, max_num_iter, verbose): """ This is the wrapper of head/tail-projection proposed in [2]. :param edges: edges in the graph. :param x: projection vector x. :param costs: edge costs in the graph. :param g: the number of connected components. :param root: root of subgraph. Usually, set to -1: no root. :param s_low: the lower bound of the sparsity. :param s_high: the upper bound of the sparsity. :param max_num_iter: the maximum number of iterations used in binary search procedure. :param verbose: print out some information. :return: 1. the support of the projected vector 2. the projected vector """ prizes = x * x # to avoid too large upper bound problem. if s_high >= len(prizes) - 1: s_high = len(prizes) - 1 re_nodes = wrap_head_tail_bisearch(edges, prizes, costs, g, root, s_low, s_high, max_num_iter, verbose) proj_w = np.zeros_like(x) proj_w[re_nodes[0]] = x[re_nodes[0]] return re_nodes[0], proj_w
def algo_head_tail_bisearch(edges, x, costs, g, root, s_low, s_high, max_num_iter, verbose): prizes = x * x # to avoid too large upper bound problem. if s_high >= len(prizes) - 1: s_high = len(prizes) - 1 re_nodes = wrap_head_tail_bisearch(edges, prizes, costs, g, root, s_low, s_high, max_num_iter, verbose) proj_w = np.zeros_like(x) proj_w[re_nodes[0]] = x[re_nodes[0]] return re_nodes[0], proj_w