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


Python math.log10方法代码示例

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


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

示例1: getTicks

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def getTicks(self, regionID):
        ticks = []
        start = 0
        width = self.scale.partsToLengths[regionID]
        end = start + width

        res = (10 ** round(math.log10(end - start))) / 10.0
        if width / res > 15:
            res *= 2.5
        elif width / res < 5:
            res /= 2.0

        roundStart = start - (start%res)

        for i in range(int(roundStart), end, int(res)):
            ticks.append(i)

        return ticks 
开发者ID:svviz,项目名称:svviz,代码行数:20,代码来源:track.py

示例2: test

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def test(ctx):
    val_data.reset()
    avg_psnr = 0
    batches = 0
    for batch in val_data:
        batches += 1
        data = gluon.utils.split_and_load(batch.data[0], ctx_list=ctx, batch_axis=0)
        label = gluon.utils.split_and_load(batch.label[0], ctx_list=ctx, batch_axis=0)
        outputs = []
        for x in data:
            outputs.append(net(x))
        metric.update(label, outputs)
        avg_psnr += 10 * math.log10(1/metric.get()[1])
        metric.reset()
    avg_psnr /= batches
    print('validation avg psnr: %f'%avg_psnr) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:18,代码来源:super_resolution.py

示例3: _fade_in

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def _fade_in(self, waveform_length: int) -> Tensor:
        fade = torch.linspace(0, 1, self.fade_in_len)
        ones = torch.ones(waveform_length - self.fade_in_len)

        if self.fade_shape == "linear":
            fade = fade

        if self.fade_shape == "exponential":
            fade = torch.pow(2, (fade - 1)) * fade

        if self.fade_shape == "logarithmic":
            fade = torch.log10(.1 + fade) + 1

        if self.fade_shape == "quarter_sine":
            fade = torch.sin(fade * math.pi / 2)

        if self.fade_shape == "half_sine":
            fade = torch.sin(fade * math.pi - math.pi / 2) / 2 + 0.5

        return torch.cat((fade, ones)).clamp_(0, 1) 
开发者ID:pytorch,项目名称:audio,代码行数:22,代码来源:transforms.py

示例4: _fade_out

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def _fade_out(self, waveform_length: int) -> Tensor:
        fade = torch.linspace(0, 1, self.fade_out_len)
        ones = torch.ones(waveform_length - self.fade_out_len)

        if self.fade_shape == "linear":
            fade = - fade + 1

        if self.fade_shape == "exponential":
            fade = torch.pow(2, - fade) * (1 - fade)

        if self.fade_shape == "logarithmic":
            fade = torch.log10(1.1 - fade) + 1

        if self.fade_shape == "quarter_sine":
            fade = torch.sin(fade * math.pi / 2 + math.pi / 2)

        if self.fade_shape == "half_sine":
            fade = torch.sin(fade * math.pi + math.pi / 2) / 2 + 0.5

        return torch.cat((ones, fade)).clamp_(0, 1) 
开发者ID:pytorch,项目名称:audio,代码行数:22,代码来源:transforms.py

示例5: forward

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def forward(self, waveform: Tensor) -> Tensor:
        r"""
        Args:
            waveform (Tensor): Tensor of audio of dimension (..., time).

        Returns:
            Tensor: Tensor of audio of dimension (..., time).
        """
        if self.gain_type == "amplitude":
            waveform = waveform * self.gain

        if self.gain_type == "db":
            waveform = F.gain(waveform, self.gain)

        if self.gain_type == "power":
            waveform = F.gain(waveform, 10 * math.log10(self.gain))

        return torch.clamp(waveform, -1, 1) 
开发者ID:pytorch,项目名称:audio,代码行数:20,代码来源:transforms.py

示例6: get_weight

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def get_weight(follower_count=1, following_count=1, status_count=1, listed_in_count=1, is_verified=False):
    """
    (Follower_count / Following_count) + status_count + listed_in_count
    """
    if not follower_count and not following_count and not status_count:
        return 0
    if not follower_count:
        follower_count = 1
    if not following_count:
        following_count = 1
    if not status_count:
        status_count = 1
    if not listed_in_count:
        listed_in_count = 1
    return int((follower_count / following_count) *
               math.log10(follower_count) +
               2 * listed_in_count) + 50 * bool(is_verified) 
开发者ID:pixlie,项目名称:oxidizr,代码行数:19,代码来源:models.py

示例7: test_custom_bode_default

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def test_custom_bode_default(self):
        ct.config.defaults['bode.dB'] = True
        ct.config.defaults['bode.deg'] = True
        ct.config.defaults['bode.Hz'] = True

        # Generate a Bode plot
        plt.figure()
        omega = np.logspace(-3, 3, 100)
        ct.bode_plot(self.sys, omega, dB=True)
        mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data()
        np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3)

        # Override defaults
        plt.figure()
        ct.bode_plot(self.sys, omega, Hz=True, deg=False, dB=True)
        mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data()
        phase_x, phase_y = (((plt.gcf().axes[1]).get_lines())[0]).get_data()
        np.testing.assert_almost_equal(mag_x[0], 0.001 / (2*pi), decimal=6)
        np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3)
        np.testing.assert_almost_equal(phase_y[-1], -pi, decimal=2)

        ct.reset_defaults() 
开发者ID:python-control,项目名称:python-control,代码行数:24,代码来源:config_test.py

示例8: PlotTimeResp

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def PlotTimeResp(self, u, t, fig, clear=True, label='model', mysub=111):
        ax = fig.add_subplot(mysub)
        if clear:
            ax.cla()
        try:
            y = self.lsim(u, t)
        except:
            y = self.lsim2(u, t)
        ax.plot(t, y, label=label)
        return ax


##     def BodePlot(self, f, fig, clear=False):
##         mtf = self.FreqResp(
##         ax1 = fig.axes[0]
##         ax1.semilogx(modelf,20*log10(abs(mtf)))
##         mphase = angle(mtf, deg=1)
##         ax2 = fig.axes[1]
##         ax2.semilogx(modelf, mphase) 
开发者ID:python-control,项目名称:python-control,代码行数:21,代码来源:controls.py

示例9: ELO

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def ELO(wins, losses, draws):

    def _elo(x):
        if x <= 0 or x >= 1: return 0.0
        return -400*math.log10(1/x-1)

    # win/loss/draw ratio
    N = wins + losses + draws;
    if N == 0: return (0, 0, 0)
    w = float(wins)  / N
    l = float(losses)/ N
    d = float(draws) / N

    # mu is the empirical mean of the variables (Xi), assumed i.i.d.
    mu = w + d/2

    # stdev is the empirical standard deviation of the random variable (X1+...+X_N)/N
    stdev = math.sqrt(w*(1-mu)**2 + l*(0-mu)**2 + d*(0.5-mu)**2) / math.sqrt(N)

    # 95% confidence interval for mu
    mu_min = mu + phi_inv(0.025) * stdev
    mu_max = mu + phi_inv(0.975) * stdev

    return (_elo(mu_min), _elo(mu), _elo(mu_max)) 
开发者ID:AndyGrant,项目名称:OpenBench,代码行数:26,代码来源:stats.py

示例10: simplify_surd

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def simplify_surd(value, sample_args, context=None):
  """E.g., "Simplify (2 + 5*sqrt(3))**2."."""
  del value  # unused
  if context is None:
    context = composition.Context()

  entropy, sample_args = sample_args.peel()

  while True:
    base = random.randint(2, 20)
    if sympy.Integer(base).is_prime:
      break
  num_primes_less_than_20 = 8
  entropy -= math.log10(num_primes_less_than_20)
  exp = _sample_surd(base, entropy, max_power=2, multiples_only=False)
  simplified = sympy.expand(sympy.simplify(exp))

  template = random.choice([
      'Simplify {exp}.',
  ])
  return example.Problem(
      question=example.question(context, template, exp=exp),
      answer=simplified) 
开发者ID:deepmind,项目名称:mathematics_dataset,代码行数:25,代码来源:arithmetic.py

示例11: _semi_prime

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def _semi_prime(entropy):
  """Generates a semi-prime with the given entropy."""
  # Add on extra entropy to account for the sparsity of the primes; we don't
  # actually use the integers sampled, but rather a random prime close to them;
  # thus some entropy is lost, which we must account for
  entropy += math.log10(max(1, entropy * math.log(10)))

  # We intentionally uniformy sample the "entropy" (i.e., approx number digits)
  # of the two factors.
  entropy_1, entropy_2 = entropy * np.random.dirichlet([1, 1])

  # Need >= 2 for randprime to always work (Betrand's postulate).
  approx_1 = number.integer(entropy_1, signed=False, min_abs=2)
  approx_2 = number.integer(entropy_2, signed=False, min_abs=2)

  factor_1 = sympy.ntheory.generate.randprime(approx_1 / 2, approx_1 * 2)
  factor_2 = sympy.ntheory.generate.randprime(approx_2 / 2, approx_2 * 2)

  return factor_1 * factor_2 
开发者ID:deepmind,项目名称:mathematics_dataset,代码行数:21,代码来源:numbers.py

示例12: calculate_psnr

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def calculate_psnr(img1, img2, border=0):
    # img1 and img2 have range [0, 255]
    #img1 = img1.squeeze()
    #img2 = img2.squeeze()
    if not img1.shape == img2.shape:
        raise ValueError('Input images must have the same dimensions.')
    h, w = img1.shape[:2]
    img1 = img1[border:h-border, border:w-border]
    img2 = img2[border:h-border, border:w-border]

    img1 = img1.astype(np.float64)
    img2 = img2.astype(np.float64)
    mse = np.mean((img1 - img2)**2)
    if mse == 0:
        return float('inf')
    return 20 * math.log10(255.0 / math.sqrt(mse))


# --------------------------------------------
# SSIM
# -------------------------------------------- 
开发者ID:cszn,项目名称:KAIR,代码行数:23,代码来源:utils_image.py

示例13: calc_psnr

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def calc_psnr(sr, hr, scale, rgb_range, dataset=None):
    if hr.nelement() == 1: return 0

    diff = (sr - hr) / rgb_range
    if dataset and dataset.dataset.benchmark:
        shave = scale
        # print('Ycbcr PSNR.')
        if diff.size(1) > 1:
            gray_coeffs = [65.738, 129.057, 25.064]
            convert = diff.new_tensor(gray_coeffs).view(1, 3, 1, 1) / 256
            diff = diff.mul(convert).sum(dim=1)
    else:
        shave = scale + 6

    valid = diff[..., shave:-shave, shave:-shave]
    mse = valid.pow(2).mean()

    return -10 * math.log10(mse) 
开发者ID:HolmesShuan,项目名称:OISR-PyTorch,代码行数:20,代码来源:utility.py

示例14: percent_to_millibel

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def percent_to_millibel(percent, raspberry_mod=False):
    if not raspberry_mod:
        from math import log10

        multiplier = 2.5

        percent *= multiplier
        percent = min(percent, 100. * multiplier)
        percent = max(percent, 0.000001)

        millibel = 1000 * log10(percent / 100.)

    else:
        # special case for mute
        if percent == 0:
            return -11000

        min_allowed = -4000
        max_allowed = 400
        percent = percent / 100.
        millibel = min_allowed + (max_allowed - min_allowed) * percent

    return int(millibel) 
开发者ID:KanoComputing,项目名称:kano-toolset,代码行数:25,代码来源:audio.py

示例15: calculate_decibel

# 需要导入模块: import math [as 别名]
# 或者: from math import log10 [as 别名]
def calculate_decibel(data):
    """
    Calculates the volume level in decibel of the given data

    :param data: A bytestring used to calculate the decibel level
    :return db: The calculated volume level in decibel
    """

    count = len(data) / 2
    form = "%dh" % count
    shorts = struct.unpack(form, data)
    sum_squares = 0.0
    for sample in shorts:
        n = sample * (1.0 / 32768)
        sum_squares += n * n
    rms = math.sqrt(sum_squares / count) + 0.0001
    db = 20 * math.log10(rms)
    return db 
开发者ID:loehnertz,项目名称:rattlesnake,代码行数:20,代码来源:rattlesnake.py


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