提交 7a1e9ec4 authored 作者: Joseph Paul Cohen's avatar Joseph Paul Cohen

fix test case and add docs

上级 59018422
...@@ -2169,9 +2169,26 @@ square = sqr ...@@ -2169,9 +2169,26 @@ square = sqr
def cov(a): def cov(a):
X -= X.mean(axis=1, keepdims=1) """Calculate the covariance matrix.
c = X.dot(X.T) Covariance indicates the level to which two variables vary together.
return c/(X.shape[1]-1) If we examine N-dimensional samples, :math:`X = [x_1, x_2, ... x_N]^T`,
then the covariance matrix element :math:`C_{ij}` is the covariance of
:math:`x_i` and :math:`x_j`. The element :math:`C_{ii}` is the variance
of :math:`x_i`.
----------
a : array_like
A 2-D array containing multiple variables and observations.
Each row of `a` represents a variable, and each column is
observations of all those variables.
Returns
-------
out : The covariance matrix of the variables.
"""
a -= a.mean(axis=1, keepdims=1)
c = a.dot(a.T)
return c/(a.shape[1]-1)
@_scal_elemwise @_scal_elemwise
def sqrt(a): def sqrt(a):
......
...@@ -8173,7 +8173,7 @@ def test_norm(): ...@@ -8173,7 +8173,7 @@ def test_norm():
def test_cov(): def test_cov():
x = theano.tensor.matrix('x') x = theano.tensor.matrix('x')
c = T.cov(x) c = theano.tensor.cov(x)
f = theano.function([x], c) f = theano.function([x], c)
data = np.asarray(np.random.rand(3,5),dtype=config.floatX) data = np.asarray(np.random.rand(3,5),dtype=config.floatX)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论