Пример #1
0
    def object_landmark_features(self, agent, f_prism, r_words, l_prism):
        result_dict = {}

        assert not isnan(l_prism.points_xy[0][0])
        assert not isnan(f_prism.points_xy[0][0])

        prism_dict = compute_fdict(sf.sfe_f_prism_l_prism_names(),
                                   sf.sfe_f_prism_l_prism(f_prism, l_prism, normalize=True))
        result_dict = merge(result_dict, prism_dict)

        ax, ay, agent_theta = agent.path.points_xytheta


        for name, theta in [("avs_theta_start", agent_theta[0]), ("avs_theta_end", agent_theta[-1]),
                            ("avs_theta_avg", na.mean(agent_theta))]:
            avs_dict = compute_fdict(sf.spatial_features_names_avs_polygon_polygon(),
                                     sf.spatial_features_avs_polygon_polygon(f_prism.points_xy,
                                                                             l_prism.points_xy,
                                                                             theta))

            result_dict = merge(result_dict, add_prefix(name, avs_dict))            
        #print "******************"
        #theta = agent_theta[0]
        theta = agent_theta[0]
        #print "agent theta", degrees(theta)
        #print "f_centroid", f_prism.centroid2d()
        #print "l_centroid", l_prism.centroid2d()
        if not array_equal(f_prism.centroid2d(), l_prism.centroid2d()):
            angle_btwn_points = sf.math2d_angle(na.array(f_prism.centroid2d()) - na.array(l_prism.centroid2d()))
            #print "angle between points", degrees(angle_btwn_points)
            angle = theta - angle_btwn_points - math.pi/4
            #print "angle", degrees(angle)
            quadrant = sf.math2d_angle_to_quadrant(angle)
            octant = sf.math2d_angle_to_octant(angle + math.pi/8)
            #print "quadrant", quadrant
            #print "******************"
        else:
            quadrant = -1
            octant = -1

            #result_dict["f_in_l_quadrant_%d" % quadrant] = 1
        result_dict["f_in_l_quadrant"] = quadrant
        for i in range(-1, 8):
            result_dict["f_in_l_octant_%d" % i] = 0
        result_dict["f_in_l_octant_%d" % octant] = 1


        result_dict = dict((f, v) for f, v in result_dict.iteritems() if (("avsg" not in f) and
                                                                          ("avsHeightExp" not in f) and
                                                                          ("avsResult" not in f)))


        result_dict = add_word_features(result_dict, r_words)


        return result_dict
Пример #2
0
    def testSupports2(self):
        f_prism = Prism.from_points_xy(
            array([[12.40321594, 11.89190306, 10.48174026, 10.99305313],
                   [50.60192082, 52.01208363, 51.50077075, 50.09060794]]), 0.0,
            2.0)
        l_prism = Prism.from_points_xy(
            array([[10.77335704, 10.26535702, 11.3045877, 11.81258772],
                   [51.37659439, 52.25647628, 52.85647637, 51.97659448]]),
            0.30952800960131738, 1.3382280096013166)

        mpl.gca().clear()
        mpl.gca().set_aspect("equal")

        #mpl.show()

        features = compute_fdict(
            sfe_f_prism_l_prism_names(),
            sfe_f_prism_l_prism(f_prism, l_prism, normalize=True))
        self.assertEqual(features["F_3dSupportsLandmarkFigure"], 0)
        self.assertEqual(features["F_3dSupportsFigureLandmark"], 1)
        self.assertEqual(features["F_3dIntersectsFigureLandmark"], 1)

        self.assertEqual(features["F_3dEndsHigherThanLandmarkFigure"], 0)
        self.assertEqual(features["F_3dEndsHigherThanFigureLandmark"], 1)

        self.assertEqual(features["F_3dStartsHigherThanLandmarkFigure"], 1)
        self.assertEqual(features["F_3dStartsHigherThanFigureLandmark"], 0)
Пример #3
0
    def testSupports1(self):
        f_prism = Prism.from_points_xy(
            array([[16.26972295, 17.58320551, 16.85879986, 15.5453173],
                   [47.84974226, 48.57414791, 49.88763048, 49.16322482]]), 0.0,
            2.0)
        l_prism = Prism.from_points_xy(
            array([[17.28494274, 16.78494273, 17.82417321, 18.32417321],
                   [48.70261888, 49.56864429, 50.16864428, 49.30261887]]),
            0.27844635713715404, 0.98183174233715431)

        mpl.gca().clear()
        mpl.gca().set_aspect("equal")
        #mpl.show()

        features = compute_fdict(
            sfe_f_prism_l_prism_names(),
            sfe_f_prism_l_prism(f_prism, l_prism, normalize=True))
        self.assertEqual(features["F_3dSupportsLandmarkFigure"], 0)
        self.assertEqual(features["F_3dSupportsFigureLandmark"], 1)
        self.assertEqual(features["F_3dIntersectsFigureLandmark"], 1)

        self.assertEqual(features["F_3dEndsHigherThanLandmarkFigure"], 0)
        self.assertEqual(features["F_3dEndsHigherThanFigureLandmark"], 1)

        self.assertEqual(features["F_3dStartsHigherThanLandmarkFigure"], 1)
        self.assertEqual(features["F_3dStartsHigherThanFigureLandmark"], 0)
Пример #4
0
    def destFromCorpus(self):
        f_prism = Prism(
            array([[8.20976285, 7.35040178, 12.13996339, 12.99932446],
                   [52.3373722, 54.04890265, 56.4537461, 54.74221565]]),
            0.44360731519999963, 0.8500074167999998)
        l_prism = Prism(
            array([[19.08576266, 20.43434719, 19.77759778, 18.42901326],
                   [34.78776701, 35.44451641, 36.79310093, 36.13635153]]), 0.0,
            2.0)
        agent_theta = [
            0.45318688, 0.44080626, 0.39198138, 0.26087461, 0.02694216,
            0.04905031
        ]

        features = compute_fdict(
            spatial_features_names_avs_polygon_polygon(),
            spatial_features_avs_polygon_polygon(f_prism.points_xy,
                                                 l_prism.points_xy,
                                                 agent_theta[0]))
        mpl.gca().set_aspect("equal")
        #mpl.show()

        for key, value in sorted(features.iteritems()):
            print key, value

        assert allclose(features["F_avsHeight_-1_0"], -1.2797392167521806)
        assert allclose(features["F_avsHeight_0_-1"], 0.96482147016613318)
        assert allclose(features["F_avsHeight_0_1"], 0.99831498193067569)
        assert allclose(features["F_avsHeight_1_0"], 1.3390039512081222)
Пример #5
0
    def np_features(self, f_words, object_grounding):
        """
        Compute features for a noun phrase, given a grounding.
        """
        assert not isnan(object_grounding.points_xy[0][0])


        result_dict = {}
        polygon_dict = compute_fdict(sf.flu_polygon_names(vectors(f_words)),
                                     sf.flu_polygon(vectors(f_words), object_grounding.points_xy, True))

        figure_i = self.add_landmark(object_grounding)
        result_dict = merge(result_dict, polygon_dict)


        if hasattr(object_grounding, "tags"):
            visible_objects = self._get_landmark_context(figure_i)
            lo_dict = language_object(f_words,
                                      visible_objects,
                                      object_grounding.tags)

            result_dict = merge(result_dict, lo_dict)


        return result_dict
Пример #6
0
    def path_landmark_features(self, f_path, r_words, l_grounding):
        fdict = compute_fdict(sf.sfe_f_path_l_polygon_names(),
                              sf.sfe_extract_f_path_l_polygon(f_path.points_xytheta,
                                                              l_grounding.points_xy,
                                                              normalize=True))

        fdict = add_word_features(fdict, r_words)
        return fdict
Пример #7
0
    def test_features(self):
        from spatial_feature_expected_results import results

        for result in results:
            fig_xyth = result["args"]["fig_xyth"]
            gnd_xy = result["args"]["gnd_xy"]
            result_dict = result["result"]

            feats_C = sfe_extract_f_path_l_polygon(fig_xyth,
                                                   gnd_xy,
                                                   normalize=True)
            names_C = sfe_f_path_l_polygon_names()

            fdict = compute_fdict(names_C, feats_C)
            for key, value in fdict.iteritems():
                expected_value = result_dict[key]
                assert_sorta_eq(value, expected_value)
Пример #8
0
    def testFunkyArguments(self):
        """
        Test that it returns the same values. 
        """
        otheta = 1.1752771158
        of_points_xy = [[
            19.08576266,
            20.43434719,
            19.77759778,
            18.42901326,
        ], [
            34.78776701,
            35.44451641,
            36.79310093,
            36.13635153,
        ]]
        ol_points_xy = [[
            19.08576266,
            20.43434719,
            19.77759778,
            18.42901326,
        ], [
            34.78776701,
            35.44451641,
            36.79310093,
            36.13635153,
        ]]

        result = None

        for i in range(0, 20):
            print "i", i
            fvec = compute_fdict(
                spatial_features_names_avs_polygon_polygon(),
                spatial_features_avs_polygon_polygon(of_points_xy,
                                                     ol_points_xy, otheta))
            if result == None:
                result = fvec
            else:
                for key in result.keys():
                    print key
                    self.assertEqual(result[key], fvec[key])
Пример #9
0
    def testSupports(self):
        f_prism = Prism.from_points_xy(
            array([[12.19116674, 11.65687213, 10.8115738, 11.34586841],
                   [49.87727769, 50.72257602, 50.18828141, 49.34298308]]), 0.0,
            2.0)
        l_prism = Prism.from_points_xy(
            array([[10.61577541, 10.11577543, 11.15500591, 11.6550059],
                   [50.24525845, 51.11128387, 51.71128384, 50.84525842]]),
            0.30936596999170651, 1.0127513551917064)

        mpl.gca().clear()
        mpl.gca().set_aspect("equal")

        #mpl.show()
        features = compute_fdict(
            sfe_f_prism_l_prism_names(),
            sfe_f_prism_l_prism(f_prism, l_prism, normalize=True))
        self.assertEqual(features["F_3dSupportsLandmarkFigure"], 0)
        self.assertEqual(features["F_3dSupportsFigureLandmark"], 0)
        self.assertEqual(features["F_3dIntersectsFigureLandmark"], 0)
Пример #10
0
    def testSameFigureAndLandmark(self):

        f_prism = Prism.from_points_xy(
            array([[21.72099827, 21.22099828, 22.26022877, 22.76022875],
                   [40.789814, 41.65583942, 42.25583939, 41.38981397]]),
            3.3273999996559184e-06, 0.70338871259999969)
        l_prism = Prism.from_points_xy(
            array([[21.72099827, 21.22099828, 22.26022877, 22.76022875],
                   [40.789814, 41.65583942, 42.25583939, 41.38981397]]),
            3.3273999996559184e-06, 0.70338871259999969)

        features = compute_fdict(
            sfe_f_prism_l_prism_names(),
            sfe_f_prism_l_prism(f_prism, l_prism, normalize=True))

        #mpl.show()

        self.assertEqual(features["F_3dSupportsLandmarkFigure"], 0)
        self.assertEqual(features["F_3dSupportsFigureLandmark"], 0)
        self.assertEqual(features["F_3dIntersectsFigureLandmark"], 1)
Пример #11
0
    def testNotOverlapping(self):
        fend = Prism.from_points_xy(
            array([[11.38086607, 11.11520079, 10.6916185, 10.95728378],
                   [50.18213065, 50.60571294, 50.34004767, 49.91646537]]), 0.0,
            2.0)
        lend = Prism.from_points_xy(
            array([[8.81022941, 8.31022943, 9.34945991, 9.8494599],
                   [52.6054371, 53.47146252, 54.07146249, 53.20543707]]),
            0.81463427695147927, 1.5180196621514792)

        features = compute_fdict(
            sfe_f_prism_l_prism_names(),
            sfe_f_prism_l_prism(fend, lend, normalize=True))

        self.assertEqual(math3d_higher_than(fend, lend), True)
        self.assertEqual(math3d_higher_than(lend, fend), False)
        self.assertEqual(math2d_overlaps(fend.points_xy, lend.points_xy),
                         False)
        self.assertEqual(math3d_intersect_prisms(fend, fend), True)

        self.assertEqual(features["F_3dSupportsLandmarkFigure"], 0)

        self.assertEqual(features["F_3dSupportsFigureLandmark"], 0)