{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Predictive power metrics", "id": "eb9fb4a1a68e633" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "!pip install amlgym", "id": "3a2c1c2a35c2e0f2" }, { "metadata": {}, "cell_type": "markdown", "source": "Learn a model to be evaluated:", "id": "243b51efc337c73b" }, { "cell_type": "code", "execution_count": null, "id": "initial_id", "metadata": { "collapsed": true }, "outputs": [], "source": [ "from amlgym.benchmarks import get_domain_path, get_trajectories_path\n", "from amlgym.algorithms import get_algorithm\n", "from amlgym.util.util import empty_domain\n", "\n", "# Get learning algorithm\n", "learner = get_algorithm('nolam')\n", "\n", "# Get an input domain with no preconditions and effects\n", "domain_ref_path = get_domain_path('blocksworld')\n", "domain_empty_path = empty_domain(domain_ref_path)\n", "\n", "# Get a set of trajectories to learn from\n", "traj_paths = get_trajectories_path('blocksworld')\n", "\n", "# Learn a domain model\n", "model = learner.learn(domain_empty_path, traj_paths)" ] }, { "metadata": {}, "cell_type": "markdown", "source": "Print the learned model", "id": "c37e9a2fcb11330c" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "print(model)", "id": "6ca1abc82297796c" }, { "metadata": {}, "cell_type": "markdown", "source": "Save the learned model to a file:", "id": "e57ba7ed0e528f13" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "domain_eval_path = 'domain_learned.pddl'\n", "with open(domain_eval_path, 'w') as f:\n", " f.write(model)" ], "id": "180a5e01e627481f" }, { "metadata": {}, "cell_type": "markdown", "source": "Get the test set of states necessary to evaluate predicted applicability and predicted effects metrics:", "id": "c2d26df0bdcd4500" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.benchmarks import get_problems_path, get_test_states\n", "\n", "test_states = get_test_states('blocksworld', kind='predictive_power')\n", "problem_paths = get_problems_path('blocksworld', kind='predictive_power')\n", "\n", "# get first problem file path\n", "problem_path = problem_paths[0]\n", "\n", "# get test set of state for a single problem\n", "test_states = test_states[problem_path.split('/')[-1]]" ], "id": "7442d5009738bfdc" }, { "metadata": {}, "cell_type": "markdown", "source": "Create a simulator defined by the learned domain model and an environment simulator defined by a reference domain model", "id": "bbfdd327bae98dd0" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.modeling.UPEnv import UPEnv\n", "simulator_learned = UPEnv(domain_eval_path, problem_path)\n", "simulator_ref = UPEnv(domain_ref_path, problem_path)" ], "id": "f23f15d513a88d04" }, { "metadata": {}, "cell_type": "markdown", "source": "Evaluate the predicted applicability and predicted effects metrics with a learned domain simulator and environment simulator.", "id": "4bba85de1fe660c" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.metrics import predictive_power\n", "predictive_metrics = predictive_power(simulator_learned,\n", " simulator_ref,\n", " test_states)\n", "print(predictive_metrics)" ], "id": "5cb4c2dae24c8453" } ], "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 }