Beispiel #1
0
def std(t):
    """
    Computes the standard deviation of a :class:`Tensor`.

    :param t: a :class:`Tensor`

    :return: a scalar :math:`\ge 0`
    """

    return torch.sqrt(tn.var(t))
Beispiel #2
0
def normalized_moment(t, k, eps=1e-12):
    """
    Compute a normalized central moment :math:`\\mathbb{E}[(t - \\mathbb{E}[t])^k] / \\sigma^k'.

    :param t: input :class:`Tensor`
    :param k: the desired moment order (integer :math:`\ge 1`)
    :param eps: relative error for rounding (default is 1e-12)

    :return: the :math:`k`-th order normalized moment of `t`
    """

    return raw_moment(t - tn.mean(t), k=k,
                      eps=eps) / tn.var(t)**(k / 2.) / t.numel()
Beispiel #3
0
def normalized_moment(t, k, marginals=None, eps=1e-12, algorithm='eig'):
    """
    Compute a normalized central moment :math:`\\mathbb{E}[(t - \\mathbb{E}[t])^k] / \\sigma^k'.

    :param t: input :class:`Tensor`
    :param k: the desired moment order (integer :math:`\ge 1`)
    :param marginals: an optional list of vectors
    :param eps: relative error for rounding (default is 1e-12)

    :return: the :math:`k`-th order normalized moment of `t`
    """

    return raw_moment(t - tn.mean(t, marginals=marginals),
                      k=k,
                      marginals=marginals,
                      eps=eps,
                      algorithm=algorithm) / tn.var(t, marginals=marginals)**(
                          k / 2.)  # / t.numel()
Beispiel #4
0
    def var(self, **kwargs):
        """
        See :func:`metrics.var()`.
        """

        return tn.var(self, **kwargs)
Beispiel #5
0
 def check():
     x = t.torch()
     assert tn.relative_error(tn.mean(t), torch.mean(x)) <= 1e-3
     assert tn.relative_error(tn.var(t), torch.var(x)) <= 1e-3
     assert tn.relative_error(tn.norm(t), torch.norm(x)) <= 1e-3