예제 #1
0
    def testEqual(self):
        sis = SpanningIntervalSet([
            SpanningInterval(OP, Interval(OP, NINF, 3.0, OP),
                             Interval(CL, 1.0, PINF, OP), CL)
        ])

        self.assertEqual(sis, sis, True)
예제 #2
0
    def normalized(self):
        if self.isNormalized:
            return self

        jPrime = min_inf([self.j, self.l])
        kPrime = max_inf([self.k, self.i])
        gammaPrime = self.gamma and self.i != NINF
        deltaPrime = (self.delta and jPrime != PINF
                      and (lt_inf(self.j, self.l) or
                           (self.zeta and self.alpha and self.beta)))
        epsilonPrime = (self.epsilon and kPrime != NINF
                        and (gt_inf(self.k, self.i) or
                             (self.gamma and self.beta and self.alpha)))
        zetaPrime = self.zeta and self.l != PINF

        if (le_inf(self.i, jPrime) and le_inf(kPrime, self.l)
                and implies(eq_inf(self.i, jPrime), gammaPrime and deltaPrime)
                and implies(eq_inf(kPrime, self.l), epsilonPrime and zetaPrime)
                and implies(eq_inf(self.i, self.l),
                            (self.alpha and self.beta)) and self.i != PINF
                and jPrime != NINF and kPrime != PINF and self.l != NINF):
            return SpanningInterval(self.alpha,
                                    Interval(gammaPrime, self.i, jPrime,
                                             deltaPrime),
                                    Interval(epsilonPrime, kPrime, self.l,
                                             zetaPrime),
                                    self.beta,
                                    isNormalized=True)
        else:
            return emptySpanningInterval
예제 #3
0
 def destIntersect(self):
     """
     erased intersect because it's hard to implement correctly
     """
     sis = SpanningIntervalSet([
         SpanningInterval(OP, Interval(OP, NINF, 3.0, OP),
                          Interval(CL, 1.0, PINF, OP), CL)
     ])
     self.assertEqual(sis, sis.intersect(sis))
예제 #4
0
 def run():
     results = inference(model, approach("figure", "landmark"))
     print "results", results
     self.assertEqual(
         results,
         SpanningIntervalSet([
             SpanningInterval(CL, Interval(CL, 0.0, 3600.0, CL),
                              Interval(CL, 3600.0, 6300.0, CL), OP),
             SpanningInterval(CL, Interval(CL, 6300.0, 24800.0, CL),
                              Interval(CL, 24800.0, 31800.0, CL), OP)
         ]))
예제 #5
0
    def testSomething(self):
        si1 = SpanningInterval(CL, Interval(OP, NINF, 1.0, OP),
                               Interval(CL, 1.0, 1.0, CL), OP)
        si2 = SpanningInterval(OP, Interval(OP, NINF, 1.0, OP),
                               Interval(CL, 1.0, 1.0, CL), OP)

        self.assertEquals(si1.containsInterval(Interval(CL, 0, 1, OP)), True)
        self.assertNotEqual(si1, emptySpanningInterval)
        self.assertNotEqual(si1.normalized(), emptySpanningInterval)
        print "si1", si1.normalized()

        sis = SpanningIntervalSet([si1, si2])
예제 #6
0
    def union(si1, si2):
        if si1.alpha == si2.alpha and si1.beta == si2.beta:
            bigUnion = SpanningInterval(si1.alpha,
                                        Interval.span(si1.i1, si2.i1),
                                        Interval.span(si1.i2,
                                                      si2.i2), si1.beta)
            bigUnionNotInSi1 = si1.complement().intersectInterval(bigUnion)
            bigUnionNotInSi2 = si2.complement().intersectInterval(bigUnion)

            if (all([i.subset(si2) for i in bigUnionNotInSi1])
                    and all([i.subset(si1) for i in bigUnionNotInSi2])):
                return SpanningIntervalSet([bigUnion])

        return SpanningIntervalSet([si1, si2])
예제 #7
0
    def intersection(i1, i2):

        if i1.alpha == i2.alpha and i1.beta == i2.beta:
            if gt_inf(i1.i, i2.i):
                gamma = i1.gamma
            elif i1.i == i2.i:
                gamma = i1.gamma and i2.gamma
            elif lt_inf(i1.i, i2.i):
                gamma = i2.gamma
            else:
                raise ValueError()

            if lt_inf(i1.j, i2.j):
                delta = i1.delta
            elif i1.j == i2.j:
                delta = i1.delta and i2.delta
            elif gt_inf(i1.j, i2.j):
                delta = i2.delta
            else:
                raise ValueError()

            if gt_inf(i1.k, i2.k):
                epsilon = i1.epsilon
            elif i1.k == i2.k:
                epsilon = i1.epsilon and i2.epsilon
            elif lt_inf(i1.k, i2.k):
                epsilon = i2.epsilon
            else:
                raise ValueError()

            if lt_inf(i1.l, i2.l):
                zeta = i1.zeta
            elif i1.l == i2.l:
                zeta = i1.zeta and i2.zeta
            elif gt_inf(i1.l, i2.l):
                zeta = i2.zeta
            else:
                raise ValueError()

            return SpanningInterval(
                i1.alpha,
                Interval(gamma, max_inf([i1.i, i2.i]), min_inf([i1.j, i2.j]),
                         delta),
                Interval(epsilon, max_inf([i1.k, i2.k]), min_inf([i1.l, i2.l]),
                         zeta), i1.beta).normalized()

        else:
            return emptySpanningInterval
예제 #8
0
    def testFollow(self):
        map_fn = "%s/data/directions/direction_floor_3/direction_floor_3_small_filled.cmf" % TKLIB_HOME
        cluster_fn = "%s/data/directions/direction_floor_3/skels/direction_floor_3_skel.pck" % TKLIB_HOME
        gtruth_tag_fn = "%s/data/directions/direction_floor_3/tags/df3_small_tags.tag" % TKLIB_HOME
        assignment_fn = "%s/nlp/data/aaai_2010_smv/stefie10/assignment1.1.yaml" % TKLIB_HOME
        tagFile = tag_util.tag_file(gtruth_tag_fn, map_fn)
        tagFile.get_map()
        tagFile.get_tag_names()

        skeleton = carmen_map_skeletonizer.load(cluster_fn, map_fn)
        assignment = Assignment.load(assignment_fn, tagFile, skeleton)

        slowEntry = assignment.entries[0]

        model = modelForSituation(slowEntry.situation)
        print "model", model

        results = inference(model, following("figure", "landmark"))

        self.assertEqual(
            results,
            SpanningIntervalSet([
                SpanningInterval(CL, Interval(CL, 1100.0, 5700.0, OP),
                                 Interval(OP, 1100.0, 5700.0, CL), OP),
                SpanningInterval(CL, Interval(CL, 6200.0, 15900.0, OP),
                                 Interval(OP, 6200.0, 15900.0, CL), OP),
                SpanningInterval(CL, Interval(CL, 16000.0, 21000.0, OP),
                                 Interval(OP, 16000.0, 21000.0, CL), OP)
            ]))
예제 #9
0
    def complement(self):

        return SpanningIntervalSet([
            SpanningInterval(self.alpha, everything,
                             Interval(CL, NINF, self.k, not self.epsilon),
                             self.beta),
            SpanningInterval(self.alpha, everything,
                             Interval(not self.zeta, self.l, PINF, CL),
                             self.beta),
            SpanningInterval(self.alpha,
                             Interval(CL, NINF, self.i, not self.gamma),
                             everything, self.beta),
            SpanningInterval(self.alpha,
                             Interval(not self.delta, self.j, PINF, CL),
                             everything, self.beta),
            SpanningInterval(not self.alpha, everything, everything,
                             self.beta),
            SpanningInterval(self.alpha, everything, everything,
                             not self.beta),
            SpanningInterval(not self.alpha, everything, everything,
                             not self.beta),
        ])
예제 #10
0
    def span(i1, i2):
        j = min_inf([i1.j, i2.j])
        k = max_inf([i1.k, i2.k])
        delta = ((i1.delta and le_inf(i1.j, i2.j))
                 or (i2.delta and ge_inf(i1.j, i2.j)))
        epsilon = ((i1.epsilon and ge_inf(i1.k, i2.k))
                   or (i2.epsilon and le_inf(i1.k, i2.k)))

        return SpanningIntervalSet([
            SpanningInterval(i1.alpha, Interval(i1.gamma, i1.i, i1.j,
                                                i1.delta),
                             Interval(i1.epsilon, i1.k, i1.l, i1.zeta),
                             i1.beta),
            SpanningInterval(i1.alpha, Interval(i1.gamma, i1.i, j, delta),
                             Interval(epsilon, k, i1.l, i1.zeta), i1.beta),
            SpanningInterval(i1.alpha, Interval(i1.gamma, i1.i, j, delta),
                             Interval(epsilon, k, i2.l, i2.zeta), i2.beta),
            SpanningInterval(i2.alpha, Interval(i2.gamma, i2.i, j, delta),
                             Interval(epsilon, k, i1.l, i1.zeta), i1.beta),
            SpanningInterval(i2.alpha, Interval(i2.gamma, i2.i, j, delta),
                             Interval(epsilon, k, i2.l, i2.zeta), i2.beta)
        ])
예제 #11
0
 def largestInterval(self):
     return Interval(self.alpha, self.i1.i, self.i2.j, self.beta)
예제 #12
0
        elif allenRelation == allenRelations.iDuring:
            result = []
            for alpha2 in endStatus:
                for beta2 in endStatus:
                    result.append(
                        SpanningInterval(
                            alpha2,
                            Interval(self.alpha and alpha2 and self.gamma,
                                     self.i, PINF, CL),
                            Interval(CL, NINF, self.l, self.beta and not beta2
                                     and self.zeta), beta2))
            return SpanningIntervalSet(result)
        else:
            raise ValueError("Bad relation: " + ` allenRelation `)


emptySpanningInterval = SpanningInterval(OP,
                                         Interval(OP, 0, 0, OP),
                                         Interval(OP, 0, 0, OP),
                                         OP,
                                         isNormalized=True)
allIntervals = SpanningIntervalSet([
    SpanningInterval(OP, Interval(OP, NINF, PINF, OP),
                     Interval(OP, NINF, PINF, OP), OP),
    SpanningInterval(OP, Interval(OP, NINF, PINF, OP),
                     Interval(OP, NINF, PINF, OP), CL),
    SpanningInterval(CL, Interval(OP, NINF, PINF, OP),
                     Interval(OP, NINF, PINF, OP), OP),
    SpanningInterval(CL, Interval(OP, NINF, PINF, OP),
                     Interval(OP, NINF, PINF, OP), CL),
])
예제 #13
0
    def testCenter(self):
        self.assertEqual(Interval(OP, 1, 4, OP).center, 2.5)
        self.assertEqual(Interval(OP, -1, 3, OP).center, 1)

        self.assertEqual(Interval(OP, NINF, PINF, OP).center, 0)
예제 #14
0
    def testSubsetAndSuperset(self):
        self.containment(Interval(CL, 0, 1, CL),
                         Interval(CL, -1, 2, CL),
                         isSubset=True,
                         isSuperset=False)

        self.containment(Interval(CL, -1, 2, CL),
                         Interval(CL, 0, 1, CL),
                         isSubset=False,
                         isSuperset=True)

        self.containment(Interval(OP, 0, 1, OP),
                         Interval(CL, 0, 1, CL),
                         isSubset=True,
                         isSuperset=False)

        self.containment(Interval(CL, 0, 1, CL),
                         Interval(OP, 0, 1, OP),
                         isSubset=False,
                         isSuperset=True)
        self.containment(Interval(OP, 0, 1, OP),
                         Interval(CL, 0, 1, CL),
                         isSubset=True,
                         isSuperset=False)

        self.containment(Interval(CL, 0, 1, OP),
                         Interval(CL, 0, 1, CL),
                         isSubset=True,
                         isSuperset=False)

        self.containment(Interval(OP, 0, 1, CL),
                         Interval(CL, 0, 1, CL),
                         isSubset=True,
                         isSuperset=False)

        self.containment(Interval(CL, 0, 1, CL),
                         Interval(CL, 0, 1, CL),
                         isSubset=False,
                         isSuperset=True)

        self.containment(Interval(CL, 0, 1, CL),
                         Interval(CL, 0.5, 1.5, CL),
                         isSubset=False,
                         isSuperset=False)

        self.containment(Interval(CL, 0, 1, CL),
                         Interval(CL, 10, 11, CL),
                         isSubset=False,
                         isSuperset=False)

        self.containment(Interval(CL, 0.0, 1.0, CL),
                         Interval(CL, 0.0, 2.0, CL),
                         isSubset=True,
                         isSuperset=False)
예제 #15
0
    def testLength(self):
        self.assertEqual(Interval(OP, 1, 4, OP).length, 3)
        self.assertEqual(Interval(OP, -1, 3, OP).length, 4)

        self.assertEqual(Interval(OP, NINF, PINF, OP).length, PINF)
예제 #16
0
    def D(self, allenRelation):
        if allenRelation == allenRelations.equals:
            return SpanningIntervalSet([self])
        elif allenRelation == allenRelations.lessThan:
            result = []
            for alpha2 in endStatus:
                for beta2 in endStatus:
                    result.append(
                        SpanningInterval(
                            alpha2,
                            Interval(
                                not self.beta and not alpha2 and self.epsilon,
                                self.k, PINF, CL), everything, beta2))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.greaterThan:
            result = []
            for alpha2 in endStatus:
                for beta2 in endStatus:
                    result.append(
                        SpanningInterval(
                            alpha2, everything,
                            Interval(
                                CL, NINF, self.j, not self.alpha and not beta2
                                and self.delta), beta2))

            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.meets:
            result = []
            for beta2 in endStatus:
                result.append(
                    SpanningInterval(not self.beta, self.i2, everything,
                                     beta2))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.iMeets:
            result = []
            for alpha2 in endStatus:
                result.append(
                    SpanningInterval(alpha2, everything, self.i1,
                                     not self.alpha))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.overlaps:
            result = []
            for alpha2 in endStatus:
                for beta2 in endStatus:
                    result.append(
                        SpanningInterval(
                            alpha2,
                            Interval(self.alpha and not alpha2 and self.gamma,
                                     self.i, self.l, self.beta and alpha2
                                     and self.zeta),
                            Interval(not self.beta and beta2 and self.epsilon,
                                     self.k, PINF, CL), beta2))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.iOverlaps:
            result = []
            for alpha2 in endStatus:
                for beta2 in endStatus:
                    result.append(
                        SpanningInterval(
                            alpha2,
                            Interval(CL, NINF, self.j, not self.alpha
                                     and alpha2 and self.delta),
                            Interval(self.alpha and beta2 and self.gamma,
                                     self.i, self.l, self.beta and not beta2
                                     and self.zeta), beta2))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.starts:
            result = []
            for beta2 in endStatus:
                result.append(
                    SpanningInterval(
                        self.alpha, self.i1,
                        Interval(not self.beta and beta2 and self.epsilon,
                                 self.k, PINF, CL), beta2))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.iStarts:
            result = []
            for beta2 in endStatus:
                result.append(
                    SpanningInterval(
                        self.alpha, self.i1,
                        Interval(CL, NINF, self.l, self.beta and not beta2
                                 and self.zeta), beta2))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.finishes:
            result = []
            for alpha2 in endStatus:
                result.append(
                    SpanningInterval(
                        alpha2,
                        Interval(CL, NINF, self.j, not self.alpha and alpha2
                                 and self.delta), self.i2, self.beta))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.iFinishes:
            result = []
            for alpha2 in endStatus:
                result.append(
                    SpanningInterval(
                        alpha2,
                        Interval(self.alpha and not alpha2 and self.gamma,
                                 self.i, PINF, CL), self.i2, self.beta))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.during:
            result = []
            for alpha2 in endStatus:
                for beta2 in endStatus:
                    result.append(
                        SpanningInterval(
                            alpha2,
                            Interval(CL, NINF, self.j, not self.alpha
                                     and alpha2 and self.delta),
                            Interval(not self.beta and beta2 and self.epsilon,
                                     self.k, PINF, CL), beta2))
            return SpanningIntervalSet(result)
        elif allenRelation == allenRelations.iDuring:
            result = []
            for alpha2 in endStatus:
                for beta2 in endStatus:
                    result.append(
                        SpanningInterval(
                            alpha2,
                            Interval(self.alpha and alpha2 and self.gamma,
                                     self.i, PINF, CL),
                            Interval(CL, NINF, self.l, self.beta and not beta2
                                     and self.zeta), beta2))
            return SpanningIntervalSet(result)
        else:
            raise ValueError("Bad relation: " + ` allenRelation `)
예제 #17
0
 def testSpan(self):
     self.assertEqual(
         Interval.span(Interval(OP, 1, 4, OP), Interval(CL, 2, 6, CL)),
         Interval(OP, 1, 6, CL))