Beispiel #1
0
    def test_should_find_similar(self):
        # given
        cfg = Configuration(3, 2, encoder=RealValueEncoder(2))
        cl1 = Classifier(
            condition=Condition([UBR(0, 0), UBR(0, 3), UBR(0, 3)], cfg=cfg),
            action=0,
            effect=Effect([UBR(0, 3), UBR(0, 3), UBR(0, 3)], cfg=cfg),
            cfg=cfg
        )
        cl2 = Classifier(
            condition=Condition([UBR(0, 0), UBR(0, 3), UBR(0, 3)], cfg=cfg),
            action=0,
            effect=Effect([UBR(0, 3), UBR(0, 3), UBR(0, 3)], cfg=cfg),
            cfg=cfg
        )

        # then
        assert cl1 == cl2
Beispiel #2
0
 def cfg(self):
     return Configuration(classifier_length=2,
                          number_of_possible_actions=2,
                          encoder_bits=4)
Beispiel #3
0
 def cfg(self):
     return Configuration(classifier_length=2,
                          number_of_possible_actions=2,
                          encoder=RealValueEncoder(4))
Beispiel #4
0
    return metrics


if __name__ == '__main__':
    # Load desired environment
    chckb = gym.make('checkerboard-2D-3div-v0')

    # Create agent
    encoder = RealValueEncoder(resolution_bits=4)
    cfg = Configuration(chckb.observation_space.shape[0],
                        chckb.action_space.n,
                        encoder=encoder,
                        user_metrics_collector_fcn=_checkerboard_metrics,
                        epsilon=0.5,
                        do_ga=True,
                        theta_r=0.9,
                        theta_i=0.2,
                        theta_ga=100,
                        chi=0.5,
                        mu=0.15)

    agent = RACS(cfg)
    population, metrics = agent.explore_exploit(chckb, 100)

    # print reliable classifiers
    reliable = [cl for cl in population if cl.is_reliable()]
    for cl in reliable:
        logging.info(cl)

    # print metrics
Beispiel #5
0
    return metrics


if __name__ == '__main__':
    # Load desired environment
    rmpx = gym.make('real-multiplexer-3bit-v0')

    # Create agent
    encoder = RealValueEncoder(resolution_bits=5)
    cfg = Configuration(rmpx.observation_space.shape[0],
                        rmpx.action_space.n,
                        encoder=encoder,
                        user_metrics_collector_fcn=_rmpx_metrics,
                        epsilon=1.0,
                        do_ga=True,
                        theta_r=0.9,
                        theta_i=0.3,
                        theta_ga=100,
                        chi=0.5,
                        mu=0.15)

    agent = RACS(cfg)
    population, metrics = agent.explore_exploit(rmpx, 100)
    logging.info("Done")

    # print reliable classifiers
    reliable = [cl for cl in population if cl.is_reliable()]
    reliable = sorted(reliable, key=lambda cl: -cl.fitness)

    for cl in reliable[:10]:
Beispiel #6
0
import gym
# noinspection PyUnresolvedReferences
import gym_multiplexer

from lcs.agents.racs import Configuration, RACS

if __name__ == '__main__':
    # Load desired environment
    rmpx = gym.make('real-multiplexer-6bit-v0')

    # Create agent
    cfg = Configuration(rmpx.env.observation_space.shape[0],
                        2,
                        encoder_bits=3,
                        epsilon=1.0)
    agent = RACS(cfg)

    population, _ = agent.explore(rmpx, 10)