def negativeExamples(task_planner, fe, start_state, esdc, ggg, name, labeled_states): results = task_planner.find_plan(start_state, [ggg], save_state_tree=True, search_depth_event=4) observations = [] labeled_actions = [decompile([(a, s)]) for a, s in labeled_states] for i, (cost, state, ggg) in enumerate(results): state_sequence = task_planner.state_sequence(state) actions = [decompile([(a, s)]) for a, s in state_sequence] overlap = False for a in actions: if a in labeled_actions: overlap = True #if not overlap or len(actions) != len(labeled_actions): if labeled_states[-1][1] != state_sequence[-1][1]: features = fe.features(ggg, ggg.factors[0], state_sequence) example_id = "%s_%d_neg" % (name, i) obs = dataset.ContinuousObservation(example_id, False, False, features, sdcs=[esdc]) observations.append(obs) return observations
def sendInstructionToCfb(self): entry = self.instructionModel.selectedEntry() esdc, ggg = self.recipe_manager.make_ggg_for_instruction(entry.text) self.costFunctionBrowser.gggs = [ggg] self.costFunctionBrowser.esdcs = [esdc] self.costFunctionBrowser.followCommand(entry.text, state=entry.start_state, esdcs=[esdc]) for plan in self.costFunctionBrowser.plansList: result = self.recipe_manager.sequence(plan) string = planningLanguage.decompile(result) print "planning language", string
def inferPlan(self): print "follow command" recipe_text = str(self.recipeTextEdit.toPlainText()) sequence = self.recipe_manager.find_plan(recipe_text, self.start_state) entries = [] for i, (instruction, states, cost) in enumerate(sequence): if i == 0: start_state = self.start_state else: start_state = sequence[i - 1][1][-1][1] annotation = planningLanguage.decompile(states) entry = instructionModel.Entry(i, instruction.text, annotation, start_state, cost) entries.append(entry) self.instructionModel.setData(entries)
def evaluateEndToEnd(self, targetRecipe, useBeam=True): #A list of (planningLanguage, is_correct) tuples. Used mainly for GUI completePath = [] self.totalCount += 1 model_fname = "kitchenModel_1.5.pck" training_set = pickle_util.load("training.pck") rm = recipeManager.RecipeManager(model_fname) pl = planningLanguage.PlanningLanguage() print "\nEvaluating (end-to-end):", targetRecipe.name recipeText = targetRecipe.instruction_text initialState = targetRecipe.start_state if useBeam: inferredPlan = rm.find_beam_plan(recipeText, initialState) else: inferredPlan = rm.find_plan(recipeText, initialState) print "\ninferred", inferredPlan actualEndState = inferredPlan[-1][1][-1][1] print "\ndesired states", targetRecipe.states desiredEndState = targetRecipe.states[-1][-1][1] plInferredPath = "" for i in inferredPlan: plInferredPath = plInferredPath + " | " + planningLanguage.decompile( i[1]) print "\nPL inferred:", plInferredPath plActual = "" for i in targetRecipe.instructions: plActual = plActual + " | " + i[1] print "\nPL Desired:", plActual, "\n" #print desiredEndState #print "end state", actualEndState if desiredEndState == actualEndState: self.successCount += 1 print "\n\nResults for the End-to-End evaluation for :", targetRecipe.name print "Success" else: print "\nResults for the End-to-End evaluation for :", targetRecipe.name print "Failure" return 0
def evaluateInstructions(self, targetRecipe): #Can a single instruction be interpreted as multiple instructions? Does it even matter? model_fname = "kitchenModel_1.5.pck" rm = recipeManager.RecipeManager(model_fname) pl = planningLanguage.PlanningLanguage() tc = 0 sc = 0 nsc = 0 #A list of (planningLanguage, is_correct) tuples. Used mainly for GUI completePath = [] print "Evaluating (instruction-level): " + targetRecipe.name for i in range(len(targetRecipe.instructions)): self.totalCount += 1 tc += 1 instruction = targetRecipe.instructions[i] #print "instruction", instruction initialState = targetRecipe.idx_to_start_state(i) instructionInferredPlan = rm.find_plan(instruction[0], initialState) desiredPlan = pl.compileAnnotation(instruction[1], initialState) desiredEndState = desiredPlan[-1][1] if len(instructionInferredPlan) == 0: #print "Zero length instruction for:", instruction if len(desiredPlan) == 1: if desiredPlan[-1][0].name == "noop": self.noopSuccessCount += 1 nsc += 1 completePath.append(("| noop()", True)) else: completePath.append(("None", False)) else: completePath.append(("None", False)) else: #print "inferred plan", instructionInferredPlan actualEndState = instructionInferredPlan[-1][1][-1][1] #print "actualEndState", actualEndState #plInferredPath = planningLanguage.decompile(instructionInferredPlan[-1][1]) plInferredPath = "" for i in instructionInferredPlan: plInferredPath = plInferredPath + " | " + planningLanguage.decompile( i[1]) if desiredEndState == actualEndState: self.successCount += 1 sc += 1 print instructionInferredPlan completePath.append((plInferredPath, True)) else: completePath.append((plInferredPath, False)) print "State is not the same for instruction", instruction print "Inferred path was: ", planningLanguage.decompile( instructionInferredPlan[0][1]) ## print "Desired mixing bowl:", desiredEndState.mixing_bowl ## print "Actual mixing bowl:", actualEndState.mixing_bowl print "\n" print "\n\nResults for the instruction-level evaluation of :", targetRecipe.name print "Total Instructions:", tc, "\nSuccess:", sc print "Noop Success:", nsc print "Failures:", tc - (sc + nsc), "\n\n" return completePath