Skip to main content

Accuracy-based Learning Classifier Systems with Rule Combining

Project description

XCS-RC

Accuracy-based Learning Classifier Systems with Rule Combining mechanism, shortly XCS-RC for Python3, loosely based on Martin Butz's XCS Java code (2001). Read my PhD thesis here for the complete algorithmic description.

Rule Combining is novel function that employs inductive reasoning, replacing all Darwinian genetic operation like mutation and crossover. It can handle binaries and real, reaching better correctness rate and population size quicker than several XCS instances. My earlier papers comparing them can be obtained at here and here.


Relevant links


Installation

pip install xcs-rc

Initialization

import xcs_rc
agent = xcs_rc.Agent()

Classic Reinforcement Learning cycle

# input: binary string, e.g., "100110" or decimal array
state = str(randint(0, 1))

# pick methods: 0 = explore, 1 = exploit, 2 = explore_it
action = agent.next_action(state, pick_method=1)

# determine reward and apply it, e.g.,
reward = agent.maxreward if action == int(state[0]) else 0.0
agent.apply_reward(reward)

Partially Observable Markov Decision Process (POMDP) environment

# create env and agent
env = xcs_rc.MarkovEnv('maze4')  # maze4 is built-in
env.add_agents(num=1, tcomb=100, xmax=50)
agent = env.agents[0]

for episode in range(8000):
    steps = env.one_episode(pick_method=2)  # returns the number of taken steps

Data classification

agent.train(X_train, y_train)
cm = agent.test(X_test, y_test)  # returns the confusion matrix
preds, probs = agent.predict(X)  # returns lists of predictions and probabilities

Print population, save it to CSV file, or use append mode

agent.pop.print(title="Population")
agent.save('xcs_population.csv', title="Final XCS Population")
agent.save('xcs_pop_every_100_cycles.csv', title="Cycle: ###", save_mode='a')

Finally, inserting rules to population

# automatically load the last set (important for append mode)
agent.load("xcs_population.csv", empty_first=True)
agent.pop.add(my_list_of_rules)  # from a list of classifiers

Main Parameters

XCS-RC Parameters

  • tcomb: combining period, number of learning cycles before the next rule combining
  • predtol: prediction tolerance, maximum difference between two classifiers to be combined
  • prederrtol: prediction error tolerance, threshold for deletion of inappropriately combined rules

How to Set

agent.tcomb = 50 # perform rule combining every 50 cycles
agent.predtol = 20.0 # combines rules whose prediction value differences <= 20.0
agent.prederrtol = 10.0 # remove if error > 10.0, after previously below it

Parameters from original XCS

  • all related to mutation and crossover is removed
  • the others are kept and accessible (e.g., agent.alpha = 0.15)

Results

Classical Problems: multiplexer and Markov environment:

Binary MP11-HIGH

Real MP6-HIGH

Markov Maze4

Flappy Bird from PyGame Learning Environment:

Flappy Bird XCS-RC plot

Flappy Bird XCS-RC youtube

Youtube: CartPole-v0 Benchmark from OpenAI Gym:

CartPole XCS-RC

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xcs-rc-1.1.9.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xcs_rc-1.1.9-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file xcs-rc-1.1.9.tar.gz.

File metadata

  • Download URL: xcs-rc-1.1.9.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for xcs-rc-1.1.9.tar.gz
Algorithm Hash digest
SHA256 6b1c0e01cc9df2fec8d24a1d723d63382a437f601df6c2a8be882d8bc2de6e8f
MD5 06d710342077a939a6f844a6b66d6c91
BLAKE2b-256 fc097061813aba81d00fa317261d992749d6e95295bd99538f33ffcede87c9c9

See more details on using hashes here.

File details

Details for the file xcs_rc-1.1.9-py3-none-any.whl.

File metadata

  • Download URL: xcs_rc-1.1.9-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for xcs_rc-1.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 804891ad25cd8b822b7b8be64a60b6e27f9059273e415522764c1ea9916186e2
MD5 653b70082d72cf0e72f07f0e732f5358
BLAKE2b-256 55149a4d9b1b28520c1332c8b96c9559880bffd311f8c3484714b273bb4dd5a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page