Beispiel #1
0
    def __init__(self,
                 in_n,
                 out_message,
                 out_update,
                 l_target,
                 type='regression'):
        super(MpnnIntNet, self).__init__()

        n_layers = len(out_update)

        # Define message 1 & 2
        self.m = nn.ModuleList([
            MessageFunction('intnet',
                            args={
                                'in': 2 * in_n[0] + in_n[1],
                                'out': out_message[i]
                            }) if i == 0 else MessageFunction(
                                'intnet',
                                args={
                                    'in': 2 * out_update[i - 1] + in_n[1],
                                    'out': out_message[i]
                                }) for i in range(n_layers)
        ])

        # Define Update 1 & 2
        self.u = nn.ModuleList([
            UpdateFunction('intnet',
                           args={
                               'in': in_n[0] + out_message[i],
                               'out': out_update[i]
                           }) if i == 0 else UpdateFunction(
                               'intnet',
                               args={
                                   'in': out_update[i - 1] + out_message[i],
                                   'out': out_update[i]
                               }) for i in range(n_layers)
        ])

        # Define Readout
        self.r = ReadoutFunction('intnet',
                                 args={
                                     'in': out_update[-1],
                                     'target': l_target
                                 })

        self.type = type
Beispiel #2
0
    def __init__(self,
                 d,
                 in_n,
                 out_update,
                 hidden_state_readout,
                 l_target,
                 type='regression'):
        super(MpnnDuvenaud, self).__init__()

        n_layers = len(out_update)

        # Define message 1 & 2
        self.m = nn.ModuleList(
            [MessageFunction('duvenaud') for _ in range(n_layers)])

        # Define Update 1 & 2
        self.u = nn.ModuleList([
            UpdateFunction('duvenaud',
                           args={
                               'deg': d,
                               'in': self.m[i].get_out_size(in_n[0], in_n[1]),
                               'out': out_update[0]
                           })
            if i == 0 else UpdateFunction(
                'duvenaud',
                args={
                    'deg': d,
                    'in': self.m[i].get_out_size(out_update[i - 1], in_n[1]),
                    'out': out_update[i]
                }) for i in range(n_layers)
        ])

        # Define Readout
        self.r = ReadoutFunction('duvenaud',
                                 args={
                                     'layers':
                                     len(self.m) + 1,
                                     'in': [
                                         in_n[0] if i == 0 else out_update[i -
                                                                           1]
                                         for i in range(n_layers + 1)
                                     ],
                                     'out':
                                     hidden_state_readout,
                                     'target':
                                     l_target
                                 })

        self.type = type
Beispiel #3
0
    def __init__(self,
                 e,
                 hidden_state_size,
                 message_size,
                 n_layers,
                 l_target,
                 type='regression'):
        super(MpnnGGNN, self).__init__()

        # Define message
        self.m = nn.ModuleList([
            MessageFunction('ggnn',
                            args={
                                'e_label': e,
                                'in': hidden_state_size,
                                'out': message_size
                            })
        ])

        # Define Update
        self.u = nn.ModuleList([
            UpdateFunction('ggnn',
                           args={
                               'in_m': message_size,
                               'out': hidden_state_size
                           })
        ])

        # Define Readout
        self.r = ReadoutFunction('ggnn',
                                 args={
                                     'in': hidden_state_size,
                                     'target': l_target
                                 })

        self.type = type

        self.args = {}
        self.args['out'] = hidden_state_size

        self.n_layers = n_layers
Beispiel #4
0
    idx = np.random.permutation(len(files))
    idx = idx.tolist()

    valid_ids = [files[i] for i in idx[0:10000]]
    test_ids = [files[i] for i in idx[10000:20000]]
    train_ids = [files[i] for i in idx[20000:]]

    data_train = datasets.Qm9(root, train_ids)
    data_valid = datasets.Qm9(root, valid_ids)
    data_test = datasets.Qm9(root, test_ids)

    # d = datasets.utils.get_graph_stats(data_train, 'degrees')
    d = [1, 2, 3, 4]

    ## Define message
    m = MessageFunction('duvenaud')

    ## Parameters for the update function
    # Select one graph
    g_tuple, l = data_train[0]
    g, h_t, e = g_tuple

    m_v = m.forward(h_t[0], h_t[1], e[list(e.keys())[0]])

    in_n = len(m_v)
    out_n = 30

    ## Define Update
    u = UpdateFunction('duvenaud', args={'deg': d, 'in': in_n, 'out': out_n})

    in_n = len(h_t[0])