def check_pruning_condition(self, list_of_cp_key): demonstrations_in_cluster = [self.map_cp2demonstrations[cp] for cp in list_of_cp_key] num_demonstrations = len(set(demonstrations_in_cluster)) num_total_demonstrations = len(self.list_of_demonstrations) data_representation = num_demonstrations / float(num_total_demonstrations) weighted_data_representation = pruning.weighted_score(self.list_of_demonstrations, list(set(demonstrations_in_cluster))) val = weighted_data_representation if constants.WEIGHTED_PRUNING_MODE else data_representation print str(data_representation), len(list_of_cp_key) print str(weighted_data_representation), len(list_of_cp_key) return val <= self.representativeness
def check_pruning_condition(self, list_of_cp_key): demonstrations_in_cluster = [ self.map_cp2demonstrations[cp] for cp in list_of_cp_key ] num_demonstrations = len(set(demonstrations_in_cluster)) num_total_demonstrations = len(self.list_of_demonstrations) data_representation = num_demonstrations / float( num_total_demonstrations) weighted_data_representation = pruning.weighted_score( self.list_of_demonstrations, list(set(demonstrations_in_cluster))) val = weighted_data_representation if constants.WEIGHTED_PRUNING_MODE else data_representation print str(data_representation), len(list_of_cp_key) print str(weighted_data_representation), len(list_of_cp_key) return val <= self.representativeness
def cluster_pruning(self): for cluster in self.map_level1_cp.keys(): cluster_list_of_cp = self.map_level1_cp[cluster] cluster_demonstrations = [] for cp in cluster_list_of_cp: cluster_demonstrations.append(self.map_cp2demonstrations[cp]) data_representation = float(len(set(cluster_demonstrations))) / float(len(self.list_of_demonstrations)) weighted_data_representation = pruning.weighted_score( self.list_of_demonstrations, list(set(cluster_demonstrations)) ) print str(cluster) + ": " + str(data_representation), " " + str(len(cluster_list_of_cp)) print str(cluster) + ":w " + str(weighted_data_representation), " " + str(len(cluster_list_of_cp)) val = weighted_data_representation if constants.WEIGHTED_PRUNING_MODE else data_representation if val <= self.representativeness: print "Pruned" new_cluster_list = cluster_list_of_cp[:] print "Pruned cluster" for cp in cluster_list_of_cp: self.list_of_cp.remove(cp) new_cluster_list.remove(cp) self.map_level1_cp[cluster] = new_cluster_list predictions = [] filtered_changepoints = None inv_map = {v: k for k, v in constants.alphabet_map.items()} for cluster in self.map_level1_cp: cluster_list_of_cp = self.map_level1_cp[cluster] for cp in cluster_list_of_cp: predictions.append(inv_map[cluster]) filtered_changepoints = utils.safe_concatenate( filtered_changepoints, utils.reshape(self.changepoints[cp]) ) predictions = np.array(predictions) self.save_cluster_metrics(filtered_changepoints, predictions, "level1")
def cluster_pruning(self): for cluster in self.map_level1_cp.keys(): cluster_list_of_cp = self.map_level1_cp[cluster] cluster_demonstrations = [] for cp in cluster_list_of_cp: cluster_demonstrations.append(self.map_cp2demonstrations[cp]) data_representation = float(len(set(cluster_demonstrations))) / float(len(self.list_of_demonstrations)) weighted_data_representation = pruning.weighted_score(self.list_of_demonstrations, list(set(cluster_demonstrations))) print str(cluster) + ": " + str(data_representation), " " + str(len(cluster_list_of_cp)) print str(cluster) + ":w " + str(weighted_data_representation), " " + str(len(cluster_list_of_cp)) val = weighted_data_representation if constants.WEIGHTED_PRUNING_MODE else data_representation if val <= self.representativeness: print "Pruned" new_cluster_list = cluster_list_of_cp[:] print "Pruned cluster" for cp in cluster_list_of_cp: self.list_of_cp.remove(cp) new_cluster_list.remove(cp) self.map_level1_cp[cluster] = new_cluster_list predictions = [] filtered_changepoints = None inv_map = {v:k for k, v in constants.alphabet_map.items()} for cluster in self.map_level1_cp: cluster_list_of_cp = self.map_level1_cp[cluster] for cp in cluster_list_of_cp: predictions.append(inv_map[cluster]) filtered_changepoints = utils.safe_concatenate(filtered_changepoints, utils.reshape(self.changepoints[cp])) predictions = np.array(predictions) self.save_cluster_metrics(filtered_changepoints, predictions, 'level1')
def cluster_pruning(self): for cluster in self.map_level1_cp.keys(): cluster_list_of_cp = self.map_level1_cp[cluster] cluster_demonstrations = [] for cp in cluster_list_of_cp: cluster_demonstrations.append(self.map_cp2demonstrations[cp]) data_representation = float(len(set(cluster_demonstrations))) / float(len(self.list_of_demonstrations)) weighted_data_representation = pruning.weighted_score(self.list_of_demonstrations, list(set(cluster_demonstrations))) print str(cluster) + ": " + str(data_representation), " " + str(len(cluster_list_of_cp)) print str(cluster) + ":w " + str(weighted_data_representation), " " + str(len(cluster_list_of_cp)) val = weighted_data_representation if constants.WEIGHTED_PRUNING_MODE else data_representation if val <= self.representativeness: print "Pruned" new_cluster_list = cluster_list_of_cp[:] print "Pruned cluster" for cp in cluster_list_of_cp: self.list_of_cp.remove(cp) new_cluster_list.remove(cp) self.map_level1_cp[cluster] = new_cluster_list