def compute_features(self, state, ggg, factors): """ Computes features for the unmodified annotation. """ factor_to_fnames = {} factor_to_fvalues = {} if factors == None: factors = [ ggg.graph.get_factor_with_id(fid) for fid in ggg.graph.get_factor_id_list() ] for factor in factors: esdc = ggg.factor_to_esdc(factor) r_words = [w.text.lower() for w in esdc.r] + ["null"] words = [w.lower() for w in esdc.text.split()] + ["null"] fdict = self.factor_features(factor, state, ggg) base_features = merge(fdict, add_prefix(esdc.type + "_", fdict)) fdict = merge( base_features, add_prefix("r_", add_word_features(base_features, r_words))) fdict = merge(fdict, add_word_features(base_features, words)) factor_to_fnames[factor.id] = fdict.keys() factor_to_fvalues[factor.id] = fdict.values() return factor_to_fvalues, factor_to_fnames
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
def object_landmark_features(self, agent, f_prism, r_words, l_prism): result_dict = { "dist_f_l": sf.math2d_dist(f_prism.centroid2d(), l_prism.centroid2d()) } result_dict = add_word_features(result_dict, r_words) return result_dict
def path_landmark_features(self, f_path, r_words, l_grounding): if sf.math2d_dist(f_path.points_pts[-1], l_grounding.centroid2d) < 4: fdict = {"ends_close": 1} else: fdict = {"ends_close": 0} fdict = add_word_features(fdict, r_words) return fdict
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 object_object_averages(self, agent, f_grounding, r_words, l_grounding): """ Compute features along the entire path of the figure and landmark. """ start_t = min(f_grounding.start_t, l_grounding.start_t) end_t = max(f_grounding.end_t, l_grounding.end_t) step_size = (end_t - start_t) / 5.0 fdicts = [] if step_size == 0: step_size = 1 # iterate at least once if start_t == end_t: end_t = end_t + step_size for t in arange(start_t, end_t + step_size, step_size): f_prism = f_grounding.prismAtT(t) l_prism = l_grounding.prismAtT(t) #print "f_prism = ", f_prism #print "l_prism = ", l_prism fdict = self.object_landmark_features(agent, f_prism, r_words, l_prism) #print "landmark supports figure", [(key, value) for key, value in fdict.iteritems() # if "F_3dSupportsLandmarkFigure" in key] #print "landmark supports figure", [(key, value) for key, value in fdict.iteritems() # if "F_3dSupportsFigureLandmark" in key] fdicts.append(fdict) merged = average_dicts(fdicts) max_dict = {} for key, value in merged.iteritems(): farray = [fdict[key] for fdict in fdicts] max_dict["max_%s" % key] = max(farray) #merged = merge(merged, max_dict) #averaged_dict = add_prefix("avg_", merged) averaged_dict = max_dict #print "avg landmark supports figure", [(key, value) for key, value in averaged_dict.iteritems() # if "F_3dSupportsLandmarkFigure" in key] #print "avg landmark supports figure", [(key, value) for key, value in averaged_dict.iteritems() # if "F_3dSupportsFigureLandmark" in key] result_dict = add_word_features(averaged_dict, r_words) return result_dict