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


Python BaseUsage.distance方法代码示例

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


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

示例1: test_distance

# 需要导入模块: from cogent.core.usage import BaseUsage [as 别名]
# 或者: from cogent.core.usage.BaseUsage import distance [as 别名]
 def test_distance(self):
     """BaseUsage distance() should return dist between two BUs"""
     #absolute numbers, will normalize to calculate distance
     self.assertFloatEqual(BaseUsage('GC').distance(BaseUsage('AU')),1)
     self.assertFloatEqual(BaseUsage('AU').distance(BaseUsage('GC')),1)
     self.assertFloatEqual(BaseUsage('GCAU').distance(BaseUsage('AUAU')),.5)
     #should work even against dict with 'T's
     self.assertFloatEqual(BaseUsage('GCAU').distance(\
         BaseUsage({'A':2,'T':2,'C':0,'G':0,})),.5)
     #rounding error
     self.assertEqual(BaseUsage('ACG').distance(BaseUsage('CCGGAA')),0)
     #normalized - as in unit simplex
     ag = BaseUsage('AG')
     ag.normalize()
     uc = BaseUsage('UC')
     uc.normalize()
     self.assertFloatEqual(ag.distance(uc),1)
     self.assertFloatEqual(BaseUsage({'A':0.4,'G':0.1,'C':0.4,'U':0.1})\
     .distance(BaseUsage({'A':0.1,'G':0.4,'U':0.4,'C':0.1})),0.6)
     self.assertFloatEqual(BaseUsage({'A':0.25,'G':0.25,'C':0.25,'U':0.25})\
         .distance(BaseUsage({'A':0.25,'G':0.25,'U':0.25,'C':0.25})),0.0)
     self.assertFloatEqual(BaseUsage({'A':0.245,'G':0.255,'C':0.245,\
         'U':0.255}).distance(BaseUsage({'A':0.255,'G':0.245,'U':0.245,\
         'C':0.255})),0.02)
     self.assertFloatEqual(BaseUsage({'A':0.245,'G':0.255,'C':0.245,\
         'U':0.255}).distance(BaseUsage({'A':0.25,'G':0.25,'U':0.25,\
         'C':0.25})),0.01)
     self.assertFloatEqual(BaseUsage({'A':0.248,'G':0.252,'C':0.248,\
         'U':0.252}).distance(BaseUsage({'A':0.25,'G':0.25,'U':0.25,\
         'C':0.25})),0.004)
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:32,代码来源:test_usage.py


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