A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.pytorch.org/docs/main/generated/torch.cov.html below:

torch.cov — PyTorch main documentation

Estimates the covariance matrix of the variables given by the input matrix, where rows are the variables and columns are the observations.

A covariance matrix is a square matrix giving the covariance of each pair of variables. The diagonal contains the variance of each variable (covariance of a variable with itself). By definition, if input represents a single variable (Scalar or 1D) then its variance is returned.

The sample covariance of the variables x x x and y y y is given by:

cov ( x , y ) = ∑ i = 1 N ( x i − x ˉ ) ( y i − y ˉ ) max ⁡ ( 0 ,   N   −   δ N ) \text{cov}(x,y) = \frac{\sum^{N}_{i = 1}(x_{i} - \bar{x})(y_{i} - \bar{y})}{\max(0,~N~-~\delta N)} cov(x,y)=max(0, N  δN)i=1N(xixˉ)(yiyˉ)

where x ˉ \bar{x} xˉ and y ˉ \bar{y} yˉ are the simple means of the x x x and y y y respectively, and δ N \delta N δN is the correction.

If fweights and/or aweights are provided, the weighted covariance is calculated, which is given by:

cov w ( x , y ) = ∑ i = 1 N w i ( x i − μ x ∗ ) ( y i − μ y ∗ ) max ⁡ ( 0 ,   ∑ i = 1 N w i   −   ∑ i = 1 N w i a i ∑ i = 1 N w i   δ N ) \text{cov}_w(x,y) = \frac{\sum^{N}_{i = 1}w_i(x_{i} - \mu_x^*)(y_{i} - \mu_y^*)} {\max(0,~\sum^{N}_{i = 1}w_i~-~\frac{\sum^{N}_{i = 1}w_ia_i}{\sum^{N}_{i = 1}w_i}~\delta N)} covw(x,y)=max(0, i=1Nwi  i=1Nwii=1Nwiai δN)i=1Nwi(xiμx)(yiμy)

where w w w denotes fweights or aweights (f and a for brevity) based on whichever is provided, or w = f × a w = f \times a w=f×a if both are provided, and μ x ∗ = ∑ i = 1 N w i x i ∑ i = 1 N w i \mu_x^* = \frac{\sum^{N}_{i = 1}w_ix_{i} }{\sum^{N}_{i = 1}w_i} μx=i=1Nwii=1Nwixi is the weighted mean of the variable. If not provided, f and/or a can be seen as a 1 \mathbb{1} 1 vector of appropriate size.

Parameters

input (Tensor) – A 2D matrix containing multiple variables and observations, or a Scalar or 1D vector representing a single variable.

Keyword Arguments
Returns

(Tensor) The covariance matrix of the variables.

Example:

>>> x = torch.tensor([[0, 2], [1, 1], [2, 0]]).T
>>> x
tensor([[0, 1, 2],
        [2, 1, 0]])
>>> torch.cov(x)
tensor([[ 1., -1.],
        [-1.,  1.]])
>>> torch.cov(x, correction=0)
tensor([[ 0.6667, -0.6667],
        [-0.6667,  0.6667]])
>>> fw = torch.randint(1, 10, (3,))
>>> fw
tensor([1, 6, 9])
>>> aw = torch.rand(3)
>>> aw
tensor([0.4282, 0.0255, 0.4144])
>>> torch.cov(x, fweights=fw, aweights=aw)
tensor([[ 0.4169, -0.4169],
        [-0.4169,  0.4169]])

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4