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

【PaddlePaddle Hackathon 2】3、为 Paddle 新增 corrcoef(皮尔逊积矩相关系数) #4316

Merged
merged 12 commits into from May 9, 2022
43 changes: 43 additions & 0 deletions docs/api/paddle/linalg/corrcoef_cn.rst
@@ -0,0 +1,43 @@
.. _cn_api_linalg_corrcoef:

corrcoef
-------------------------------

.. py:function:: paddle.linalg.corrcoef(x, rowvar=True, ddof=False, name=None)


给定输入Tensor,计算输入Tensor的皮尔逊积矩相关系数矩阵。
细节请参考cov文档. 皮尔逊积矩相关系数 `R`和 协方差矩阵`C`的关系如下:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 文档需要给出链接
  • 注意中英文标点符号不要混用


.. math:: R_{ij} = \\frac{ C_{ij} } { \\sqrt{ C_{ii} * C_{jj} } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

显示还是不对,把 \\ 改成 \ ,另外可以自己查看预览链接核对,每次触发CI都会生成新的官网预览,文档参考

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

显示还是不对,把 \\ 改成 \ ,另外可以自己查看预览链接核对,每次触发CI都会生成新的官网预览,文档参考

好的好的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

显示还是不对,把 \\ 改成 \ ,另外可以自己查看预览链接核对,每次触发CI都会生成新的官网预览,文档参考

Done!


`R`的值在-1到1之间.

参数:
:::::::::
- **x** (Tensor) - 一个N(N<=2)维矩阵,包含多个变量。默认矩阵的每行是一个观测变量,由参数rowvar设置。
- **rowvar** (bool, 可选) - 若是True,则每行作为一个观测变量;若是False,则每列作为一个观测变量。默认True。
- **ddof** (bool, 可选) - 在计算中不起作用,不需要。默认False。
- **name** (str, 可选) - 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 括号里的标点符号使用中文,
  • 参数后面不加:


返回:
:::::::::
- Tensor, 输入x的皮尔逊积矩相关系数矩阵。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 注意标点符号
  • 返回 后面不加:


代码示例:
::::::::::

.. code-block:: python

import paddle

xt = paddle.rand((3,4))
paddle.linalg.corrcoef(xt)

'''
Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[ 1. , -0.73702252, 0.66228950],
[-0.73702258, 1. , -0.77104872],
[ 0.66228974, -0.77104825, 1. ]])
'''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 代码示例 后面不加:
  • 代码部分使用copy-from的方式,文档参考