图表

torchhd.graph(input: VSATensor, *, directed=False) VSATensor[来源]

从节点超向量对生成的图。

如果 directed=False 这将计算:

\[\bigoplus_{i = 0}^{n - 1} V_{0,i} \otimes V_{1,i}\]

如果 directed=True 这将计算:

\[\bigoplus_{i = 0}^{n - 1} V_{0,i} \otimes \Pi(V_{1,i})\]
Parameters:
  • 输入 (VSATensor) – 包含共享边的节点超向量对的张量。

  • directed (bool, 可选) – 指定图是否为有向图。默认值:False

Shapes:
  • 输入: \((*, 2, n, d)\)

  • 输出: \((*, d)\)

示例:

>>> x = torchhd.random(4, 6)
>>> x
tensor([[-1., -1.,  1.,  1.,  1., -1.],
        [-1., -1., -1.,  1.,  1.,  1.],
        [-1., -1.,  1., -1.,  1., -1.],
        [ 1., -1., -1., -1.,  1., -1.]])
>>> edges = torch.tensor([[0, 0, 1, 2], [1, 2, 2, 3]])
>>> edges_hv = torch.index_select(x, 0, edges.ravel()).view(2, 4, 6)
>>> edges_hv
tensor([[[-1., -1.,  1.,  1.,  1., -1.],
        [-1., -1.,  1.,  1.,  1., -1.],
        [-1., -1., -1.,  1.,  1.,  1.],
        [-1., -1.,  1., -1.,  1., -1.]],

        [[-1., -1., -1.,  1.,  1.,  1.],
        [-1., -1.,  1., -1.,  1., -1.],
        [-1., -1.,  1., -1.,  1., -1.],
        [ 1., -1., -1., -1.,  1., -1.]]])
>>> torchhd.graph(edges_hv)
tensor([ 2.,  4., -2.,  0.,  4.,  0.])