python类fabs()的实例源码

color_conversions.py 文件源码 项目:MagicWand 作者: GianlucaSilvestri 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def Lab_to_LCHab(cobj, *args, **kwargs):
    """
    Convert from CIE Lab to LCH(ab).
    """

    lch_l = cobj.lab_l
    lch_c = math.sqrt(math.pow(float(cobj.lab_a), 2) + math.pow(float(cobj.lab_b), 2))
    lch_h = math.atan2(float(cobj.lab_b), float(cobj.lab_a))

    if lch_h > 0:
        lch_h = (lch_h / math.pi) * 180
    else:
        lch_h = 360 - (math.fabs(lch_h) / math.pi) * 180

    return LCHabColor(
        lch_l, lch_c, lch_h, observer=cobj.observer, illuminant=cobj.illuminant)


# noinspection PyPep8Naming,PyUnusedLocal
color_conversions.py 文件源码 项目:MagicWand 作者: GianlucaSilvestri 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def Luv_to_LCHuv(cobj, *args, **kwargs):
    """
    Convert from CIE Luv to LCH(uv).
    """

    lch_l = cobj.luv_l
    lch_c = math.sqrt(math.pow(cobj.luv_u, 2.0) + math.pow(cobj.luv_v, 2.0))
    lch_h = math.atan2(float(cobj.luv_v), float(cobj.luv_u))

    if lch_h > 0:
        lch_h = (lch_h / math.pi) * 180
    else:
        lch_h = 360 - (math.fabs(lch_h) / math.pi) * 180
    return LCHuvColor(
        lch_l, lch_c, lch_h, observer=cobj.observer, illuminant=cobj.illuminant)


# noinspection PyPep8Naming,PyUnusedLocal
math_operation.py 文件源码 项目:vehicle_detection 作者: AuzanMuh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def centeroidPinHoleMode(height, focal, altitude, theta, yCoordinate):
    # height : jumlah baris (piksel)
    # focal -> |A'O| : focal length (piksel)
    # altitude -> |O'O| : tinggi kamera (m)
    # theta : sudut kemiringan kamera (derajat)
    # yCoordinate : indeks piksel Y object
    height = float(height)
    focal = float(focal)
    theta = float(theta)
    yCoordinate = float(yCoordinate)

    delta = math.degrees(math.atan(math.fabs(yCoordinate - (height / 2)) / focal))

    if yCoordinate >= height / 2:
        lCentroid = altitude * math.tan(math.radians(theta + delta))
    else:
        lCentroid = altitude * math.tan(math.radians(theta - delta))

    lCentroid = round(lCentroid, 4)
    delta = round(delta, 4)

    # print "delta: {0} | lCentroid: {1}".format(delta, lCentroid)
    return lCentroid
bridgeunit.py 文件源码 项目:SHIP 作者: duncan-r 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def area(self):
        """Returns the cross sectional area of the bridge openings.    

        Return:
            Dict - containing the area of the opening(s). keys = 'total', then
                '1', '2', 'n' for all openings found.
        """
        return 0
#         areas = []
#         opening_data = self.additional_row_collections['Opening']
#         x_vals = self.row_collection.getRowDataAsList(rdt.CHAINAGE)
#         y_vals = self.row_collection.getRowDataAsList(rdt.ELEVATION)
#         
#         start_vals = opening_data.getRowDataAsList(rdt.OPEN_START)
#         end_vals = opening_data.getRowDataAsList(rdt.OPEN_END)
#         soffit_vals = opening_data.getRowDataAsList(rdt.SOFFIT_LEVEL)
#         springing_vals = opening_data.getRowDataAsList(rdt.SPRINGING_LEVEL)
#         openings = zip(start_vals, end_vals, soffit_vals, springing_vals)
#         
#         for i, x in enumerate(x_vals):
#             
#             if math.fabs(x - ) 
#         
#         
#         i=0
Learning.py 文件源码 项目:options 作者: mcmachado 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _improvePolicy(self):
        ''' Policy improvement step. '''
        policy_stable = True
        for s in xrange(self.numStates):
            old_action = self.pi[s]
            tempV = [0.0] * len(self.actionSet)
            # I first get all value-function estimates
            for i in xrange(len(self.actionSet)):
                nextS, nextR = self.environment.getNextStateAndReward(
                    s, self.actionSet[i])
                tempV[i] = nextR + self.gamma * self.V[nextS]

            # Now I take the argmax
            self.pi[s] = np.argmax(tempV)
            # I break ties always choosing to terminate:
            if math.fabs(tempV[self.pi[s]] - tempV[(len(self.actionSet) - 1)]) < 0.001:
                self.pi[s] = (len(self.actionSet) - 1)
            if old_action != self.pi[s]:
                policy_stable = False

        return policy_stable
DFP.py 文件源码 项目:MLLearning 作者: buptdjd 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def hessian_dfp(self, c, delta_w, delta_g, epsilon):
        n = delta_w.size
        d = delta_g.dot(delta_w)
        if fabs(d) < epsilon:
            return np.identity(n)
        a = np.zeros((n, n))
        a = delta_w.dot(delta_w)
        a /= d
        b = np.zeros((n, n))
        w2 = c.dot(delta_g)
        b = w2.dot(w2)
        d = delta_g.dot(w2)
        if fabs(d) < epsilon:
            return np.identity(n)
        b /= d
        return c+a-b
math_utils.py 文件源码 项目:zipline-chinese 作者: zhanghan1990 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def tolerant_equals(a, b, atol=10e-7, rtol=10e-7):
    return math.fabs(a - b) <= (atol + rtol * math.fabs(b))
LEDBAT.py 文件源码 项目:PyPPSPP 作者: justas- 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _update_cto(self):
        # JP: One big WTF
        if self._first_est:
            self._srtt = self._qd
            self._rttvar = self._qd / 2
            self._cto = self._srtt + max([self._qd, LEDBAT.K * self._rttvar])
        else:
            self._rttvar = (1 - LEDBAT.BETA) * self._rttvar + LEDBAT.BETA * math.fabs(self._srtt - self._qd)
            self._srtt = (1 - LEDBAT.ALPHA) * self._srtt + LEDBAT.ALPHA * self._qd
            self._cto = self._srtt + max([self._g, LEDBAT.K * self._rttvar])
luna.py 文件源码 项目:lung-cancer-detector 作者: YichenGong 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _construct_mask_values(self, ids):
        mask_vals = {}
        print("Creating Mask Values...")

        size = len(self._annotations)
        for idx, annotation in enumerate(self._annotations):
            print(str(idx) + "/" + str(size))
            series, z, y, x, d = annotation #Order as given in the tutorial for LUNA-16
            r = d/2.0
            try:
                img, o, s = p.load(open(os.path.join(self._target_directory, series + ".pick"), "rb"))
            except:
                continue
            if series not in mask_vals:
                mask_vals[series] = {}
            voxelCenter = dp.world_to_voxel_coord(np.array([x, y, z]), o, s)
            x, y, z = voxelCenter
            y = int(y)
            z = int(z)
            sliceRange = range(max(0, int(x - r/s[0])), int(x + r/s[0] + 1)) #1 so that we don't loose any information
            for sliceIdx in sliceRange:
                center = (z, y)
                radius = math.sqrt(max(0, r*r - ((s[0] * math.fabs(x - sliceIdx))**2)))
                if sliceIdx not in mask_vals[series]:
                    mask_vals[series][sliceIdx] = []
                mask_vals[series][sliceIdx].append((center, max(radius/s[1], radius/s[2])))

        print("Mask values created!")
        return mask_vals
coordutils.py 文件源码 项目:astrobase 作者: waqasbhatti 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def decimal_to_hms(decimal_value):
    '''
    This converts from decimal degrees to HH:MM:SS, returned as a
    tuple. Negative values of degrees are wrapped to 360.0.

    '''

    # wrap to 360.0
    if decimal_value < 0:
        dec_wrapped = 360.0 + decimal_value
    else:
        dec_wrapped = decimal_value

    # convert to decimal hours first
    dec_hours = dec_wrapped/15.0

    if dec_hours < 0:
        negative = True
        dec_val = fabs(dec_hours)
    else:
        negative = False
        dec_val = dec_hours

    hours = trunc(dec_val)
    minutes_hrs = dec_val - hours

    minutes_mm = minutes_hrs * 60.0
    minutes_out = trunc(minutes_mm)
    seconds = (minutes_mm - minutes_out)*60.0

    if negative:
        hours = -hours
        return hours, minutes_out, seconds
    else:
        return hours, minutes_out, seconds
coordutils.py 文件源码 项目:astrobase 作者: waqasbhatti 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def hms_to_decimal(hours, minutes, seconds, returndeg=True):
    '''
    Converts from HH:MM:SS to a decimal value.

    if returndeg is True: returns decimal degrees
    if returndeg is False: returns decimal hours

    '''

    if hours > 24:

        return None

    else:

        dec_hours = fabs(hours) + fabs(minutes)/60.0 + fabs(seconds)/3600.0

        if returndeg:

            dec_deg = dec_hours*15.0

            if dec_deg < 0:
                dec_deg = dec_deg + 360.0
            dec_deg = dec_deg % 360.0
            return dec_deg
        else:
            return dec_hours
recipe-577113.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def adjust(xa, ya, x, y, xb, yb):
    global image
    if(image.getpixel((x,y)) == 0):
      d=math.fabs(xa-xb) + math.fabs(ya-yb)
      v=(image.getpixel((xa,ya)) + image.getpixel((xb,yb)))/2.0 \
         + (random.random()-0.5) * d * roughness
      c=int(math.fabs(v) % 256)
      image.putpixel((x,y), c)
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def abs(self):
        return self.__class__(math.fabs(self.__point[0]),
                              math.fabs(self.__point[1]),
                              math.fabs(self.__point[2]))
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def approx_equals(self, other, max_error=1e-15):
        return (math.fabs(self.lat().radians -
                          other.lat().radians) < max_error and
                math.fabs(self.lng().radians -
                          other.lng().radians) < max_error)
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def approx_equals(self, other, max_error=1e-14):
        return ((self.axis().angle(other.axis()) <= max_error and
                 math.fabs(self.height() - other.height()) <= max_error) or
                (self.is_empty() and other.height() <= max_error) or
                (other.is_empty() and self.height() <= max_error) or
                (self.is_full() and other.height() >= 2 - max_error) or
                (other.is_full() and self.height() >= 2 - max_error))
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def is_valid(self):
        return (math.fabs(self.lat().lo()) <= math.pi / 2.0 and
                math.fabs(self.lat().hi()) <= math.pi / 2.0 and
                self.lng().is_valid() and
                self.lat().is_empty() == self.lng().is_empty())
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def area(self):
        """Area in steradians."""
        if self.is_empty():
            return 0.0

        return self.lng().get_length() * math.fabs(
            math.sin(self.lat_hi().radians) -
            math.sin(self.lat_lo().radians)
        )
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def is_unit_length(p):
    return math.fabs(p.norm() * p.norm() - 1) <= 1e-15
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def approx_equals(self, other, max_error=1e-15):
        if self.is_empty():
            return other.get_length() <= max_error
        if other.is_empty():
            return self.get_length() <= max_error
        return (math.fabs(other.lo() - self.lo()) +
                math.fabs(other.hi() - self.hi()) <= max_error)
sphere.py 文件源码 项目:s2sphere 作者: sidewalklabs 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def from_point_pair(cls, a, b):
        assert math.fabs(a) <= math.pi
        assert math.fabs(b) <= math.pi
        if a == -math.pi:
            a = math.pi
        if b == -math.pi:
            b = math.pi
        if cls.positive_distance(a, b) <= math.pi:
            return cls(a, b, args_checked=True)
        else:
            return cls(b, a, args_checked=True)


问题


面经


文章

微信
公众号

扫码关注公众号