Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paddle.linalg.corrcoef的计算结果不对称 #50048

Closed
Liyulingyue opened this issue Jan 28, 2023 · 9 comments
Closed

paddle.linalg.corrcoef的计算结果不对称 #50048

Liyulingyue opened this issue Jan 28, 2023 · 9 comments
Assignees
Labels
good first issue PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭 type/bug-report 报bug

Comments

@Liyulingyue
Copy link
Contributor

bug描述 Describe the Bug

相关系数矩阵不对称。

import paddle 
print(paddle.__version__)

y = list(range(10000))
def acf(y, order):
    inputs = []
    for i in range(order+1):
        inputs.append(y[i:len(y)-(order-i)])
    inputs = paddle.to_tensor(inputs).astype('float32')
    outputs = paddle.linalg.corrcoef(inputs)
    return outputs
x = acf(y,5)

image

其他补充信息 Additional Supplementary Information

No response

@paddle-bot
Copy link

paddle-bot bot commented Jan 28, 2023

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@paddle-bot paddle-bot bot added the PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc label Jan 28, 2023
@pangyoki
Copy link
Contributor

pangyoki commented Jan 29, 2023

你好,我复现了你的问题,这个bug会找相关API负责人( #40690 )修复,谢谢反馈。
另外,我测试只有cpu设备下才会有这个问题,gpu场景下数值应该正常吧?
图片

@paddle-bot paddle-bot bot added status/following-up 跟进中 and removed status/new-issue 新建 labels Jan 30, 2023
@Liyulingyue
Copy link
Contributor Author

你好,我复现了你的问题,这个bug会找相关API负责人( #40690 )修复,谢谢反馈。 另外,我测试只有cpu设备下才会有这个问题,gpu场景下数值应该正常吧? 图片

你好,根据你的截图来看,gpu场景不正常鸭,它只保证了对角线为1,对称不同。

@luotao1
Copy link
Contributor

luotao1 commented Jan 31, 2023

@liqitong-a 可以帮忙看下这个问题么?

@AndPuQing
Copy link
Contributor

AndPuQing commented Jan 31, 2023

numpy 其实也有该问题,输出的矩阵并非严格对称,numpy.corrcoef:

import numpy as np

print(np.__version__) # 1.23.2

xt = np.random.rand(30, 40)

r = np.corrcoef(xt, dtype="float32")
print(np.allclose(r, r.T, rtol=1e-8)) # False

print(np.count_nonzero(r != r.T)) # 300
for i in range(r.shape[0]):
    for j in range(r.shape[1]):
        if r[i][j] != r[j][i]:
            print(r[i][j], r[j][i])

@liqitong-a
Copy link
Contributor

liqitong-a commented Jan 31, 2023

由于是在其他算子的基础上进行运算,所以和其他算子的精度也有关系,使用float64精度会高一些,使用float32cov算子也会有偏差。

import os
import paddle
import numpy as np

os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"

y = list(range(10000))
def acf(y, order):
    inputs = []
    for i in range(order+1):
        inputs.append(y[i:len(y)-(order-i)])

    t1 = np.array(inputs).astype('float32')
    print(np.cov(t1))
    t2 = paddle.to_tensor(inputs).astype("float32")
    print(paddle.linalg.cov(t2))

acf(y,5)

@luotao1
Copy link
Contributor

luotao1 commented Jan 31, 2023

1)使用float64精度会高一些;2)numpy 其实也有该问题,输出的矩阵并非严格对称

@Liyulingyue 看下这个问题是否解决了?

@Liyulingyue
Copy link
Contributor Author

1)使用float64精度会高一些;2)numpy 其实也有该问题,输出的矩阵并非严格对称

@Liyulingyue 看下这个问题是否解决了?

got it

但是我有个小问题,这种情况需要特意对齐吗?毕竟按照计算逻辑,对角线默认为1,对称元素应当相同?

@Liyulingyue
Copy link
Contributor Author

64可以对齐

@paddle-bot paddle-bot bot added status/close 已关闭 and removed status/following-up 跟进中 labels Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭 type/bug-report 报bug
Projects
None yet
Development

No branches or pull requests

5 participants