Ejemplo n.º 1
0
def getCombinationsOperator(n, r):
    if r > n:
        raise ValueError(
            'number of elements {0} cannot exceed the size of the set {1}'.
            format(r, n))

    return fdiv(fac(n), fmul(fac(fsub(n, r)), fac(r)))
Ejemplo n.º 2
0
def compound_interest_fnc_mpmath_with_infinite_series_definition_of_e(
        initial_investment, percent1, percent2, percent3, percent4, percent5,
        compounding_frequency):
    #converting the float values to numbers that have 100 decimal places
    initial_investment = mpmath.mpmathify(initial_investment)
    percent1 = mpmath.mpmathify(percent1)
    percent2 = mpmath.mpmathify(percent2)
    percent3 = mpmath.mpmathify(percent3)
    percent4 = mpmath.mpmathify(percent4)
    percent5 = mpmath.mpmathify(percent5)

    #   infinite series definition:  e^x = inf(x^k/K!) taken from wikipedia
    principal = initial_investment
    x = percent1 * compounding_frequency
    principal = mpmath.nsum(lambda n: principal * ((x**n) / mpmath.fac(n)),
                            [0, mpmath.inf])
    x = percent2 * compounding_frequency
    principal = mpmath.nsum(lambda n: principal * ((x**n) / mpmath.fac(n)),
                            [0, mpmath.inf])
    x = percent3 * compounding_frequency
    principal = mpmath.nsum(lambda n: principal * ((x**n) / mpmath.fac(n)),
                            [0, mpmath.inf])
    x = percent4 * compounding_frequency
    principal = mpmath.nsum(lambda n: principal * ((x**n) / mpmath.fac(n)),
                            [0, mpmath.inf])
    x = percent5 * compounding_frequency
    principal = mpmath.nsum(lambda n: principal * ((x**n) / mpmath.fac(n)),
                            [0, mpmath.inf])
    return principal
Ejemplo n.º 3
0
def getMultinomialOperator(n):
    numerator = fac(fsum(n))

    denominator = 1

    for arg in n:
        denominator = fmul(denominator, fac(arg))

    return fdiv(numerator, denominator)
Ejemplo n.º 4
0
def getMultinomial( args ):
    numerator = fac( fsum( args ) )

    denominator = 1

    for arg in args:
        denominator = fmul( denominator, fac( arg ) )

    return fdiv( numerator, denominator )
Ejemplo n.º 5
0
def de(n, k):
    result = 0

    j = n
    while j >= k:
        suma = (4**j) * (math.fac(n + j - 1) /
                         (math.fac(n - j) * math.fac(2 * j)))
        result += suma
        j -= 1
    result *= n

    return result
Ejemplo n.º 6
0
def getNthAlternatingFactorial( n ):
    result = 0

    negative = False

    for i in arange( real( n ), 0, -1 ):
        if negative:
            result = fadd( result, fneg( fac( i ) ) )
            negative = False
        else:
            result = fadd( result, fac( i ) )
            negative = True

    return result
def test_Wigner_coefficient():
    import mpmath
    mpmath.mp.dps = 4 * sf.ell_max
    i = 0
    for twoell in range(2*sf.ell_max + 1):
        for twomp in range(-twoell, twoell + 1, 2):
            for twom in range(-twoell, twoell + 1, 2):
                tworho_min = max(0, twomp - twom)
                a = sf._Wigner_coefficient(twoell, twomp, twom)
                b = float(mpmath.sqrt(mpmath.fac((twoell + twom)//2) * mpmath.fac((twoell - twom)//2)
                                      / (mpmath.fac((twoell + twomp)//2) * mpmath.fac((twoell - twomp)//2)))
                          * mpmath.binomial((twoell + twomp)//2, tworho_min//2)
                          * mpmath.binomial((twoell - twomp)//2, (twoell - twom - tworho_min)//2))
                assert np.allclose(a, b), (twoell, twomp, twom, i, sf._Wigner_index(twoell, twomp, twom))
                i += 1
Ejemplo n.º 8
0
def make_factorial_vals():
    from mpmath import fac

    n = range(150)
    fac = [fac(val) for val in n]

    return make_special_vals('factorial_vals', ('n', n), ('fac', fac))
Ejemplo n.º 9
0
def make_factorial_vals():
    from mpmath import fac

    n = list(range(150))
    fac = [fac(val) for val in n]

    return make_special_vals('factorial_vals', ('n', n), ('fac', fac))
Ejemplo n.º 10
0
    def Taylor_polynomial(f, a, n):
        """
        A taylor polynomial off of the series equation
        sum_{n=0}^\inf f^(n)(a)/n! * (x-a)^n

        takes: f,a,n
        f is some differentiable function
        a is some real number
        n is some positive integer
        """
        x = Symbol('x')

        # make some derivatives first, since f^(n) is recursive
        derivative = []
        derivative.append(f)
        index = 0
        while index <= n:
            derivative.append(str(diff(derivative[index], x)))
            index += 1
        #print(derivative) #debug

        taylor = ''
        index = 0
        while index <= n:
            taylor += str((lambda x: eval(derivative[index]))(a)) + '/' + str(
                fac(index)) + ' * ' + str((x - a)**index) + ' + '
            index += 1
        taylor = str(eval(taylor[:-3]))

        return taylor
Ejemplo n.º 11
0
def swaL(spin:int,m_ang:int,l_ang:int,x:float)->mp.mpf:
   al= mp.mpf(abs(m_ang-spin))
   be= mp.mpf(abs(m_ang+spin))
   assert((al+be)%2==0)
   n= mp.mpf(l_ang - (al+be)/2)

   if n<0:
      return mp.mpf(0)

   norm= mp.sqrt(
       (2*n+al+be+1)*mp.power(2,-al-be-1)
   *	mp.fdiv(mp.fac(n+al+be),mp.fac(n+al))
   *	mp.fdiv(mp.fac(n)      ,mp.fac(n+be))
   )
   norm*= mp.power(-1,max(m_ang,-spin))

   return norm*mp.power(1-x,al/2.)*mp.power(1+x,be/2.)*mp.jacobi(n,al,be,x)
Ejemplo n.º 12
0
def o_function(l, k, r):
    res = mpmath.hyp1f1(-1j / k + l, 2 * l + 2, -2 * 1j * k * r)
    res *= (1. / (2 * l + 1)) * (k * r)**l
    res *= mpmath.gamma(1 + 1j / k)
    res *= mpmath.rf(-1j / k, l)
    res *= (-2j)**l / mpmath.fac(2 * l)
    res *= mpmath.exp(mpmath.pi / (2 * k))
    return res
Ejemplo n.º 13
0
def getNthPolytopeNumber( n, d ):
    result = real_int( n )
    m = n + 1

    for i in arange( 1, d - 1 ):
        result = fmul( result, m )
        m += 1

    return fdiv( result, fac( d - 1 ) )
Ejemplo n.º 14
0
def getNthPolytopeNumberOperator(n, d):
    result = n
    m = fadd(n, 1)

    for _ in arange(1, d):
        result = fmul(result, m)
        m = fadd(m, 1)

    return fdiv(result, fac(d))
Ejemplo n.º 15
0
def getNthMenageNumber( n ):
    if n < 0:
        raise ValueError( '\'menage\' requires a non-negative argument' )
    elif n in [ 1, 2 ]:
        return 0
    elif n in [ 0, 3 ]:
        return 1
    else:
        return nsum( lambda k: fdiv( fprod( [ power( -1, k ), fmul( 2, n ), binomial( fsub( fmul( 2, n ), k ), k ),
                                            fac( fsub( n, k ) ) ] ), fsub( fmul( 2, n ), k ) ), [ 0, n ] )
    def rate(partition):

        b, k_vec, s = computeSignature(partition)
        partition_multiset = re.partitionToMultiset(partition)

        mergerRate = mergerRatesCoalescent(b, k_vec, s)
        factorSizes = np.prod(map(mp.fac, partition))
        factorCounts = np.prod(map(mp.fac, partition_multiset))

#        print factorSizes, factorCounts, mergerRate

        return (mp.fac(n) / factorSizes*factorCounts ) * mergerRate
Ejemplo n.º 17
0
def mp_wright_bessel(a, b, x, dps=50, maxterms=2000):
    """Compute Wright's generalized Bessel function as Series with mpmath.
    """
    with mp.workdps(dps):
        a, b, x = mp.mpf(a), mp.mpf(b), mp.mpf(x)
        res = mp.nsum(
            lambda k: x**k / mp.fac(k) * rgamma_cached(a * k + b, dps=dps),
            [0, mp.inf],
            tol=dps,
            method='s',
            steps=[maxterms])
        return mpf2float(res)
Ejemplo n.º 18
0
def test_Wigner_coefficient():
    import mpmath
    mpmath.mp.dps = 4 * sf.ell_max
    i = 0
    for twoell in range(2 * sf.ell_max + 1):
        for twomp in range(-twoell, twoell + 1, 2):
            for twom in range(-twoell, twoell + 1, 2):
                tworho_min = max(0, twomp - twom)
                a = sf._Wigner_coefficient(twoell, twomp, twom)
                b = float(
                    mpmath.sqrt(
                        mpmath.fac((twoell + twom) // 2) * mpmath.fac(
                            (twoell - twom) // 2) /
                        (mpmath.fac((twoell + twomp) // 2) * mpmath.fac(
                            (twoell - twomp) // 2))) * mpmath.binomial(
                                (twoell + twomp) // 2, tworho_min // 2) *
                    mpmath.binomial((twoell - twomp) // 2,
                                    (twoell - twom - tworho_min) // 2))
                assert np.allclose(a,
                                   b), (twoell, twomp, twom, i,
                                        sf._Wigner_index(twoell, twomp, twom))
                i += 1
Ejemplo n.º 19
0
    def group_order(self):
        """
        This method returns the order of the Weyl group.
        For types A, B, C, D, and E the order depends on
        the rank of the Lie algebra.  For types F and G,
        the order is fixed.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> c = WeylGroup("D4")
        >>> c.group_order()
        192.0
        """
        n = self.cartan_type.rank()
        if self.cartan_type.series == "A":
            return fac(n + 1)

        if self.cartan_type.series == "B" or self.cartan_type.series == "C":
            return fac(n) * (2 ** n)

        if self.cartan_type.series == "D":
            return fac(n) * (2 ** (n - 1))

        if self.cartan_type.series == "E":
            if n == 6:
                return 51840
            if n == 7:
                return 2903040
            if n == 8:
                return 696729600
        if self.cartan_type.series == "F":
            return 1152

        if self.cartan_type.series == "G":
            return 12
Ejemplo n.º 20
0
    def group_order(self):
        """
        This method returns the order of the Weyl group.
        For types A, B, C, D, and E the order depends on
        the rank of the Lie algebra.  For types F and G,
        the order is fixed.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> c = WeylGroup("D4")
        >>> c.group_order()
        192.0
        """
        n = self.cartan_type.rank()
        if self.cartan_type.series == "A":
            return fac(n+1)

        if self.cartan_type.series == "B" or self.cartan_type.series ==  "C":
            return fac(n)*(2**n)

        if self.cartan_type.series == "D":
            return fac(n)*(2**(n-1))

        if self.cartan_type.series == "E":
            if n == 6:
                return 51840
            if n == 7:
                return 2903040
            if n == 8:
                return 696729600
        if self.cartan_type.series == "F":
            return 1152

        if self.cartan_type.series == "G":
            return 12
Ejemplo n.º 21
0
def cramerVonMises(x, y):

    try:
        x = sorted(x)
        y = sorted(y)

        pool = x + y

        ps, pr = _sortRank(pool)

        rx = array([pr[ind] for ind in [ps.index(element) for element in x]])
        ry = array([pr[ind] for ind in [ps.index(element) for element in y]])

        n = len(x)
        m = len(y)

        i = array(range(1, n + 1))
        j = array(range(1, m + 1))

        u = n * sum(power((rx - i), 2)) + m * sum(power((ry - j), 2))

        t = u / (n * m * (n + m)) - (4 * n * m - 1) / (6 * (n + m))
        Tmu = 1 / 6 + 1 / (6 * (n + m))
        Tvar = 1 / 45 * ((m + n + 1) / power(
            (m + n), 2)) * (4 * m * n * (m + n) - 3 *
                            (power(m, 2) + power(n, 2)) - 2 * m * n) / (4 * m *
                                                                        n)
        t = (t - Tmu) / power(45 * Tvar, 0.5) + 1 / 6

        if t < 0:
            return -1
        elif t <= 12:
            a = 1 - mp.nsum(
                lambda x:
                (mp.gamma(x + 0.5) /
                 (mp.gamma(0.5) * mp.fac(x))) * mp.power(4 * x + 1, 0.5) * mp.
                exp(-mp.power(4 * x + 1, 2) /
                    (16 * t)) * mp.besselk(0.25,
                                           mp.power(4 * x + 1, 2) / (16 * t)),
                [0, 100]) / (mp.pi * mp.sqrt(t))
            return float(mp.nstr(a, 3))
        else:
            return 0
    except Exception as e:
        print e
        return -1
Ejemplo n.º 22
0
def getNthMenageNumber(n):
    '''https://oeis.org/A000179'''
    if n == 1:
        return -1

    if n == 2:
        return 0

    if n in [0, 3]:
        return 1

    return nsum(
        lambda k: fdiv(
            fprod([
                power(-1, k),
                fmul(2, n),
                binomial(fsub(fmul(2, n), k), k),
                fac(fsub(n, k))
            ]), fsub(fmul(2, n), k)), [0, n])
Ejemplo n.º 23
0
def cart_to_RSH_coeffs(l):
    """
    Generates a coefficients [ coef, x power, y power, z power ] for each component of
    a regular solid harmonic (in terms of raw Cartesians) with angular momentum l.

    See eq. 23 of ACS, F. C. Pickard, H. F. Schaefer and B. R. Brooks, JCP, 140, 184101 (2014)

    Returns coeffs with order 0, +1, -1, +2, -2, ...
    """

    terms = []
    for m in range(l + 1):
        thisterm = {}
        # p1 = mpmath.sqrt(mpmath.fac(l - m / mpmath.fac(l + m))) * (mpmath.fac(m) / (2**l))
        p1 = mpmath.sqrt((mpmath.fac(l - m)) / (mpmath.fac(l + m))) * ((mpmath.fac(m)) / (2**l))
        if m:
            p1 *= mpmath.sqrt(2.0)
        # Loop over cartesian components
        for lz in range(l + 1):
            for ly in range(l - lz + 1):
                lx = l - ly - lz
                xyz = lx, ly, lz
                j = int((lx + ly - m) / 2)
                if ((lx + ly - m) % 2 == 1 or j < 0):
                    continue
                p2 = mpmath.mpf(0)
                for i in range(int((l - m) / 2) + 1):
                    if i >= j:
                        p2 += (-1)**i * mpmath.fac(2 * l - 2 * i) / (
                            mpmath.fac(l - i) * mpmath.fac(i - j) * mpmath.fac(l - m - 2 * i))
                p3 = mpmath.mpf(0)
                for k in range(j + 1):
                    if j >= k and lx >= 2 * k and m + 2 * k >= lx:
                        p3 += (-1)**k / (
                            mpmath.fac(j - k) * mpmath.fac(k) * mpmath.fac(lx - 2 * k) * mpmath.fac(m - lx + 2 * k))
                p = p1 * p2 * p3
                # print(p)
                if xyz not in thisterm:
                    thisterm[xyz] = [mpmath.mpf(0.0), mpmath.mpf(0.0)]

                if (m - lx) % 2:
                    # imaginary
                    sign = mpmath.mpf(-1.0)**mpmath.mpf((m - lx - 1) / 2.0)
                    thisterm[xyz][1] += sign * p
                else:
                    # real
                    sign = mpmath.mpf(-1.0)**mpmath.mpf((m - lx) / 2.0)
                    thisterm[xyz][0] += sign * p

        tmp_R = []
        tmp_I = []
        for k, v in thisterm.items():
            # print(k, float(v[0]), float(v[1]))
            if abs(v[0]) > 0:
                tmp_R.append((k, v[0]))
            if abs(v[1]) > 0:
                tmp_I.append((k, v[1]))
        # print(len(tmp_R), len(tmp_I))
        # print('------')

        if m == 0:
            name_R = "R_%d%d" % (l, m)
            terms.append(tmp_R)
        else:
            name_R = "R_%d%dc" % (l, m)
            name_I = "R_%d%ds" % (l, m)
            terms.append(tmp_R)
            terms.append(tmp_I)
            # terms[name_R] = tmp_R
            # terms[name_I] = tmp_I

        # for k, v in terms.items():
        #     print(k, v)

    return terms
Ejemplo n.º 24
0
def getPermutations( n, r ):
    if ( real( r ) > real( n ) ):
        raise ValueError( 'number of elements {0} cannot exceed the size of the set {1}'.format( r, n ) )

    return fdiv( fac( n ), fac( fsub( n, r ) ) )
Ejemplo n.º 25
0
 def eval(self, z):
     return mpmath.fac(z)
Ejemplo n.º 26
0
def coeff(n):
    from mpmath import mp, mpf, fac
    mp.dps = 80
    return (-1)**n / (mpf(2 * n + 1) * fac(mpf(2 * n + 1)))
Ejemplo n.º 27
0
def getLahNumber( n, k ):
    return fmul( power( -1, n ), fdiv( fmul( binomial( real( n ), real( k ) ), fac( fsub( n, 1 ) ) ), fac( fsub( k, 1 ) ) ) )
Ejemplo n.º 28
0
def getArrangements( n ):
    return floor( fmul( fac( n ), e ) )
Ejemplo n.º 29
0
 def fac_ratio(m, n):
     return fac(m) / fac(n)
        _ladder_operator_coefficients[i] = mpmath.sqrt((twoell * (twoell + 2) - twom * (twom + 2))/4)
        i += 1
print(i, _ladder_operator_coefficients.shape)
np.save('ladder_operator_coefficients', _ladder_operator_coefficients)

# _Wigner_coefficients = np.empty(((4 * ell_max ** 3 + 12 * ell_max ** 2 + 11 * ell_max + 3) // 3,), dtype=float)
# i = 0
# for ell in range(ell_max + 1):
#     for mp in range(-ell, ell + 1):
#         for m in range(-ell, ell + 1):
#             rho_min = max(0, mp - m)
#             _Wigner_coefficients[i] = float(mpmath.sqrt(mpmath.fac(ell + m) * mpmath.fac(ell - m)
#                                                         / (mpmath.fac(ell + mp) * mpmath.fac(ell - mp)))
#                                             * mpmath.binomial(ell + mp, rho_min)
#                                             * mpmath.binomial(ell - mp, ell - m - rho_min))
#             i += 1

_Wigner_coefficients = np.empty(((8 * ell_max ** 3 + 18 * ell_max ** 2 + 13 * ell_max + 3) // 3,), dtype=float)
i = 0
for twoell in range(0, 2*ell_max + 1):
    for twomp in range(-twoell, twoell + 1, 2):
        for twom in range(-twoell, twoell + 1, 2):
            tworho_min = max(0, twomp - twom)
            _Wigner_coefficients[i] = float(mpmath.sqrt(mpmath.fac((twoell + twom)//2) * mpmath.fac((twoell - twom)//2)
                                                        / (mpmath.fac((twoell + twomp)//2) * mpmath.fac((twoell - twomp)//2)))
                                            * mpmath.binomial((twoell + twomp)//2, tworho_min//2)
                                            * mpmath.binomial((twoell - twomp)//2, (twoell - twom - tworho_min)//2))
            i += 1
print(i, _Wigner_coefficients.shape)
np.save('Wigner_coefficients', _Wigner_coefficients)
# for ell in range(ell_max + 1):
#     for mp in range(-ell, ell + 1):
#         for m in range(-ell, ell + 1):
#             rho_min = max(0, mp - m)
#             _Wigner_coefficients[i] = float(mpmath.sqrt(mpmath.fac(ell + m) * mpmath.fac(ell - m)
#                                                         / (mpmath.fac(ell + mp) * mpmath.fac(ell - mp)))
#                                             * mpmath.binomial(ell + mp, rho_min)
#                                             * mpmath.binomial(ell - mp, ell - m - rho_min))
#             i += 1

_Wigner_coefficients = np.empty(
    ((8 * ell_max**3 + 18 * ell_max**2 + 13 * ell_max + 3) // 3, ),
    dtype=float)
i = 0
for twoell in range(0, 2 * ell_max + 1):
    for twomp in range(-twoell, twoell + 1, 2):
        for twom in range(-twoell, twoell + 1, 2):
            tworho_min = max(0, twomp - twom)
            _Wigner_coefficients[i] = float(
                mpmath.sqrt(
                    mpmath.fac((twoell + twom) // 2) * mpmath.fac(
                        (twoell - twom) // 2) / (mpmath.fac(
                            (twoell + twomp) // 2) * mpmath.fac(
                                (twoell - twomp) // 2))) * mpmath.binomial(
                                    (twoell + twomp) // 2, tworho_min // 2) *
                mpmath.binomial((twoell - twomp) // 2,
                                (twoell - twom - tworho_min) // 2))
            i += 1
print(i, _Wigner_coefficients.shape)
np.save('Wigner_coefficients', _Wigner_coefficients)
Ejemplo n.º 32
0
    percent5 = float(user_input_array[5]) / 100.0
    user_Input_Is_Valid = True
    return 1


###########Fourth Part - mpmath and Nayuki
#constants
constant_e_mpmath_limit_definition = 0  #this constant e is only used with hector's method
constant_e_mpmath_infinite_series_definition = 0  #this constant e is also only used with hector's method
if mpmath_found:
    mpmath.mp.dps = 100  #mpmath will use 100 decimal places numbers
    mpmath.mp.pretty = True
    constant_e_mpmath_limit_definition = mpmath.limit(lambda n: (1 + 1 / n)**n,
                                                      mpmath.inf)
    constant_e_mpmath_infinite_series_definition = mpmath.nsum(
        lambda n: 1 / mpmath.fac(n), [0, mpmath.inf])


#this function will use a limit that is derived from putting(algebraically) the values of the compound interest formula inside of the limit definition of e
#and then will evaluate the limit using mpmath with the hope that the result will be more precise.
##########################################################################
def compound_interest_fnc_mpmath_with_limit_definition_of_e(
        initial_investment, percent1, percent2, percent3, percent4, percent5,
        compounding_frequency):
    #converting the float values to numbers that have 100 decimal places
    initial_investment = mpmath.mpmathify(initial_investment)
    percent1 = mpmath.mpmathify(percent1)
    percent2 = mpmath.mpmathify(percent2)
    percent3 = mpmath.mpmathify(percent3)
    percent4 = mpmath.mpmathify(percent4)
    percent5 = mpmath.mpmathify(percent5)
Ejemplo n.º 33
0
import mpmath
import numpy as np

lmax = 32

mpmath.mp.dps = 4 * lmax

_Wigner_coefficients = np.empty(((8 * lmax ** 3 + 18 * lmax ** 2 + 13 * lmax + 3) // 3,), dtype=float)
i = 0
for twol in range(0, 2 * lmax + 1):
    for twomp in range(-twol, twol + 1, 2):
        for twom in range(-twol, twol + 1, 2):
            tworho_min = max(0, twomp - twom)
            _Wigner_coefficients[i] = float(mpmath.sqrt(mpmath.fac((twol + twom) // 2) * mpmath.fac((twol - twom) // 2)
                                                        / (mpmath.fac((twol + twomp) // 2) * mpmath.fac(
                (twol - twomp) // 2)))
                                            * mpmath.fac((twol + twomp) // 2)
                                            * mpmath.fac((twol - twomp) // 2))
            i += 1
print(i, _Wigner_coefficients.shape)
np.save('Wigner_coefficients', _Wigner_coefficients)
Ejemplo n.º 34
0
def getArrangementsOperator(n):
    return floor(fmul(fac(n), e))
Ejemplo n.º 35
0
 def eval(self, z):
     return mpmath.fac(z)
Ejemplo n.º 36
0
 def fac_ratio(m, n):
     return fac(m) / fac(n)
Ejemplo n.º 37
0
def getLahNumberOperator(n, k):
    return fmul(power(-1, n),
                fdiv(fmul(binomial(n, k), fac(fsub(n, 1))), fac(fsub(k, 1))))
def rate_coverage(mk_matrix, lamda_u, rate_threshold):
    mk_mat = mk_matrix.copy()
    mk_mat_size = mk_mat.shape
    mk_mat[:, 3] = gb.dbm2pow(mk_mat[:, 3])  # converts power from dBm to W
    mk_mat[:, 6] = gb.db2pow(mk_mat[:, 6])  # coverts Bias from dB to number
    mk_OpenCell_RowIdx = (np.asarray(np.where(
        mk_mat[:,
               2] == True))).flatten()  # gives row index of open-access (m,k)
    area_opencells = np.zeros(mk_mat_size[0],
                              float)  # initialize area of open cells to zero
    Gij_mk_array = [[] for i in range(mk_mat_size[0])
                    ]  #Gij(m,k) polynomial coefficient matrix
    alpha_norm_mk_array = [[] for i in range(mk_mat_size[0])]
    Tmk = mk_mat[:, 3] * mk_mat[:, 6]  #Association weight
    Tmk_OpenCell = Tmk[
        mk_OpenCell_RowIdx]  #Association weight for open access cells
    temp_sum_integral_result = np.zeros(mk_mat_size[0], float)
    rate_coverage = np.zeros_like(rate_threshold, float)  #output array
    N_max = 4 * lamda_u
    for i in mk_OpenCell_RowIdx:  # loop to calculate Area, Nij and Gij(m,k) of open-access cells
        Tmk_norm = Tmk_OpenCell / Tmk[i]
        alpha_norm = mk_mat[mk_OpenCell_RowIdx, 5] / mk_mat[i, 5]
        Gij_mk = mk_mat[mk_OpenCell_RowIdx, 4] * (
            Tmk_norm**(2 / mk_mat[mk_OpenCell_RowIdx, 5])
        )  # Eq-7 is computed with (i,j) corresponding to ith row index
        Gij_mk_array[i] = Gij_mk
        alpha_norm_mk_array[i] = alpha_norm
        area_opencells[i] = A_ij(mk_mat[i, 4], Gij_mk, alpha_norm)
    for rate_idx in range(len(rate_threshold)):
        for i in mk_OpenCell_RowIdx:
            f1_temp = lamda_u * area_opencells[i] / mk_mat[i, 4]
            f1 = lambda n: ((3.5**3.5) / mp.fac(n)) * (mp.gamma(
                n + 4.5) / 3.32335097044784) * (f1_temp**n) * (
                    3.5 + f1_temp)**(
                        -n - 4.5)  #computation of sum terms in equation 20
            temp_sum = np.zeros(N_max + 1, float)
            temp_integral = np.zeros(N_max + 1, float)
            f2 = lambda y: sum(
                np.asarray(Gij_mk_array[i]) * (y**(2 / np.asarray(
                    alpha_norm_mk_array[i]))))  #Gij(m,k) term in eq 20
            Dij_inp = np.array([np.zeros(5, float) for tier in range(3)
                                ])  #initialize matrix for Dij(m,k) function
            #alpha_norm_dij = Dij_inp[:,2]/mk_mat[i,5]
            #alpha_norm_dij[alpha_norm_dij==0]=1  #to avoid divide by zero warning :):):)
            tier_RowIndx = (np.asarray(np.where(mk_mat[:, 0] == mk_mat[i, 0]))
                            ).flatten()  #index of tiers of ith rows RAT system
            for x in tier_RowIndx:  #fill Dij(m,k) input matrix
                k = mk_mat[x, 1]  # gives the Kth tier of Mth RAT system
                Dij_inp[k - 1, 0] = mk_mat[x, 3] / mk_mat[i, 3]
                Dij_inp[k - 1, 1] = Tmk[x] / Tmk[i]
                Dij_inp[k - 1, 2] = mk_mat[x, 5]
                if (mk_mat[x, 2]):
                    Dij_inp[k - 1, 3] = mk_mat[x, 4]
                else:
                    Dij_inp[k - 1, 4] = mk_mat[x, 4]
            for n in range(0, N_max + 1):
                temp_sum[n] = f1(n)
                sinr = (rate_threshold[rate_idx] / mk_mat[i, 7]) * (n + 1)
                #print(sinr)
                Dij_poly = D_ij(
                    Dij_inp,
                    t_x((rate_threshold[rate_idx] / mk_mat[i, 7]) * (n + 1)))
                alpha_norm_dij = Dij_inp[:, 2] / mk_mat[i, 5]
                alpha_norm_dij[alpha_norm_dij ==
                               0] = 1  #to avoid divide by zero warning :):):)
                f3 = lambda y: sum(Dij_poly * (y**(2 / alpha_norm_dij))
                                   )  #Dij term in integration
                f4 = lambda y: (t_x(
                    (rate_threshold[rate_idx] / mk_mat[i, 7]) *
                    (n + 1)) * y**(mk_mat[i, 5])) / mk_mat[i, 3]
                f5 = lambda y: -f4(y) - mp.pi * f3(y) - mp.pi * f2(y)
                temp_integral[n] = mp.quad(lambda y: y * mp.exp(f5(y)),
                                           [0, mp.inf])
            temp_sum_integral_result[i] = np.dot(temp_sum, temp_integral)
        rate_coverage[rate_idx] = (sum(
            (2 * np.pi * mk_mat[:, 4]) * temp_sum_integral_result))
    return (rate_coverage, rate_threshold)
Ejemplo n.º 39
0
def lyapunov_exponent(mathcalA, varphi, periodic_points, alg='basic', norm=2):

    k = max([len(word) for word in periodic_points])

    if alg == 'basic':
        approx_basic = []

        for n in range(1, k + 1):
            integral = sum([
                mpmath.log(mpmath.norm(cocycle(word, mathcalA), p=norm)) *
                weight(word, varphi) for word in periodic_points
                if len(word) == n
            ])
            normalization = sum([
                weight(word, varphi) for word in periodic_points
                if len(word) == n
            ])
            approx_basic.append(integral / (n * normalization))

        return approx_basic

    elif alg == 'pollicott':
        #Compute the operator trace for each periodic point
        op_trace = {
            word: operator_trace(cocycle(word, mathcalA), 0)[0]
            for word in periodic_points
        }
        op_trace_der = {
            word: operator_trace(cocycle(word, mathcalA), 0)[1]
            for word in periodic_points
        }

        #Compute traces for products of transfer operator put in dictionary indexed by power
        trace = [
            sum([(op_trace[word] * weight(word, varphi))
                 for word in periodic_points if len(word) == n])
            for n in range(1, k + 1)
        ]
        trace_der = [
            sum([(op_trace_der[word] * weight(word, varphi))
                 for word in periodic_points if len(word) == n])
            for n in range(1, k + 1)
        ]

        coefficients = [mpmath.mpf(1)]

        coefficients_der = [mpmath.mpf(0)]

        for n in range(1, k + 1):
            M = mpmath.matrix(n)
            Der_M = mpmath.matrix(n)
            for i in range(0, n):
                for j in range(0, n):
                    if j > i + 1:
                        M[i, j] = 0
                        Der_M[i, j] = 0
                    elif j == i + 1:
                        M[i, j] = n - j
                        Der_M[i, j] = 0
                    else:
                        M[i, j] = trace[i - j]
                        Der_M[i, j] = trace_der[i - j]

            coefficients.append((((-1)**n) / mpmath.fac(n)) * mpmath.det(M))

            if n == 1:
                coefficients_der.append(
                    (((-1)**n) / mpmath.fac(n)) * trace_der[0])
            else:
                #Use Jacobi's formula to compute derivative of coefficients
                coefficients_der.append(
                    (((-1)**n) / mpmath.fac(n)) * trace_of(adj(M) * Der_M))

        approximation = []

        for n in range(1, k + 1):
            approximation.append(
                sum([coefficients_der[m] for m in range(1, n + 1)]) /
                sum([m * coefficients[m] for m in range(1, n + 1)]))

        return approximation

    else:
        return "Choices of algorithm are 'basic' and 'pollicott'"