标签:list eterm 它的 lis track class bsp obj multiple
dataassociator base类 enumerate_joint_hypotheses function 实现如下
1 @classmethod 2 def enumerate_joint_hypotheses(cls, hypotheses): 3 """Enumerate the possible joint hypotheses. 4 5 Create a list of all possible joint hypotheses from the individual 6 hypotheses and determine whether each is valid. 7 8 Parameters 9 ---------- 10 hypotheses : list of :class:`Hypothesis` 11 A list of all hypotheses linking predictions to detections, 12 including missed detections 13 14 Returns 15 ------- 16 joint_hypotheses : list of :class:`JointHypothesis` 17 A list of all valid joint hypotheses with a score on each 18 """ 19 20 # Create a list of dictionaries of valid track-hypothesis pairs 21 joint_hypotheses = [ 22 JointHypothesis({ 23 track: hypothesis 24 for track, hypothesis in zip(hypotheses, joint_hypothesis)}) 25 for joint_hypothesis in itertools.product(*hypotheses.values()) 26 if cls.isvalid(joint_hypothesis)] 27 28 return joint_hypotheses
hypotheses对象是一个字典,它的key是track,value是相对应的MultipleHypothesis。
这段代码实现的是从hypotheses。在这段代码中,有几个比较有意思的python用法。
1. itertools.product(*hypotheses.values())
*hypotheses.values() 中*是unpack的用法。这样,itertools.product的input argument就是(MultipleHypothesis_1, MultipleHypothesis_2, ..., MultipleHypothesis_n)。
itertools.product()实现的是Cartesian product of input iterables. MultipleHypothesis是一个iterable objects。所以,这个部分输出的结果就是MultipleHypothesis_1、MultipleHypothesis_2,..., MultipleHypothesis_n分别各选出一个hypothesis,然后组合出的所有可能结果。
2.cls.isvalid(joint_hypothesis)
cls.isvalid()是类的static function method. 它用来检查joint_hypothesis是否合法。itertools.product()输出的joint_hypothesis存在一个量测被同时分配给多个目标的情况,所以要通过cls.isvalid()选出合法的joint_hypothesis。
3. for track, hypothesis in zip(hypotheses, joint_hypothesis)
zip的第一个参数是一个字典,字典默认是一个iterable object,内容是字典中hypotheses所有的key,也就是对应的目标(航迹)。
dataassociator base类 enumerate_joint_hypotheses method简析
标签:list eterm 它的 lis track class bsp obj multiple
原文地址:https://www.cnblogs.com/IamHC/p/12261933.html