Example #1
0
    def __init__(self, args):
        super(Model_joint, self).__init__()
        self.args = args
        self.num_features = args.num_features
        self.nhid = args.nhid
        self.num_classes = args.num_classes
        self.pooling_ratio = args.pooling_ratio
        self.dropout_ratio = args.dropout_ratio
        self.sample = args.sample_neighbor
        self.sparse = args.sparse_attention
        self.sl = args.structure_learning
        self.lamb = args.lamb

        self.conv1 = GCNConv(self.num_features, self.nhid)
        self.conv2 = GCN(self.nhid, self.nhid)
        self.conv3 = GCN(self.nhid, self.nhid)

        self.pool1 = HGPSLPool(self.nhid, self.pooling_ratio, self.sample, self.sparse, self.sl, self.lamb)
        self.pool2 = HGPSLPool(self.nhid, self.pooling_ratio, self.sample, self.sparse, self.sl, self.lamb)

        self.lin1 = torch.nn.Linear(self.nhid * 2, self.nhid)
        self.lin2 = torch.nn.Linear(self.nhid, self.nhid)

        self.lin3 = torch.nn.Linear(self.nhid * 2, self.nhid)
        self.lin4 = torch.nn.Linear(self.nhid, self.nhid)
        self.lin5 = torch.nn.Linear(self.nhid , self.num_classes)
Example #2
0
 def __init__(self, n_in, n_h, activation):
     super(GMI, self).__init__()
     self.gcn1 = GCN(
         n_in, n_h, activation
     )  # if on citeseer and pubmed, the encoder is 1-layer GCN, you need to modify it
     self.gcn2 = GCN(n_h, n_h, activation)
     self.disc1 = Discriminator(n_in, n_h)
     self.disc2 = Discriminator(n_h, n_h)
     self.avg_neighbor = AvgNeighbor()
     self.prelu = nn.PReLU()
     self.sigm = nn.Sigmoid()
Example #3
0
    def __init__(self,
                 ft_size,
                 hid_units,
                 n_networks,
                 same_discriminator=True):
        super(modeler, self).__init__()
        self.gcn_list = nn.ModuleList(
            [GCN(ft_size, hid_units) for _ in range(n_networks)])
        self.w_list = nn.ModuleList([
            nn.Linear(hid_units, hid_units, bias=False)
            for _ in range(n_networks)
        ])
        self.y_list = nn.ModuleList(
            [nn.Linear(hid_units, 1) for _ in range(n_networks)])

        self.disc_layers = InterDiscriminator(hid_units, ft_size)
        if same_discriminator:
            self.disc_fusion = self.disc_layers
        else:
            self.disc_fusion = InterDiscriminator(hid_units, ft_size)

        self.att_act1 = nn.Tanh()
        self.att_act2 = nn.Softmax(dim=-1)

        for m in self.modules():
            self.weights_init(m)
Example #4
0
 def __init__(self, n_in, n_h, activation):
     super(DGI, self).__init__()
     self.gcn = GCN(n_in, n_h, activation)
     self.read = AvgReadout()
     self.sigm = nn.Sigmoid()
     self.disc = Discriminator(n_h)
     self.disc2 = Discriminator2(n_h)
Example #5
0
def get_chordal_one_model(n_nodes, n_features, num_classes):
    """
    Returns a model specifically tailored to classify the chordal one dataset.

    :param n_nodes:     number of nodes
    :param n_features:  number of features
    :param num_classes: number of target classes

    :return:            tf model
    """
    node_features_input_layer = layers.Input(shape=(n_nodes, n_features),
                                             name='node_feature_input')
    adjacency_matrix_input_layer = layers.Input(shape=(n_nodes, n_nodes),
                                                name='adjacency_matrix_input')

    x = GCN(16,
            "relu")([node_features_input_layer, adjacency_matrix_input_layer])
    # x = layers.Dropout(rate=0.3)(x)

    # sum-pooling and dense connection to output nodes
    x = SumPool(16)(x)
    x = layers.Dense(num_classes,
                     activation="softmax",
                     activity_regularizer=tf.keras.regularizers.l1_l2(0.1))(x)

    model = tf.keras.Model(
        inputs=[node_features_input_layer, adjacency_matrix_input_layer],
        outputs=[x])
    return model
Example #6
0
File: DGI.py Project: isxinli/DMGI
    def __init__(self, args):
        super(modeler, self).__init__()
        self.args = args
        self.gcn = GCN(args.ft_size, args.hid_units, args.activation,
                       args.drop_prob, args.isBias)

        # one discriminator
        self.disc = Discriminator(args.hid_units)
        self.readout_func = self.args.readout_func
Example #7
0
    def __init__(self, args):
        super(Encoder, self).__init__()
        self.args = args
        self.num_features = args.num_features
        self.nhid = args.hdim
        self.num_classes = args.num_classes
        self.pooling_ratio = args.pooling_ratio
        self.dropout_ratio = args.dropout_ratio
        self.sample = args.sample_neighbor
        self.sparse = args.sparse_attention
        self.sl = args.structure_learning
        self.lamb = args.lamb

        self.conv1 = GCNConv(self.num_features, self.nhid)
        self.conv2 = GCN(self.nhid, self.nhid)
        self.conv3 = GCN(self.nhid, self.nhid)

        self.pool1 = HGPSLPool(self.nhid, self.pooling_ratio, self.sample, self.sparse, self.sl, self.lamb)
        self.pool2 = HGPSLPool(self.nhid, self.pooling_ratio, self.sample, self.sparse, self.sl, self.lamb)
Example #8
0
    def __init__(self, n_in, n_h, activation, k, device, hard, batch_size):
        super(DGI, self).__init__()
        self.gcn = GCN(n_in, n_h, activation)
        self.assign = Assign(k, n_h, device, hard)

        self.sigm = nn.Sigmoid()

        self.disc = Discriminator(n_h)

        self.k = k
Example #9
0
    def __init__(self, nfeat, nhid, shid, P, act):
        """Dense version of GAT."""
        super(HGCN, self).__init__()
        self.gcn_level_embeddings = []
        self.P = P #number of meta-Path
        for _ in range(P):
            self.gcn_level_embeddings.append(GCN(nfeat, nhid, act, bias=True))
            
        for i, gcn_embedding_path in enumerate(self.gcn_level_embeddings):
            
                self.add_module('gcn_path_{}'.format(i), gcn_embedding_path)

        self.semantic_level_attention = SemanticAttentionLayer(nhid, shid)
Example #10
0
    def __init__(self,n_nb, n_in, n_h, activation, num_clusters, beta):
        super(GIC, self).__init__()
        self.gcn = GCN(n_in, n_h, activation)
        
        self.read = AvgReadout()

        self.sigm = nn.Sigmoid()

        self.disc = Discriminator(n_h)
        self.disc_c = Discriminator_cluster(n_h,n_h,n_nb,num_clusters)
        
        
        self.beta = beta
        
        self.cluster = Clusterator(n_h,num_clusters)
Example #11
0
    def __init__(self, args):
        super(modeler, self).__init__()
        self.args = args
        self.gcn = nn.ModuleList([GCN(args.ft_size, args.hid_units, args.activation, args.drop_prob, args.isBias) for _ in range(args.nb_graphs)])

        self.disc = Discriminator(args.hid_units)
        self.H = nn.Parameter(torch.FloatTensor(1, args.nb_nodes, args.hid_units))
        self.readout_func = self.args.readout_func
        if args.isAttn:
            self.attn = nn.ModuleList([Attention(args) for _ in range(args.nheads)])

        if args.isSemi:
            self.logistic = LogReg(args.hid_units, args.nb_classes).to(args.device)

        self.init_weight()
Example #12
0
    def __init__(self,
                 n_in,
                 n_h,
                 activation,
                 critic="bilinear",
                 dataset=None,
                 attack_model=True):
        super(DGI, self).__init__()
        self.gcn = GCN(n_in, n_h, activation)
        self.read = AvgReadout()

        self.sigm = nn.Sigmoid()

        self.disc = Discriminator(n_h,
                                  critic=critic,
                                  dataset=dataset,
                                  attack_model=attack_model)
Example #13
0
def get_gcn_basic(n_nodes, n_features, num_classes):
    node_features_input_layer = layers.Input(shape=(n_nodes, n_features),
                                             name='node_feature_input')
    adjacency_matrix_input_layer = layers.Input(shape=(n_nodes, n_nodes),
                                                name='adjacency_matrix_input')

    # convolutional block 1
    x = GCN(32, "relu")([node_features_input_layer, adjacency_matrix_input_layer])
    # x = layers.Dropout(rate=0.3)(x)

    # sum-pooling and dense connection to output nodes
    x = SumPool(32)(x)
    x = layers.Dense(num_classes, activation="softmax")(x)

    model = tf.keras.Model(inputs=[node_features_input_layer, adjacency_matrix_input_layer],
                           outputs=[x])
    return model
Example #14
0
    def __init__(self, backbone='vgg', is_training=True):
        super().__init__()
        self.k_at_hop = [8, 4]
        self.post_dim = 120
        self.active_connection = 3
        self.is_training = is_training
        self.backbone_name = backbone
        self.fpn = FPN(self.backbone_name, self.is_training)
        self.gcn_model = GCN(600, 32)  # 600 = 480 + 120
        self.pooling = RROIAlign((3, 4), 1.0 / 1)  # (32+8)*3*4 =480

        # ##class and regression branch
        self.out_channel = 8
        self.predict = nn.Sequential(
            # nn.Conv2d(32, 16, kernel_size=3, stride=1, padding=1),
            nn.Conv2d(32, self.out_channel, kernel_size=1, stride=1,
                      padding=0))

        self.graph = Graph_RPN(self.pooling, 120)
Example #15
0
def get_chordal_two_model(n_nodes, n_features, num_classes):
    """
    Returns a model specifically tailored to classify the chordal two dataset.

    :param n_nodes:     number of nodes
    :param n_features:  number of features
    :param num_classes: number of target classes

    :return:            tf model
    """
    node_features_input_layer = layers.Input(shape=(n_nodes, n_features),
                                             name='node_feature_input')
    adjacency_matrix_input_layer = layers.Input(shape=(n_nodes, n_nodes),
                                                name='adjacency_matrix_input')

    x = GCN(64, "relu")([node_features_input_layer, adjacency_matrix_input_layer])
    x = layers.Dropout(rate=0.2)(x)

    x = SumPool(64)(x)
    x = layers.Dense(num_classes, activation="softmax")(x)

    model = tf.keras.Model(inputs=[node_features_input_layer, adjacency_matrix_input_layer],
                           outputs=[x])
    return model
Example #16
0
 def __init__(self, ft_size, hid_units):
     super(modeler, self).__init__()
     self.gcn = GCN(ft_size, hid_units)
     self.disc = InterDiscriminator(hid_units, ft_size)
Example #17
0
 def __init__(self, n_in, n_h, n_out, activation):
     super(GAE, self).__init__()
     self.hid = GCN(n_in, n_h, activation)
     self.out = GCN(n_h, n_out, act=lambda x: x)
     self.rec = InnerProductDecoder(act=lambda x: x)
Example #18
0
 def __init__(self, n_in, n_h, activation):
     super(Encoder, self).__init__()
     self.gcn = GCN(n_in, n_h, activation)
     self.mu = GCN(n_h, n_h * 2, activation)
     self.logvar = GCN(n_h, n_h * 2, activation)
Example #19
0
 def __init__(self, hidden_size, config, module_type):
     super(CognitiveGNN, self).__init__()
     self.gcn = GCN(hidden_size)
     self.both_net = MLP((hidden_size, hidden_size, 1))
     self.select_net = MLP((hidden_size, hidden_size, 1))
     self.module_type = module_type
Example #20
0
 def __init__(self, n_in, n_h, activation):
     self.gcn = GCN(n_in, n_h, activation)
     self.read = AvgReadout()
Example #21
0
 def __init__(self, n_features, n_hidden):
     super(DGI, self).__init__()
     self.gcn = GCN(n_features, n_hidden)
     self.readout = Readout()
     self.sigmoid = nn.Sigmoid()
     self.discriminator = Discriminator(n_hidden)