Esempio n. 1
0
def make_graphs(n_tmplt_nodes, n_world_nodes, n_layers, tmplt_prob, world_prob):
    tmplt_nodes = [x for x in range(n_tmplt_nodes)]
    world_nodes = [x for x in range(n_world_nodes)]

    tmplt_shape = (n_tmplt_nodes, n_tmplt_nodes)
    world_shape = (n_world_nodes, n_world_nodes)

    tmplt_adj_mats = [csr_matrix(np.random.choice([0, 1], tmplt_shape, p=[1-tmplt_prob, tmplt_prob])) for i in range(n_layers)]
    world_adj_mats = [csr_matrix(np.random.choice([0, 1], world_shape, p=[1-world_prob, world_prob])) for i in range(n_layers)]

    channels = [str(x) for x in range(n_layers)]

    tmplt = uclasm.Graph(np.array(tmplt_nodes), channels, tmplt_adj_mats)
    world = uclasm.Graph(np.array(world_nodes), channels, world_adj_mats)

    tmplt.is_cand = np.ones((tmplt.n_nodes,world.n_nodes), dtype=np.bool)
    tmplt.candidate_sets = {x: set(world.nodes) for x in tmplt.nodes}

    return tmplt, world
import sys
sys.path.append("..")

import numpy as np
import uclasm

nodelist, channels, adjs = uclasm.load_combo(
    "example_data_files/example_combo.csv",
    node_vs_edge_col=0,
    node_str="v",
    src_col=1,
    dst_col=2,
    channel_col=3,
    node_col=1,
    label_col=2,
    header=0)

nodes = nodelist.node
labels = nodelist.label

# Use the same graph data for both template and world graphs
tmplt = uclasm.Graph(nodes, channels, adjs, labels=labels)
world = uclasm.Graph(nodes, channels, adjs, labels=labels)
Esempio n. 3
0
                link_col_square[j * 3:j * 3 + 3, size + i * 3 + j] = 1

        for i in range(size):
            digit_idxs = [i * size + j for j in range(size)]
            rs_idxs = digit_idxs + [x + 2 * size * size for x in digit_idxs]
            cs_idxs = [x + size * size for x in digit_idxs
                       ] + [x + 2 * size * size for x in digit_idxs]
            world_adj_mats[1][np.ix_(rs_idxs, rs_idxs)] = link_row_square
            world_adj_mats[1][np.ix_(cs_idxs, cs_idxs)] = link_col_square

        for i in range(2):
            world_adj_mats[i] = sp.sparse.csr_matrix(world_adj_mats[i])
            tmplt_adj_mats[i] = sp.sparse.csr_matrix(tmplt_adj_mats[i])

    # initial candidate set for template nodes is the full set of world nodes
    tmplt = uclasm.Graph(np.array(tmplt_nodes), channels, tmplt_adj_mats)
    world = uclasm.Graph(np.array(world_nodes), channels, world_adj_mats)

    tmplt.is_cand = np.ones((tmplt.n_nodes, world.n_nodes), dtype=np.bool)
    tmplt.candidate_sets = {x: set(world.nodes) for x in tmplt.nodes}

    def update_node_candidates(tmplt, world, tmplt_node, cands):
        cand_row = np.zeros(world.n_nodes, dtype=np.bool)
        for cand in cands:
            cand_row[world.node_idxs[cand]] = True
        tmplt.is_cand[tmplt.node_idxs[tmplt_node]] &= cand_row

    tmplt.labels = np.array(['__'] * tmplt.n_nodes)
    world.labels = np.array(['__'] * world.n_nodes)

    if stype == "9x9":
Esempio n. 4
0
# Now generate world and template graphs, inserting a signal in the top left

np.random.seed(0)

channels = list(range(n_channels))

# TODO: allow for nodes of arbitrary dtype

# Note: by design, the template nodes have the same ids as the signal nodes
tmplt_nodes = np.arange(n_world_nodes, n_world_nodes+n_tmplt_nodes)
world_nodes = np.arange(n_world_nodes, 2*n_world_nodes)

tmplt_adj_mats = []
world_adj_mats = []

for channel in channels:
    tmplt_adj = np.random.geometric(tmplt_p, (n_tmplt_nodes, n_tmplt_nodes)) - 1
    world_adj = np.random.geometric(world_p, (n_world_nodes, n_world_nodes)) - 1

    # Embed a signal in the top left block of the world graph
    world_adj[:n_tmplt_nodes, :n_tmplt_nodes] += tmplt_adj

    tmplt_adj_mats.append(sparse.csc_matrix(tmplt_adj))
    world_adj_mats.append(sparse.csc_matrix(world_adj))


# initial candidate set for template nodes is the full set of world nodes
tmplt = uclasm.Graph(tmplt_nodes, channels, tmplt_adj_mats)
world = uclasm.Graph(world_nodes, channels, world_adj_mats)