{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Syntactic similarity metrics", "id": "eb9fb4a1a68e633" }, { "metadata": {}, "cell_type": "markdown", "source": "AMLGym provides several measures for evaluation an action model w.r.t. a reference model or simulator.", "id": "1ac309b575ed4764" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "!pip install amlgym", "id": "3a2c1c2a35c2e0f2" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.metrics import print_metrics\n", "\n", "print_metrics()" ], "id": "5074d7d2f20b291f" }, { "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('rosame')\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": "93a7b7785b9cd873" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "print(model)", "id": "a54bbcad9ad6fe7f" }, { "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": "Syntactic similarity can be measured by means of precision and recall:", "id": "79155f5492207006" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.metrics import syntactic_precision\n", "precision = syntactic_precision(domain_eval_path, domain_ref_path)\n", "print(precision)" ], "id": "fd36b0d1fc890673" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ "from amlgym.metrics import syntactic_recall\n", "recall = syntactic_recall(domain_eval_path, domain_ref_path)\n", "print(recall)" ], "id": "17a95e4b15c731e8" } ], "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 }