Esempio n. 1
0
def test_to_disjoint():
    # TODO test e_list
    x, i = to_disjoint(x_list, None)
    a, i = to_disjoint(None, a_list)
    x, a, i = to_disjoint(x_list, a_list)
    assert x.ndim == 2
    assert a.ndim == 2
    assert x.shape[0] == a.shape[0] == a.shape[1]
Esempio n. 2
0
    def collate(self, batch):
        packed = self.pack(batch, return_dict=True)
        y = None
        if "y" in self.dataset.signature:
            y = packed.pop("y_list")
            if self.node_level:
                if len(np.shape(y[0])) == 1:
                    y = [y_[:, None] for y_ in y]
                y = np.vstack(y)
            else:
                if len(np.shape(y[0])) == 0:
                    y = [np.array([y_]) for y_ in y]
                y = np.array(y)

        output = to_disjoint(**packed)

        # Sparse matrices to SparseTensors
        output = list(output)
        for i in range(len(output)):
            if sp.issparse(output[i]):
                output[i] = sp_matrix_to_sp_tensor(output[i])
        output = tuple(output)

        if y is None:
            return output
        else:
            return output, y
Esempio n. 3
0
def test_modes_ops():
    ns = [10, 5, 8]
    x_list = [np.random.randn(n, 3) for n in ns]
    a_list = [sp.csr_matrix(np.ones((n, n))) for n in ns]

    x, a, i = to_disjoint(x_list, a_list)
    a = sp_matrix_to_sp_tensor(a)

    expected_x = np.zeros((len(ns), max(ns), 3))
    for i_, n in enumerate(ns):
        expected_x[i_, :n] = x_list[i_]

    expected_a = np.zeros((len(ns), max(ns), max(ns)))
    for i_, n in enumerate(ns):
        expected_a[i_, :n, :n] = a_list[i_].A

    # Disjoint signal to batch
    result = ops.disjoint_signal_to_batch(x, i).numpy()

    assert expected_x.shape == result.shape
    assert np.allclose(expected_x, result, atol=tol)

    # Disjoint adjacency to batch
    result = ops.disjoint_adjacency_to_batch(a, i).numpy()

    assert expected_a.shape == result.shape
    assert np.allclose(expected_a, result, atol=tol)
Esempio n. 4
0
    def collate(self, batch):
        packed = self.pack(batch)

        y = packed.pop("y_list", None)
        if y is not None:
            y = collate_labels_disjoint(y, node_level=self.node_level)

        output = to_disjoint(**packed)
        output = sp_matrices_to_sp_tensors(output)

        if len(output) == 1:
            output = output[0]

        if y is None:
            return output
        else:
            return output, y
Esempio n. 5
0
    def collate(self, batch):
        packed = self.pack(batch, return_dict=True)
        y = None
        if "y" in self.dataset.signature:
            y = packed.pop("y_list")
            y = np.vstack(y) if self.node_level else np.array(y)

        output = to_disjoint(**packed)
        output = list(output)
        for i in range(len(output)):
            if sp.issparse(output[i]):
                output[i] = sp_matrix_to_sp_tensor(output[i])
        output = tuple(output)

        if y is None:
            return output
        else:
            return output, y
Esempio n. 6
0
    def collate(self, batch):
        packed = self.pack(batch)

        y = packed.pop("y_list", None)
        if y is not None:
            y = collate_labels_disjoint(y, node_level=True)

        output = to_disjoint(**packed)
        output = output[:-1]  # Discard batch index
        output = sp_matrices_to_sp_tensors(output)

        if len(output) == 1:
            output = output[0]

        output = (output, )
        if y is not None:
            output += (y, )
        if self.sample_weights is not None:
            output += (self.sample_weights, )

        if len(output) == 1:
            output = output[0]  # Again, in case there are no targets and no SW

        return output