Пример #1
0
def eye(m, n=None):
    n = n or m
    array = [0] * m * n
    for i in range(m):
        if i >= n: break
        array[i * n + i] = 1
    return Tensor(array, shape=(m, n))
Пример #2
0
 def chi2_uniform2d_distance(table, correct):
     row_sums = Tensor.sum(table, axis=1)
     col_sums = Tensor.sum(table, axis=0)
     all_sums = Tensor.sum(row_sums)
     expected = zeros_like(table)
     _correct = False
     if (table.shape[0] - 1) * (table.shape[1] - 1) == 1:
         _correct = True
     for i in range(table.shape[0]):
         for j in range(table.shape[1]):
             expected_ij = row_sums[i] * col_sums[j] / all_sums
             expected[i, j] = expected_ij
             if expected_ij < 10:
                 _correct = correct and True
     if _correct:
         return Tensor.sum((abs(table - expected) - 0.5)**2 / expected)
     return Tensor.sum((table - expected)**2 / expected)
Пример #3
0
def t_test(x, y=None, mu=None):
    x = tensor(x)
    if y is not None:
        y = tensor(y)

    if y is None and mu is None:
        raise TypeError('Count of arguments must be 2, but only 1')
    t = 0
    df = 0
    if y is not None:
        n1 = len(x)
        n2 = len(y)
        if n1 <= 1 or n2 <= 1:
            raise ValueError

        mean1 = Tensor.mean(x)
        mean2 = Tensor.mean(y)

        var1 = Tensor.sum((x - mean1)**2) / (n1 - 1)
        var2 = Tensor.sum((y - mean2)**2) / (n2 - 1)

        t = (mean1 - mean2) / _math.sqrt(var1 / n1 + var2 / n2)
        df = (var1 / n1 + var2 / n2)**2 / (var1**2 / (n1**2 *
                                                      (n1 - 1)) + var2**2 /
                                           (n2**2 * (n2 - 1)))
    if mu is not None:
        n = len(x)
        mean = Tensor.mean(x)
        sd = (Tensor.sum((x - mean)**2) / (n - 1))**0.5

        t = (mean - mu) / (sd / _math.sqrt(n))
        df = n - 1
    p = betainc(df / (t**2 + df), df / 2, 1 / 2, regularized=True)
    return t, df, p
Пример #4
0
def tanh(x):
    return Tensor.map(x, _math.tanh)
Пример #5
0
def log2(x):
    return Tensor.map(x, _math.log2)
Пример #6
0
def expm1(x):
    return Tensor.map(x, _math.expm1)
Пример #7
0
def remainder(x, y):
    return Tensor.map2(x, y)
Пример #8
0
def ldexp(x, i):
    return Tensor.map2(x, i, _math.ldexp)
Пример #9
0
def isinf(x):
    return Tensor.map(x, _math.isinf)
Пример #10
0
def outer(x1, x2):
    return Tensor.map_outer(x1, x2, _operator.mul)
Пример #11
0
def factorial(x):
    return Tensor.map(x, _math.factorial)
Пример #12
0
def round(x, ndigits=None):
    return Tensor.map2(x, ndigits, _builtins.round)
Пример #13
0
def fabs(x):
    return Tensor.map(x, _math.fabs)
Пример #14
0
def lgamma(x):
    return Tensor.map(x, _math.lgamma)
Пример #15
0
def gamma(x):
    return Tensor.map(x, _math.gamma)
Пример #16
0
def erfc(x):
    return Tensor.map(x, _math.erfc)
Пример #17
0
def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
    _isclose = lambda a, b: _math.isclose(a, b, rel_tol=1e-09, abs_tol=0.0)
    return Tensor.map2(a, b, _isclose)
Пример #18
0
def floor(x):
    return Tensor.map(x, _math.floor)
Пример #19
0
def isfinite(x):
    return Tensor.map(x, _math.isfinite)
Пример #20
0
def fmod(x, y):
    return Tensor.map2(x, y, _math.fmod)
Пример #21
0
def isnan(x):
    return Tensor.map(x, _math.isnan)
Пример #22
0
 def chi2_uniform_distance(table):
     expected = Tensor.sum(table) / len(table)
     cntrd = table - expected
     return Tensor.sum(cntrd**2) / expected
Пример #23
0
def modf(x):
    return Tensor.map(x, _math.modf)
Пример #24
0
def frexp(x):
    return Tensor.map(x, _math.frexp)
Пример #25
0
def trunc(x):
    return Tensor.map(x, _math.trunc)
Пример #26
0
def gcd(a, b):
    return Tensor.map2(a, b, _math.gcd)
Пример #27
0
def log(x, base):
    return Tensor.map2(x, base, _math.log)
Пример #28
0
def norm(x):
    x = tensor(x)
    return sqrt((Tensor.sum(square(x))))
Пример #29
0
def log10(x):
    return Tensor.map(x, _math.log10)
Пример #30
0
def sinh(x):
    return Tensor.map(x, _math.sinh)