示例#1
0
文件: ACS2.py 项目: masterchef8/ACS2
def apply_ga(aset: list, t: int, pop: list):
    sumNum = 0
    sumTgaN = 0
    for CL in aset:
        sumTgaN += CL.tga * CL.num
        sumNum += CL.num
    if (t - sumTgaN) / sumNum > cons.thetaGA:
        for CL in aset:
            CL.tga = t
        parent1 = select_offspring(aset)
        parent2 = select_offspring(aset)

        child1 = Classifier(parent1)
        child2 = Classifier(parent2)

        child1.num += 1
        child2.num += 1

        child1.exp += 1
        child2.exp += 1

        apply_ga_mutation(child1)
        apply_ga_mutation(child2)

        if random() < cons.x:
            apply_crossover(child1, child2)
            child1.r = (parent1.r + parent2.r) / 2
            child2.r = (parent1.r + parent2.r) / 2

            child1.q = (parent1.q + parent2.q) / 2
            child2.q = (parent1.q + parent2.q) / 2
        child1.q /= 2
        child2.q /= 2

        delete_classifier(aset, pop)
        if child1.condition != [cons.symbol] * cons.lenCondition:
            add_ga_classifier(aset, pop, child1)

        if child2.condition != [cons.symbol] * cons.lenCondition:
            add_ga_classifier(aset, pop, child2)
示例#2
0
文件: ACS2.py 项目: masterchef8/ACS2
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