How to Use AIXIjs for General Reinforcement Learning Experiments

Feb 21, 2023 | Data Science

AIXIjs is a remarkable JavaScript framework that enables running General Reinforcement Learning (RL) agents directly in your browser. This tool is particularly adept at operating in complex environments that are partially observable, non-Markovian, and non-ergodic. If you are keen to explore the breadth of Bayesian RL agents, AIXIjs provides a seamless platform for experimentation. Let’s dive in to see how you can utilize this innovative tool effectively.

Setting Up Your Environment

Before we begin, ensure you are using a recent version of Chrome, as AIXIjs runs best under this browser for the complete experience.

Features of AIXIjs

AIXIjs comes equipped with a variety of agents and environments, including:

  • Agents:
    • Bayes (AIXI)
    • KSA (Square, Shannon, and Kullback-Leibler)
    • Thompson Sampling
    • MDL Agent
    • BayesExp
    • (Tabular) QLearning
    • SARSA
  • Environments:
    • Bandits
    • Finite-state MDPs
    • Gridworld POMDPs

Creating Your First Demo

Ready to experiment? Here’s how you can set up a basic simulation with AIXI on a Dispenser Gridworld. Think of building your simulation like constructing a LEGO castle; you need all the right pieces in the correct order to make it operational.


let config = /* ... */; // environment config; see src/config.js for examples
let env = new Gridworld(config); // construct environment
let options = /* ... */; // agent options; see src/config.js for examples
let agent = new BayesAgent(options); // construct agent
let trace = new BayesTrace(); // accumulator for performance and history
let a = null; // action
let e = env.generatePercept(); // percept main loop

for (let t = 0; t < options.steps; t++) {
    trace.log(agent, env, a, e); // log info to trace
    a = agent.selectAction(e); // agent computes its policy and selects an action
    env.perform(a); // pass this action to the environment and compute dynamics
    e = env.generatePercept(); // environment emits a percept
    agent.update(a, e); // agent learns from action and resulting percept
}

// now do what you want with the trace -- it has logged all the relevant data

In this code snippet, you first configure the environment and agent. Then you run a loop where your agent constantly interacts with the environment, learns from it, and keeps track of its performance.

Running Experiments

To run multiple simulations, you can use the helper function demo.experiment(...configs,runs). Here’s how to initiate an experiment:

  1. Open the console in Chrome (Ctrl+Shift+I on Linux).
  2. Input your experiment configuration.
  3. After running the simulations, a download link for results.json will appear at the bottom of the DOM.

For data analytics enthusiasts, you’ll also find an iPython notebook in experiments/analysis.ipynb to help visualize your results.

Troubleshooting Tips

As with any new tool, you may encounter some hiccups along the way. Here are a few troubleshooting tips:

  • Browser Compatibility: Ensure you are running the latest version of Chrome for the best experience.
  • Configuration Issues: Double-check your environment and agent configuration variables in src/config.js.
  • JSON Download: If the download link for results.json does not appear, try refreshing the page and running the experiment again.
  • For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox