如何从距离矩阵计算原始向量?

发布于 2024-10-18 03:50:10 字数 391 浏览 3 评论 0原文

我有一个关于向量和矩阵的小问题。

假设向量 V = {v1, v2, ..., vn}。我生成一个 n×n 距离矩阵 M 定义为:

M_ij = | v_i - v_j |使得 i,j 属于 [1, n]。

也就是说,方阵中的每个元素M_ij是V中两个元素的绝对距离。

例如,我有一个向量V = {1,3,3,5},距离矩阵将是 米=[ 0 2 2 4; 2 0 0 2; 2 0 0 2; 4 2 2 0; ]

看起来很简单。现在到了问题所在。给定这样一个矩阵M,如何获得初始V?

谢谢。

根据这个问题的一些答案,似乎答案并不唯一。因此,现在假设所有初始向量已归一化为 0 均值和 1 方差。问题是:给定这样一个对称距离矩阵M,如何确定初始归一化向量?

I have a small question about vector and matrix.

Suppose a vector V = {v1, v2, ..., vn}. I generate a n-by-n distance matrix M defined as:

M_ij = | v_i - v_j | such that i,j belong to [1, n].

That is, each element M_ij in the square matrix is the absolute distance of two elements in V.

For example, I have a vector V = {1, 3, 3, 5}, the distance matrix will be
M=[
0 2 2 4;
2 0 0 2;
2 0 0 2;
4 2 2 0; ]

It seems pretty simple. Now comes to the question. Given such a matrix M, how to obtain the initial V?

Thank you.

Based on some answer for this question, it seems that the answer is not unique. So, now suppose that all the initial vector has been normalized to 0 mean and 1 variance. The question is: Given such a symmetric distance matrix M, how to decide the initial normalized vector?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

病女 2024-10-25 03:50:10

你不能。为了让您了解原因,请考虑以下两种情况:

V1 = {1,2,3}

M1 = [ 0 1 2 ; 1 0 1 ; 2 1 0]

V2 = {3,4,5}

M2 = [ 0 1 2 ; 1 0 1 ; 2 1 0]

如您所见,单个 M 可能是多个 V 的结果。因此,您无法向后映射。

You can't. To give you an idea of why, consider these two cases:

V1 = {1,2,3}

M1 = [ 0 1 2 ; 1 0 1 ; 2 1 0 ]

V2 = {3,4,5}

M2 = [ 0 1 2 ; 1 0 1 ; 2 1 0 ]

As you can see, a single M could be the result of more than one V. Therefore, you can't map backwards.

来日方长 2024-10-25 03:50:10

没有办法唯一地确定答案,因为距离矩阵对于向所有元素添加一个常数以及将所有值乘以 -1 是不变的。但是,假设元素 1 等于 0,并且第一个非零元素为正,您可以找到答案。这是伪代码:

# Assume v[1] is 0
v[1] = 0
# e is value of first non-zero vector element
e = 0
# ei is index of first non-zero vector element
ei = 0
for i = 2...n:
  # if all vector elements have been 0 so far
  if e == 0:
    # get the current distance from element 1 and its index
    # this new element may still be 0
    e = d[1,i]
    ei = i
    v[i] = e
  elseif d[1,i] == d[ei,i] + v[ei]: # v[i] <= v[1]
    # v[i] is to the left of v[1] (assuming v[ei] > v[1])
    v[i] = -d[1,i]
  else:
    # some other case; v[i] is to the right of v[1]
    v[i] = d[1,i]

There is no way to determine the answer uniquely, since the distance matrix is invariant to adding a constant to all elements and to multiplying all the values by -1. Assuming that element 1 is equal to 0, and that the first nonzero element is positive, however, you can find an answer. Here is the pseudocode:

# Assume v[1] is 0
v[1] = 0
# e is value of first non-zero vector element
e = 0
# ei is index of first non-zero vector element
ei = 0
for i = 2...n:
  # if all vector elements have been 0 so far
  if e == 0:
    # get the current distance from element 1 and its index
    # this new element may still be 0
    e = d[1,i]
    ei = i
    v[i] = e
  elseif d[1,i] == d[ei,i] + v[ei]: # v[i] <= v[1]
    # v[i] is to the left of v[1] (assuming v[ei] > v[1])
    v[i] = -d[1,i]
  else:
    # some other case; v[i] is to the right of v[1]
    v[i] = d[1,i]
猫瑾少女 2024-10-25 03:50:10

我认为不可能找到原始向量,但您可以通过获取矩阵的第一行来找到向量的翻译。

如果让 M_ij = | v_i - v_j |然后将所有 v_k 翻译为 k\in [1,n] 你会得到
M_ij = | vi + 1 - v_j + 1 |
= | v_i - v_j |

因此,只需将第一行作为向量并找到一个初始点将向量平移到其中。

更正:

Let v_1 = 0, and let l_k = | v_k | for k\in [2,n] and p_k the parity of v_k

Let p_1 = 1

for(int i = 2; i < n; i++)
   if( | l_i - l_(i+1) | != M_i(i+1) )
      p_(i+1) = - p_i
   else
      p_(i+1) = p_i

按顺序对 k\in [2,n] 中的所有 v_k 执行此操作将显示每个 v_k 相对于其他 v_k 的奇偶性

然后您可以找到具有相同或相反方向更新的原始向量的平移

(对于标准化向量):

  Let d = Sqrt(v_1^2 + v_2^2 + ... + v_n^2)

  Vector = {0, v_1 / d, v_2 / d, ... , v_n / d}
            or
           {0, -v_1 / d, -v_2 / d, ... , -v_n / d}

I don't think it is possible to find the original vector, but you can find a translation of the vector by taking the first row of the matrix.

If you let M_ij = | v_i - v_j | and you translate all v_k for k\in [1,n] you will get
M_ij = | v-i + 1 - v_j + 1 |
= | v_i - v_j |

Hence, just take the first row as the vector and find one initial point to translate the vector to.

Correction:

Let v_1 = 0, and let l_k = | v_k | for k\in [2,n] and p_k the parity of v_k

Let p_1 = 1

for(int i = 2; i < n; i++)
   if( | l_i - l_(i+1) | != M_i(i+1) )
      p_(i+1) = - p_i
   else
      p_(i+1) = p_i

doing this for all v_k for k\in [2,n] in order will show the parity of each v_k in respect to the others

Then you can find a translation of the original vector with the same or opposite direction

Update (For Normalized vector):

  Let d = Sqrt(v_1^2 + v_2^2 + ... + v_n^2)

  Vector = {0, v_1 / d, v_2 / d, ... , v_n / d}
            or
           {0, -v_1 / d, -v_2 / d, ... , -v_n / d}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文