if (not feasibleActions) or len(moveSeq)>wordLength: break print "Run: %d\t Iteration: %d\t Word: %d\t factor (%d|%d)" %(i, numIter, t, len(currFactors), len(allowedFactors)) while feasibleActions: # If there are no feasible actions available if not feasibleActions: break chosenAction = random.choice(list(feasibleActions)) tentativeMoveSeq = moveSeq+[chosenAction] # Compute all k-subsequences tempFactors = generateKSubsequences(tentativeMoveSeq, 2) # Check if the factors generated are subset of allowed factors if tempFactors.issubset(allowedFactors): currState = getNextPosition(arenaDimensions, currState, chosenAction) currFactors.update(tempFactors) moveSeq = deepcopy(tentativeMoveSeq) numIter += 1 numFactors.append(len(currFactors)) break else: feasibleActions.remove(chosenAction) # Check if learning is complete or not if currFactors == allowedFactors: learningComplete = True
def computeSPkGrammar(self, kval, moveSeq): '''Compute the SP-k grammar from the input move sequence''' return generateKSubsequences(moveSeq, kval)
break print "Run: %d\t Iteration: %d\t Word: %d\t factor (%d|%d)" % ( i, numIter, t, len(currFactors), len(allowedFactors)) while feasibleActions: # If there are no feasible actions available if not feasibleActions: break chosenAction = random.choice(list(feasibleActions)) tentativeMoveSeq = moveSeq + [chosenAction] # Compute all k-subsequences tempFactors = generateKSubsequences(tentativeMoveSeq, 2) # Check if the factors generated are subset of allowed factors if tempFactors.issubset(allowedFactors): currState = getNextPosition(arenaDimensions, currState, chosenAction) currFactors.update(tempFactors) moveSeq = deepcopy(tentativeMoveSeq) numIter += 1 numFactors.append(len(currFactors)) break else: feasibleActions.remove(chosenAction) # Check if learning is complete or not if currFactors == allowedFactors: