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


Python math.fabs方法代码示例

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


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

示例1: contains

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def contains(self, other):
        if isinstance(other, self.__class__):
            if self.is_inverted():
                if other.is_inverted():
                    return other.lo() >= self.lo() and other.hi() <= self.hi()
                return (other.lo() >= self.lo() or other.hi() <= self.hi()) \
                        and not self.is_empty()
            else:
                if other.is_inverted():
                    return self.is_full() or other.is_empty()
                return other.lo() >= self.lo() and other.hi() <= self.hi()
        else:
            assert math.fabs(other) <= math.pi
            if other == -math.pi:
                other = math.pi
            return self.fast_contains(other) 
开发者ID:qedus,项目名称:sphere,代码行数:18,代码来源:sphere.py

示例2: test_speed_limiting

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def test_speed_limiting(self):
        obj = pySmartDL.SmartDL(self.res_testfile_1gb, dest=self.dl_dir, progress_bar=False, connect_default_logger=self.enable_logging)
        obj.limit_speed(1024**2)  # 1MB per sec
        obj.start(blocking=False)

        while not obj.get_dl_size():
            time.sleep(0.1)
        time.sleep(30)

        expected_dl_size = 30 * 1024**2
        allowed_delta = 0.6  # because we took only 30sec, the delta needs to be quite big, it we were to test 60sec the delta would probably be much smaller
        diff = math.fabs(expected_dl_size - obj.get_dl_size()) / expected_dl_size

        obj.stop()
        obj.wait()

        self.assertLessEqual(diff, allowed_delta) 
开发者ID:iTaybb,项目名称:pySmartDL,代码行数:19,代码来源:test_pySmartDL.py

示例3: check_success

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def check_success(self, position, close_goal):

        rospy.logwarn("gripping force: " + str(self._gripper.get_force()))
        rospy.logwarn("gripper position: " + str(self._gripper.get_position()))
        rospy.logwarn("gripper position deadzone: " + str(self._gripper.get_dead_zone()))

        if not self._gripper.is_moving():
            success = True
        else:
            success = False

        # success = fabs(self._gripper.get_position() - position) < self._gripper.get_dead_zone()


        rospy.logwarn("gripping success: " + str(success))

        return success 
开发者ID:microsoft,项目名称:AI-Robot-Challenge-Lab,代码行数:19,代码来源:gripper_action_server.py

示例4: _adjust

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def _adjust(self, xa, ya, x, y, xb, yb):
        """ fix the sides of the map """
        if self.grid[x][y] == 0:
            d = math.fabs(xa - xb) + math.fabs(ya - yb)
            ROUGHNESS = self.params.get('roughness')
            v = (self.grid[xa][ya] + self.grid[xb][yb]) / 2.0 \
                + (random.random() - 0.5) * d * ROUGHNESS
            c = int(math.fabs(v) % 257)
            if y == 0:
                self.grid[x][self.size - 1] = c
            if x == 0 or x == self.size - 1:
                if y < self.size - 1:
                    self.grid[x][self.size - 1 - y] = c
            range_low, range_high = self.params.get('height_range')
            if c < range_low:
                c = range_low
            elif c > range_high:
                c = range_high
            self.grid[x][y] = c 
开发者ID:eranimo,项目名称:hexgen,代码行数:21,代码来源:heightmap.py

示例5: function

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def function(self):
		r"""Return benchmark evaluation function.

		Returns:
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
		"""
		def f(D, x):
			r"""Fitness function.

			Args:
				D (int): Dimensionality of the problem
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.

			Returns:
				float: Fitness value for the solution.
			"""
			val1, val2 = 0.0, 0.0
			for i in range(D): val1 += x[i] ** 2
			for i in range(D): val2 += x[i]
			return fabs(val1 ** 2 - val2 ** 2) ** (1 / 2) + (0.5 * val1 + val2) / D + 0.5
		return f

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3 
开发者ID:NiaOrg,项目名称:NiaPy,代码行数:25,代码来源:hgbat.py

示例6: function

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def function(self):
		r"""Return benchmark evaluation function.

		Returns:
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
		"""
		def f(D, x):
			r"""Fitness function.

			Args:
				D (int): Dimensionality of the problem
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.

			Returns:
				float: Fitness value for the solution.
			"""
			val = 1.0
			for i in range(D):
				valt = 1.0
				for j in range(1, 33): valt += fabs(2 ** j * x[i] - round(2 ** j * x[i])) / 2 ** j
				val *= (1 + (i + 1) * valt) ** (10 / D ** 1.2) - (10 / D ** 2)
			return 10 / D ** 2 * val
		return f

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3 
开发者ID:NiaOrg,项目名称:NiaPy,代码行数:27,代码来源:katsuura.py

示例7: function

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def function(self):
		r"""Return benchmark evaluation function.

		Returns:
			Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function
		"""
		def g(z, D):
			if z > 500: return (500 - fmod(z, 500)) * sin(sqrt(fabs(500 - fmod(z, 500)))) - (z - 500) ** 2 / (10000 * D)
			elif z < -500: return (fmod(z, 500) - 500) * sin(sqrt(fabs(fmod(z, 500) - 500))) + (z - 500) ** 2 / (10000 * D)
			return z * sin(fabs(z) ** (1 / 2))
		def h(x, D): return g(x + 420.9687462275036, D)
		def f(D, sol):
			r"""Fitness function.

			Args:
				D (int): Dimensionality of the problem
				sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check.

			Returns:
				float: Fitness value for the solution.
			"""
			val = 0.0
			for i in range(D): val += h(sol[i], D)
			return 418.9829 * D - val
		return f 
开发者ID:NiaOrg,项目名称:NiaPy,代码行数:27,代码来源:schwefel.py

示例8: get_version_from_list

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def get_version_from_list(v, vlist):
    """See if we can match v (string) in vlist (list of strings)
    Linux has to match in a fuzzy way."""
    if is_windows:
        # Simple case, just find it in the list
        if v in vlist: return v
        else: return None
    else:
        # Fuzzy match: normalize version number first, but still return
        # original non-normalized form.
        fuzz = 0.001
        for vi in vlist:
            if math.fabs(linux_ver_normalize(vi) - linux_ver_normalize(v)) < fuzz:
                return vi
        # Not found
        return None 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:18,代码来源:intelc.py

示例9: assertNear

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def assertNear(self, f1, f2, err, msg=None):
    """Asserts that two floats are near each other.

    Checks that |f1 - f2| < err and asserts a test failure
    if not.

    Args:
      f1: A float value.
      f2: A float value.
      err: A float value.
      msg: An optional string message to append to the failure message.
    """
    self.assertTrue(
        math.fabs(f1 - f2) <= err,
        "%f != %f +/- %f%s" % (f1, f2, err, " (%s)" % msg
                               if msg is not None else "")) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:test_util.py

示例10: testAUCMeter

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def testAUCMeter(self):
        mtr = meter.AUCMeter()

        test_size = 1000
        mtr.add(torch.rand(test_size), torch.zeros(test_size))
        mtr.add(torch.rand(test_size), torch.Tensor(test_size).fill_(1))

        val, tpr, fpr = mtr.value()
        self.assertTrue(math.fabs(val - 0.5) < 0.1, msg="AUC Meter fails")

        mtr.reset()
        mtr.add(torch.Tensor(test_size).fill_(0), torch.zeros(test_size))
        mtr.add(torch.Tensor(test_size).fill_(0.1), torch.zeros(test_size))
        mtr.add(torch.Tensor(test_size).fill_(0.2), torch.zeros(test_size))
        mtr.add(torch.Tensor(test_size).fill_(0.3), torch.zeros(test_size))
        mtr.add(torch.Tensor(test_size).fill_(0.4), torch.zeros(test_size))
        mtr.add(torch.Tensor(test_size).fill_(1),
                torch.Tensor(test_size).fill_(1))
        val, tpr, fpr = mtr.value()

        self.assertEqual(val, 1.0, msg="AUC Meter fails") 
开发者ID:pytorch,项目名称:tnt,代码行数:23,代码来源:test_meters.py

示例11: nextX

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def nextX(self):
        if self.c[1] != self.a[1] and self.c[1] != self.b[1]:
            # inverse quadratic interpolation
            s = self.a[0] * self.b[1] * self.c[1] / ((self.a[1] - self.b[1]) * (self.a[1] - self.c[1])) \
                + self.b[0] * self.a[1] * self.c[1] / ((self.b[1] - self.a[1]) * (self.b[1] - self.c[1])) \
                + self.c[0] * self.a[1] * self.b[1] / ((self.c[1] - self.a[1]) * (self.c[1] - self.b[1]))
        else:
            s = (self.a[0] * self.b[1] - self.b[0] * self.a[1]) / (self.b[1] - self.a[1])

        c_dist = fabs(self.c[0] - self.b[0] if self.bisect else self.d)
        self.bisect = (s - self.b[0]) * (s - 0.75 * self.a[0] - 0.25 * self.b[0]) >= 0. \
                      or fabs(s - self.b[0]) > 0.5 * c_dist \
                      or c_dist < self.tol

        if self.bisect:
            s = 0.5 * (self.a[0] + self.b[0])

        self.d = s
        return s 
开发者ID:alpha-miner,项目名称:Finance-Python,代码行数:21,代码来源:Brent.py

示例12: is_fallen

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def is_fallen(self):
    """Decide whether the minitaur has fallen.

    Returns:
      Boolean value that indicates whether the minitaur has fallen.
    """
    roll, pitch, _ = self.minitaur.GetTrueBaseRollPitchYaw()
    is_fallen = math.fabs(roll) > 0.3 or math.fabs(pitch) > 0.3
    return is_fallen 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:11,代码来源:minitaur_trotting_env.py

示例13: is_fallen

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def is_fallen(self):
    """Decides whether the minitaur is in a fallen state.

    If the roll or the pitch of the base is greater than 0.3 radians, the
    minitaur is considered fallen.

    Returns:
      Boolean value that indicates whether the minitaur has fallen.
    """
    roll, pitch, _ = self.minitaur.GetTrueBaseRollPitchYaw()
    return math.fabs(roll) > 0.3 or math.fabs(pitch) > 0.3 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:13,代码来源:minitaur_reactive_env.py

示例14: _reward

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def _reward(self):
    roll, pitch, _ = self.minitaur.GetBaseRollPitchYaw()
    return 1.0 / (0.001 + math.fabs(roll) + math.fabs(pitch)) 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:5,代码来源:minitaur_four_leg_stand_env.py

示例15: _sift_sentiment_scores

# 需要导入模块: import math [as 别名]
# 或者: from math import fabs [as 别名]
def _sift_sentiment_scores(self, sentiments):
        # want separate positive versus negative sentiment scores
        pos_sum = 0.0
        neg_sum = 0.0
        neu_count = 0
        for sentiment_score in sentiments:
            if sentiment_score > 0:
                pos_sum += (float(sentiment_score) +1) # compensates for neutral words that are counted as 1
            if sentiment_score < 0:
                neg_sum += (float(sentiment_score) -1) # when used with math.fabs(), compensates for neutrals
            if sentiment_score == 0:
                neu_count += 1
        return pos_sum, neg_sum, neu_count 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:15,代码来源:vader.py


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