产生疏远矩阵的n维超立方体 [英] generating distanced matrix for an n-dimensional hypercube

查看:300
本文介绍了产生疏远矩阵的n维超立方体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么算法或生成邻接矩阵为任何尺寸的超立方体的方法是什么?说你的输入为5,将创建一个5维超立方体

is there any algorithm or method of generating the adjacency matrix for a hypercube for any dimension? say your input is 5 it would create a 5-dimensional hypercube

所有我能找到的来源
维基


推荐答案

如果你想生成一个N-D单元超立方体的顶点,你基本上可以做出N值真值表。下面是一些code我用的是:

If you want to generate the vertices of a N-D unit hypercube, you can basically make an N-value truthtable. Here's some code I use for that:

function output = ttable(values)

  output = feval(@(y)feval(@(x)mod(ceil(repmat((1:x(1))', 1, numel(x) - 1) ./ repmat(x(2:end), x(1), 1)) - 1, repmat(fliplr(y), x(1), 1)) + 1, fliplr([1 cumprod(y)])), fliplr(values));
end

和获得5-D超立方体的顶点可以称之为是这样的:

and to get the vertices of a 5-D hypercube you can call it like this:

vertices = ttable(ones(1, 5) * 2) - 1;

在这里,您可以发现,仅由一个位不同的所有顶点,即计算邻接矩阵:

From here you can calculate the adjacency matrix by finding all vertices that differ by only one bit, i.e.:

adj_list = zeros(2^5, 5);
adj_mat = zeros(2^5, 2^5);
for v=1:2^5
  L1_dists = sum(abs(vertices - repmat(vertices(v, :), 2^5, 1)), 2);
  adj_list(v, :) = find(L1_dists == 1);
  adj_mat(v, find(L1_dists == 1)) = 1;
end

这篇关于产生疏远矩阵的n维超立方体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆