def testPlanningLanguageCompile(self): emptyState = kitchenState.KitchenState() emptyState.table.contains = [kitchenState.Ingredient(contains=["flour"], homogenous=True, amount="1/2 cup", physicalObject=PhysicalObject(prism_from_point(3, 1, 1, 2), lcmId = 5, tags=['Flour']))] planningObject = planningLanguage.PlanningLanguage() stateActionPair = planningObject.compileAnnotation("pour(flour)", emptyState) print stateActionPair
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 __init__(self, recipeName, recipeSource, ingredientsList, instructionsList): """ This constructor takes as params: recipeName - The name of the recipe as a string recipeSource - The source of the recipe ingredientsList, a list of tuples containing a string representation of that ingredient and a ingredient object, e.g. [("1/2 cup flour", Ingredient("flour", "1/2 cup"))] instructionsList - a list of tuples containing a string of a single 'instruction' and its corresponding annotation (collection of actions) as a string (for now). e.g. [("Mix flour and eggs", "Pour(flour), Pour(eggs), Mix()")] """ self.name = recipeName self.source = recipeSource self.is_training_set = None self.start_state = kitchenState.KitchenState() #build kitchen state kitchenTable = [] for i in ingredientsList: kitchenTable.append(i[1]) self.start_state.table.contains = kitchenTable self.ingredients = ingredientsList self.instructions = instructionsList self.pl = planningLanguage.PlanningLanguage() self.states = [] start_state = self.start_state for i in self.instructions: results = self.pl.compileAnnotation(i[1], start_state) self.states.append(results) start_state = results[-1][1] self.num_instructions = len(self.instructions)
def testPlanningLanguageEmpty(self): actualOutput = planningLanguage.PlanningLanguage() self.assertNotEqual(actualOutput, None)
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