{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Active Algorithms", "id": "eb9fb4a1a68e633" }, { "metadata": {}, "cell_type": "markdown", "source": "AMLGym implements a random baseline for active learning in fully observable and deterministic environments.", "id": "1ac309b575ed4764" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "!pip install amlgym", "id": "3a2c1c2a35c2e0f2" }, { "metadata": {}, "cell_type": "markdown", "source": "Get an input domain with predicate/operator signatures and no preconditions and effects.", "id": "774218ec2666c651" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.benchmarks import get_domain_path\n", "from amlgym.util.util import empty_domain\n", "\n", "domain = 'blocksworld'\n", "domain_ref_path = get_domain_path(domain)\n", "input_domain_path = empty_domain(domain_ref_path)" ], "id": "67f9460df2d696a5" }, { "metadata": {}, "cell_type": "markdown", "source": "Create a simulator of a fully observable and deterministic environment.", "id": "da80e00d74f127a1" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from unified_planning.shortcuts import SequentialSimulator\n", "from unified_planning.io import PDDLReader\n", "from amlgym.benchmarks import get_problems_path\n", "\n", "problem_path = get_problems_path(domain, kind='learning')[0]\n", "problem = PDDLReader().parse_problem(domain_ref_path, problem_path)\n", "\n", "env = SequentialSimulator(problem=problem)" ], "id": "b9f57982d205380" }, { "metadata": {}, "cell_type": "markdown", "source": "Instantiate a random agent and learns a model by acting in the simulated environment for a maximum number of 100 steps. At each step, the agent attempts to execute an action and observes the resulting environment state. Notice that action executions can fail.", "id": "6b9bde8ba4fe1329" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.algorithms import get_algorithm\n", "\n", "learner = get_algorithm('RandomAgent', max_steps=40)\n", "model, trajectory = learner.learn(env, input_domain_path)" ], "id": "fd01879bb9546ea3" }, { "metadata": {}, "cell_type": "markdown", "source": "Print the learned model and produced trajectory.", "id": "3582699c5af52659" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "print(\"##################### Learned model #####################\")\n", "print(model)\n", "\n", "print(\"################# Generated trajectory ##################\")\n", "print(trajectory)" ], "id": "7063d567fa9b9075" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }