def destPolygons(self): fvec = spatial_features_avs_polygon_polygon( tp([(0, 0), (1, 0), (1, 1), (0, 1)]), tp([(2, 0), (3, 0), (3, 1), (2, 1)]), 0) self.assertFalse(any(na.isnan(x) for x in fvec)) fvec = spatial_features_avs_polygon_polygon( tp([(0, 0), (1, 0), (1, 1), (0, 1)]), tp([(0, 0), (1, 0), (1, 1), (0, 1)]), 0) self.assertFalse(any(na.isnan(x) for x in fvec))
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)
def destFunkyTheta(self): p1_xy = [[10, 10, 11, 11], [50, 51, 51, 50]] p2_xy = [[20, 20, 21, 21], [30, 32, 32, 30]] fvec = spatial_features_avs_polygon_polygon(p1_xy, p2_xy, 0) print fvec
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
def destSameOrientedPolygons(self): polygon = [ [21.72099827, 40.789814], [21.22099828, 41.65583942], [22.26022877, 42.25583939], [22.76022875, 41.38981397], ] fvec = spatial_features_avs_polygon_polygon(tp(polygon), tp(polygon), 0) names = list(sfe_f_polygon_l_polygon_names()) print names, fvec self.assertFalse(any(na.isnan(x) for x in fvec))
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])