当前位置: 首页>>代码示例>>Python>>正文


Python Math.log方法代码示例

本文整理汇总了Python中pyLibrary.maths.Math.log方法的典型用法代码示例。如果您正苦于以下问题:Python Math.log方法的具体用法?Python Math.log怎么用?Python Math.log使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyLibrary.maths.Math的用法示例。


在下文中一共展示了Math.log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pdf

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
    def pdf(self, data):

        # XXX assume root as first index
        assert self.parents[0] == -1
        assert self.w[0] == 0.0

        res = np.zeros(len(data))

        for i in range(len(data)):
            res[i] = Math.log((1.0 / (math.sqrt(2.0 * math.pi) * self.variance[0])) * math.exp(( data[i, 0] - self.mean[0]  ) ** 2 / (-2.0 * self.variance[0] ** 2)))
            for j in range(1, self.dimension):
                pind = self.parents[j]
                res[i] += Math.log(
                    (1.0 / (math.sqrt(2.0 * math.pi) * self.variance[j])) * math.exp(( data[i, j] - self.mean[j] - self.w[j] * ( data[i, pind] - self.mean[pind] )  ) ** 2 / (-2.0 * self.variance[j] ** 2)))

        return res
开发者ID:klahnakoski,项目名称:pymix,代码行数:18,代码来源:conditional_gauss.py

示例2: ighmm_log_gamma_sum

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def ighmm_log_gamma_sum(log_a, s, parent):
    max = 1.0
    argmax = 0

    # shortcut for the trivial case
    if parent.gamma_states == 1:
        return parent.gamma_a[0] + log_a[parent.gamma_id[0]]

    logP = ARRAY_MALLOC(len(s.in_a))

    # calculate logs of a[k,l]*gamma[k,hi] as sums of logs and find maximum:
    for j in range(len(s.in_a)):
        # search for state j_id in the gamma list
        for k in range(0, parent.gamma_states):
            if parent.gamma_id[k] == j:
                break
        if k == parent.gamma_states:
            logP[j] = 1.0
        else:
            logP[j] = log_a[j] + parent.gamma_a[k]
            if max == 1.0 or (logP[j] > max and logP[j] != 1.0):
                max = logP[j]
                argmax = j

    # calculate max+Math.log(1+sum[j!=argmax exp(logP[j]-max)])
    result = 1.0
    for j in range(len(s.in_a)):
        if j != argmax and logP[j] != 1.0:
            result += exp(logP[j] - max)

    result = Math.log(result)
    result += max
    return result
开发者ID:klahnakoski,项目名称:pymix,代码行数:35,代码来源:kbest.py

示例3: sample

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
 def sample(self, native=False):
     if native:
         return random.normalvariate(self.mean, self.variance)
     else:
         r2 = -2.0 * Math.log(random_mt.float23())   # r2 ~ chi-square(2)
         theta = 2.0 * math.pi * random_mt.float23()  # theta ~ uniform(0, 2 \pi)
         return math.sqrt(self.variance) * math.sqrt(r2) * math.cos(theta) + self.mean
开发者ID:klahnakoski,项目名称:pymix,代码行数:9,代码来源:normal.py

示例4: wrap_gsl_dirichlet_lnpdf

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def wrap_gsl_dirichlet_lnpdf(alpha, x):
    if hasattr(x[0], "__iter__"):
        output = [wrap_gsl_dirichlet_lnpdf(alpha, xi) for xi in x]
    else:
        output = Math.log(special.gamma(sum(alpha))) - np.sum(np.log(special.gamma(alpha))) + np.sum(np.log([xi ** (ai - 1.0) for xi, ai in zip(x, alpha)]))

    return output
开发者ID:klahnakoski,项目名称:pymix,代码行数:9,代码来源:mixextend.py

示例5: Viterbi_precompute

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def Viterbi_precompute(mo, o, len, v):
    # Precomputing the Math.log(a_ij)
    for j in range(mo.N):
        for i in range(mo.N):
            if mo.s[j].in_a[i] == 0.0:        # DBL_EPSILON ?
                v.log_in_a[j][i] = +1 # Not used any further in the calculations
            else:
                v.log_in_a[j][i] = Math.log(mo.s[j].in_a[i])



    # Precomputing the Math.log(bj(ot))
    for j in range(mo.N):
        for t in range(mo.M):
            if mo.s[j].b[t] == 0.0:    # DBL_EPSILON ?
                v.log_b[j][t] = +1
            else:
                v.log_b[j][t] = Math.log(mo.s[j].b[t])
开发者ID:klahnakoski,项目名称:pymix,代码行数:20,代码来源:viterbi.py

示例6: kbest_buildLogMatrix

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def kbest_buildLogMatrix(s, N):
    # create & initialize matrix:
    log_a = ARRAY_MALLOC(N)
    for i in range(0, N):
        log_a[i] = ARRAY_MALLOC(N)
        for j in range(N):
            log_a[i][j] = Math.log(s[i].in_a[j])

    return log_a
开发者ID:klahnakoski,项目名称:pymix,代码行数:11,代码来源:kbest.py

示例7: geo_mean

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def geo_mean(values):
    """
    GIVEN AN ARRAY OF dicts, CALC THE GEO-MEAN ON EACH ATTRIBUTE
    """
    agg = Struct()
    for d in values:
        for k, v in d.items():
            if v != 0:
                agg[k] = nvl(agg[k], ZeroMoment.new_instance()) + Math.log(Math.abs(v))
    return {k: Math.exp(v.stats.mean) for k, v in agg.items()}
开发者ID:klahnakoski,项目名称:Datazilla2ElasticSearch,代码行数:12,代码来源:transform.py

示例8: sviterbi_precompute

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def sviterbi_precompute(smo, O, T, v):
    # Precomputing of Math.log(b_j(O_t))
    for t in range(T):
        for j in range(smo.N):
            cb = smo.s[j].calc_b(O[t])
            if cb == 0.0:
            # DBL_EPSILON ?
                v.log_b[j][t] = -DBL_MAX
            else:
                v.log_b[j][t] = Math.log(cb)
开发者ID:klahnakoski,项目名称:pymix,代码行数:12,代码来源:sviterbi.py

示例9: sdfobau_forward

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def sdfobau_forward(mo, O, len, alpha, scale):
    clazz = 0

    if mo.model_type & kSilentStates:
        mo.topo_order()

    sdfobau_initforward(mo, alpha[0], O[0], scale)
    if scale[0] < EPS_PREC:
        # means: first symbol can't be generated by hmm
        log_p = +1

    else:
        log_p = -Math.log(1 / scale[0])
        for t in range(1, len):
            scale[t] = 0.0
            if mo.cos > 1:
                clazz = mo.get_class(mo.N, t - 1)
                #iterate over non-silent states
            for i in range(mo.N):
                if not (mo.model_type & kSilentStates) or not (mo.silent[i]):
                    alpha[t][i] = sdfoba_stepforward(mo.s[i], alpha[t - 1], mo.s[i].b[O[t]], clazz)
                    scale[t] += alpha[t][i]


            #iterate over silent state
            if mo.model_type & kSilentStates:
                for i in range(mo.topo_order_length):
                    id = mo.topo_order[i]
                    alpha[t][id] = sdfoba_stepforward(mo.s[id], alpha[t], 1, clazz)
                    #scale[t] += alpha[t][id]

            if scale[t] < EPS_PREC:
                # O-string  can't be generated by hmm
                log_p = +1.0
                break

            c_t = 1 / scale[t]
            for i in range(mo.N):
                alpha[t][i] *= c_t
                # sum_ Math.log(c[t]) to get  Math.log( P(O|lambda) )
            log_p -= Math.log(c_t)
    return log_p
开发者ID:klahnakoski,项目名称:pymix,代码行数:44,代码来源:sdfoba.py

示例10: entropy

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def entropy(p):
    """
    Returns the Shannon entropy for the probilistic vector 'p'.

    @param p: 'numpy' vector that sums up to 1.0
    """
    res = 0.0
    for i in range(len(p)):
        if p[i] != 0.0:
            res += p[i] * Math.log(p[i], 2)
    return -res
开发者ID:klahnakoski,项目名称:pymix,代码行数:13,代码来源:stats.py

示例11: logp_joint

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
    def logp_joint(self, O, len, S, slen):
        state_pos = 0
        pos = 0
        osc = 0
        dim = self.dim

        prevstate = state = S[0]
        log_p = Math.log(self.s[state].pi)
        if not (self.model_type & kSilentStates) or 1: # XXX not mo.silent[state]  :
            log_p += Math.log(self.s[state].calc_b(O[pos]))
            pos += 1

        for state_pos in range(1, len):
            state = S[state_pos]
            if self.cos > 1:
                if not self.class_change.get_class:
                    Log.error("get_class not initialized")

                osc = self.class_change.get_class(self, O, self.class_change.k, pos)
                if osc >= self.cos:
                    Log.error("get_class returned index %d but model has only %d classes!", osc, self.cos)

            if abs(self.s[state].in_a[osc][prevstate]) < GHMM_EPS_PREC:
                Log.error("Sequence can't be built. There is no transition from state %d to %d.", prevstate, state)

            log_p += Math.log(self.s[state].in_a[osc][prevstate])

            if not (self.model_type & kSilentStates) or 1: # XXX !mo.silent[state]
                log_p += Math.log(self.s[state].calc_b(O[pos]))
                pos += 1

            prevstate = state

        if pos < len:
            Log.note("state sequence too shortnot  processed only %d symbols", pos)
        if state_pos < slen:
            Log.note("sequence too shortnot  visited only %d states", state_pos)

        return log_p
开发者ID:klahnakoski,项目名称:pymix,代码行数:41,代码来源:cmodel.py

示例12: get_posterior

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def get_posterior(mix_model, data, logreturn=True):
    # matrix of posterior probs: components# * (sequence positions)#
    log_l = np.zeros((mix_model.G, len(data)), dtype='Float64')

    # computing log posterior distribution
    for i in range(mix_model.G):
        log_l[i] = Math.log(mix_model.pi[i]) + mix_model.components[i].pdf(data)


    # computing data log likelihood as criteria of convergence
    # log_l is normalized in-place and likelihood is returned as log_p
    (log_l, log_p) = mixextend.get_normalized_posterior_matrix(log_l)

    if logreturn == True:
        return log_l
    else:
        return np.exp(log_l)
开发者ID:klahnakoski,项目名称:pymix,代码行数:19,代码来源:stats.py

示例13: ighmm_cvector_log_sum

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
def ighmm_cvector_log_sum(a, length):
    max = 1.0
    argmax = 0

    # find maximum value in a:
    for i in range(0, length):
        if max == 1.0 or (a[i] > max and a[i] != 1.0):
            max = a[i]
            argmax = i


    # calculate max+Math.log(1+sum[i!=argmax exp(a[i]-max)])
    result = 1.0
    for i in range(0, length):
        if a[i] != 1.0 and i != argmax:
            result += exp(a[i] - max)

    result = Math.log(result)
    result += max
    return result
开发者ID:klahnakoski,项目名称:pymix,代码行数:22,代码来源:wrapper.py

示例14: pdf

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
    def pdf(self, data):
        if isinstance(data, DataSet):
            assert data.internalData is not None, "Internal data not initialized."
            nr = len(data.internalData)
            assert data.internalData.shape == (nr, 1), 'shape = ' + str(data.internalData.shape)

            x = np.transpose(data.internalData)[0]

        elif hasattr(data, "__iter__"):
            nr = len(data)

            if data.shape == (nr, 1):  # data format needs to be changed
                x = np.transpose(data)[0]
            elif data.shape == (nr,):
                x = data
            else:
                raise TypeError, 'Invalid data shape: ' + str(data.shape)
        else:
            raise TypeError, "Unknown/Invalid input type:" + str(type(data))

        return Math.log(self.lambd) + (-self.lambd * x)  # XXX pure Python implementation for now
开发者ID:klahnakoski,项目名称:pymix,代码行数:23,代码来源:exponential.py

示例15: sample

# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import log [as 别名]
    def sample(self, seed=0, native=False):
        C0 = 2.515517
        C1 = 0.802853
        C2 = 0.010328
        D1 = 1.432788
        D2 = 0.189269
        D3 = 0.001308


        if self.variance <= 0.0:
            Log.error("u <= 0.0 not allowed\n")

        sigma = math.sqrt(self.variance)

        if seed != 0:
            random_mt.set_seed(seed)


        # Inverse transformation with restricted sampling by Fishman
        U = random_mt.float23()
        Feps = ighmm_rand_get_PHI((self.minimum - self.mean) / sigma)

        Us = Feps + (1 - Feps) * U
        Us1 = 1 - Us
        t = min(Us, Us1)

        t = math.sqrt(-Math.log(t))

        T = sigma * (t - (C0 + t * (C1 + t * C2)) / (1 + t * (D1 + t * (D2 + t * D3))))

        if Us < Us1:
            x = self.mean - T
        else:
            x = self.mean + T

        return x
开发者ID:klahnakoski,项目名称:pymix,代码行数:38,代码来源:normal_right.py


注:本文中的pyLibrary.maths.Math.log方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。