diff --git a/notebook_1.ipynb b/notebook_1.ipynb index 948248d..8bf189b 100644 --- a/notebook_1.ipynb +++ b/notebook_1.ipynb @@ -21,11 +21,22 @@ }, "colab": { "name": "notebook_1.ipynb", - "provenance": [] + "provenance": [], + "include_colab_link": true }, "accelerator": "GPU" }, "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, { "cell_type": "code", "metadata": { @@ -64,7 +75,7 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 289 + "height": 309 }, "outputId": "071a2d56-f9b7-4a6e-f026-176467e727a6" }, @@ -786,15 +797,338 @@ } ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "CeKA5XON5w1b", + "colab_type": "text" + }, + "source": [ + "## Download the dataset from the main website\n", + "https://www.dropbox.com/s/9i05v6yw1kbkup3/Feynman_without_units.tar.gz?dl=0" + ] + }, { "cell_type": "code", "metadata": { "id": "FPmFhwwXnSbJ", "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "outputId": "4d2dcbf8-53ed-46c7-9d27-d228190ce596" + }, + "source": [ + "!cd /content && curl 'https://ucd3ff70cd66e120740afd0dca77.dl.dropboxusercontent.com/cd/0/get/A7lbizfGye_MJiIyAeFPuIV6aj-Ajn9ooJkLoHutz_8Uj1JALzXbzdHee-IR-jLMtzFFJpUFwL8_iILQjEhGaxzAz1pBI76vSd1szbcvSyYiuA/file?_download_id=812773581487114473712942950240052852664169083740701356029081840937&_notify_domain=www.dropbox.com&dl=1' \\\n", + " -H 'authority: ucd3ff70cd66e120740afd0dca77.dl.dropboxusercontent.com' \\\n", + " -H 'upgrade-insecure-requests: 1' \\\n", + " -H 'dnt: 1' \\\n", + " -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' \\\n", + " -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \\\n", + " -H 'sec-fetch-site: cross-site' \\\n", + " -H 'sec-fetch-mode: navigate' \\\n", + " -H 'sec-fetch-dest: iframe' \\\n", + " -H 'referer: https://www.dropbox.com/' \\\n", + " -H 'accept-language: en-US,en;q=0.9,ar;q=0.8' \\\n", + " --compressed > with_units.gz" + ], + "execution_count": 73, + "outputs": [ + { + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "100 3911M 100 3911M 0 0 51.3M 0 0:01:16 0:01:16 --:--:-- 54.0M\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "_ncr6YDy5OuX", + "colab_type": "code", "colab": {} }, "source": [ - "" + "!cd /content && tar -xzf with_units.gz && cd /content/AI-Feynman/Code" + ], + "execution_count": 75, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pXAAM7-F7B47", + "colab_type": "text" + }, + "source": [ + "## Solver configurations " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "uTi8DWUB6mOZ", + "colab_type": "code", + "colab": {} + }, + "source": [ + "_CFG = {\n", + " \"dataset_path\" : \"/content/Feynman_with_units\",\n", + " \"operations_file\" : \"./14ops.txt\",\n", + " \"polynomial_degree\" : 3,\n", + " \"number_of_epochs\" : 100,\n", + " \"bruteforce_time\" : 20,\n", + " \"test_percentage\" : 0,\n", + "}" + ], + "execution_count": 80, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "day8oRZd584P", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import logging\n", + "import pathlib\n", + "from tabulate import tabulate\n", + "from pathlib import Path\n", + "\n", + "from S_run_aifeynman import run_aifeynman\n", + "\n", + "\n", + "\n", + "class RunAll:\n", + " \"\"\"\n", + " Run the solver on the whole dataset\n", + " \"\"\"\n", + "\n", + " def __init__(self, *, cfg):\n", + " logging.basicConfig(filename=\"output.log\", level=logging.DEBUG)\n", + " self.cfg = cfg\n", + " self.results = {}\n", + " self.run_solver()\n", + " self.print_results()\n", + " \n", + " \n", + " def print_results(self):\n", + " table = []\n", + " for file, sol in self.results.items():\n", + " table.append(sol[-1])\n", + " print(tabulate(\n", + " table,\n", + " headers=[\n", + " \"Average error\",\n", + " \"Cumulative error\",\n", + " \"Error\",\n", + " \"Symbolic expression\",\n", + " ],\n", + " )\n", + " )\n", + "\n", + " def run_solver(self):\n", + " path = Path(self.cfg[\"dataset_path\"])\n", + " for child in path.iterdir():\n", + " self.results[str(child).split(\"/\")[-1]] = run_aifeynman(\n", + " pathdir=str(path.resolve()) + \"/\",\n", + " filename=str(child).split(\"/\")[-1],\n", + " BF_try_time=int(self.cfg[\"bruteforce_time\"]),\n", + " BF_ops_file_type=Path(self.cfg[\"operations_file\"]),\n", + " polyfit_deg=int(self.cfg[\"polynomial_degree\"]),\n", + " NN_epochs=int(self.cfg[\"number_of_epochs\"]),\n", + " vars_name=[],\n", + " test_percentage=int(self.cfg[\"test_percentage\"]),\n", + " )\n", + "\n", + " logging.info(self.results)\n", + " print(self.results)\n", + " break\n" + ], + "execution_count": 82, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "RGCB0c4Y60SN", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "d5196c91-f32e-418b-f6a4-f3b209e52536" + }, + "source": [ + "%%time\n", + "RunAll(cfg=_CFG)\n", + " " + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[51.15902059069184, 20.675103111179986, '0.004022719301*exp((x0-x2))']\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[51.15902059069184, 20.675103111179986, '0.004022719301*exp((x0-x2))']\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[33.277483182721156, 22.1547566076253, 'sin(-3.141488536836+pi)']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[51.15902059069184, 20.675103111179986, '0.004022719301*exp((x0-x2))']\n", + "[55.05915604694043, 20.67484487176153, 'sin(0.004022721884*exp((x0-x2)))']\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[33.277483176683035, 22.154455877817387, 'tan(-3.141488536837+pi)']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[40.98223775998753, 21.183319681656723, 'tan(0.000804487112*x0)']\n", + "[51.15902059069184, 20.675103111179986, '0.004022719301*exp((x0-x2))']\n", + "[55.05915604694043, 20.67484487176153, 'sin(0.004022721884*exp((x0-x2)))']\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[33.277483176683035, 22.154455877817387, 'tan(-3.141488536837+pi)']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[40.98223775998753, 21.183319681656723, 'tan(0.000804487112*x0)']\n", + "[46.506651128358314, 17.822359130503216, 0.999762833118439]\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[33.277483176683035, 22.154455877817387, 'tan(-3.141488536837+pi)']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[40.98223775998753, 21.183319681656723, 'tan(0.000804487112*x0)']\n", + "[46.506651128358314, 17.822359130503216, 0.999762833118439]\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[33.277483176683035, 22.154455877817387, 'tan(-3.141488536837+pi)']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[40.98223775998753, 21.183319681656723, 'tan(0.000804487112*x0)']\n", + "[46.506651128358314, 17.822359130503216, 0.999762833118439]\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[33.277483176683035, 22.154455877817387, 'tan(-3.141488536837+pi)']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[40.98223775998753, 21.183319681656723, 'tan(0.000804487112*x0)']\n", + "[46.506651128358314, 17.822359130503216, 0.999762833118439]\n", + "[827.7908368114961, 15.818087729923782, '0.011310680850017867*exp(0.657313427369091*x0 - 0.329012690616457*x1 - 0.657628557578617*x2 + 0.05*(0.865498915782026*x0 - 2.598092660426)**3 - 0.19*(0.865498915782026*x0 - 2.598092660426)**2 - 0.03*(0.866102055832982*x1 - 2.59949521113202)**3 + 0.09*(0.866102055832982*x1 - 2.59949521113202)**2 - 0.05*(0.865730183707546*x2 - 2.59833480258971)**3 + 0.19*(0.865730183707546*x2 - 2.59833480258971)**2)']\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n", + "Checking polyfit \n", + "\n", + "Complexity RMSE Expression\n", + "[0.0, 22.237236710703904, '0']\n", + "[33.27106902340706, 22.154989285167847, 'asin(-9.869500746207+(pi*pi))']\n", + "[33.277483174076494, 22.15455540709694, 'asin(-3.141488536837+pi)']\n", + "[33.277483176683035, 22.154455877817387, 'tan(-3.141488536837+pi)']\n", + "[36.212641398803086, 21.686042400598424, '0.000796326710733263']\n", + "[37.46217224612712, 21.60140943610803, '0.000070125147*(x0*exp(x0))']\n", + "[37.86269260929867, 21.539933898458983, '0.000624807452*pi']\n", + "[38.22735211031243, 21.183541479121935, '0.000804488145*x0']\n", + "[40.98223775998753, 21.183319681656723, 'tan(0.000804487112*x0)']\n", + "[46.506651128358314, 17.822359130503216, 0.999762833118439]\n", + "[827.7908368114961, 15.818087729923782, '0.011310680850017867*exp(0.657313427369091*x0 - 0.329012690616457*x1 - 0.657628557578617*x2 + 0.05*(0.865498915782026*x0 - 2.598092660426)**3 - 0.19*(0.865498915782026*x0 - 2.598092660426)**2 - 0.03*(0.866102055832982*x1 - 2.59949521113202)**3 + 0.09*(0.866102055832982*x1 - 2.59949521113202)**2 - 0.05*(0.865730183707546*x2 - 2.59833480258971)**3 + 0.19*(0.865730183707546*x2 - 2.59833480258971)**2)']\n", + "Checking for brute force + \n", + "\n", + "Checking for brute force * \n", + "\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "lCDxpirtCgph", + "colab_type": "code", + "colab": {} + }, + "source": [ + " " ], "execution_count": null, "outputs": []