def gen_match_set(pop: list, percept: list): """ Generate a list of Classifier thats match current perception :param pop: :type pop: list :param percept: :type percept: list :return: :rtype: list """ ma = [] if time == 0 or len(pop) == 0: for i in range(cons.nbAction): newcl = Classifier() newcl.condition = [cons.symbol] * cons.lenCondition newcl.action = i newcl.effect = [cons.symbol] * cons.lenCondition newcl.exp = 0 newcl.t = time newcl.q = 0.5 pop.append(newcl) for c in pop: if does_match(c, percept): ma.append(c) return ma
def cover_triple(percept_: list, action: int, percept: list, t: int) -> Classifier: child = Classifier() for i in range(len(percept)): if percept_[i] != percept[i]: child.condition[i] = percept_[i] child.effect[i] = percept[i] child.action = action child.exp = 0 child.r = 0 child.aav = 0 child.alp = t child.tga = t child.t = t child.q = 0.5 child.num = 1 return child
def apply_mutation(cl: Classifier, perception: list): """ :type cl: Classifier :param cl: :type perception: list :param perception: :return: """ for i in range(len(cl.condition)): if rd.random() < cons.nu: if cl.condition[i] == cons.dontCare: cl.condition[i] = perception[i] else: cl.condition[i] = cons.dontCare if rd.random() < cons.nu: c = rd.choice([i for i in range(0, (cons.nbAction - 1))]) cl.action = c
def generate_covering_classifier(env, action): newcl = Classifier() newcl.condition = ['0'] * len(env) for i in range(len(env)): if rd.random() < cons.P_dontcare: newcl.condition[i] = cons.dontCare else: newcl.condition[i] = env[i] for i in range(len(action)): if action[i] is False: newcl.action = i newcl.prediction = cons.predictionIni newcl.predictionError = cons.predictionErrorIni newcl.fitness = cons.fitnessIni newcl.experience = 0 newcl.timeStamp = time newcl.actionSetSize = 1 newcl.numerosity = 1 return newcl