diff --git a/notebooks/Alhazen.ipynb b/notebooks/Alhazen.ipynb index 35092a84..091e25f4 100644 --- a/notebooks/Alhazen.ipynb +++ b/notebooks/Alhazen.ipynb @@ -235,6 +235,17 @@ "The calculator code is listed below." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from math import tan as rtan\n", + "from math import cos as rcos\n", + "from math import sin as rsin" + ] + }, { "cell_type": "code", "execution_count": null, @@ -245,11 +256,6 @@ "This file contains the code under test for the example bug.\n", "The sqrt() method fails on x <= 0.\n", "\"\"\"\n", - "from math import tan as rtan\n", - "from math import cos as rcos\n", - "from math import sin as rsin\n", - "\n", - "\n", "def task_sqrt(x):\n", " \"\"\"Computes the square root of x, using the Newton-Raphson method\"\"\"\n", " if x <= -12 and x >= -42:\n", @@ -383,8 +389,15 @@ "metadata": {}, "outputs": [], "source": [ - "import sys\n", - "\n", + "import sys" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "SUBJECT = \"calculator\"\n", "\n", "def sample_runner(sample):\n", @@ -685,8 +698,15 @@ "metadata": {}, "outputs": [], "source": [ - "from abc import ABC, abstractmethod\n", - "\n", + "from abc import ABC, abstractmethod" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "class Feature(ABC):\n", " '''\n", " The abstract base class for grammar features.\n", @@ -795,8 +815,15 @@ "metadata": {}, "outputs": [], "source": [ - "from numpy import nanmax, isnan\n", - "\n", + "from numpy import nanmax, isnan" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "class NumericInterpretation(Feature):\n", " '''\n", " This class represents numeric interpretation features of a grammar. These features\n", @@ -882,8 +909,15 @@ "outputs": [], "source": [ "from collections import defaultdict\n", - "import re\n", - "\n", + "import re" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "# Regex for non-terminal symbols in expansions\n", "RE_NONTERMINAL = re.compile(r'(<[^<> ]*>)')\n", "\n", @@ -1099,8 +1133,15 @@ "metadata": {}, "outputs": [], "source": [ - "import random\n", - "\n", + "import random" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "# For this example, fix the random seed so that the produced output is deterministic\n", "random.seed(24)\n", "f = GrammarFuzzer(EXPR_GRAMMAR, max_nonterminals=3)\n", @@ -1175,8 +1216,15 @@ "metadata": {}, "outputs": [], "source": [ - "import copy\n", - "\n", + "import copy" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "def transform_grammar(sample: str,\n", " grammar: Grammar) -> Grammar:\n", " # copy of the grammar\n", @@ -1403,8 +1451,15 @@ "metadata": {}, "outputs": [], "source": [ - "import math\n", - "\n", + "import math" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "def friendly_decision_tree(clf, feature_names,\n", " class_names = ['NO_BUG', 'BUG'],\n", " indent=0):\n", @@ -1996,8 +2051,15 @@ "metadata": {}, "outputs": [], "source": [ - "from pathlib import Path\n", - "\n", + "from pathlib import Path" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "class TreePath:\n", " def __init__(self, samplefile: Optional[Path], is_bug: bool, requirements: List[TreeRequirement]):\n", " self.__sample = samplefile\n", @@ -2271,8 +2333,15 @@ "metadata": {}, "outputs": [], "source": [ - "import string\n", - "\n", + "import string" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "SPEC_GRAMMAR: Grammar = {\n", " \"\":\n", " [\"\"],\n", @@ -3218,7 +3287,16 @@ "metadata": {}, "outputs": [], "source": [ - "import inspect\n", + "import inspect" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", "print(inspect.getsource(task_sqrt))" ] }, diff --git a/notebooks/PICS/Alhazen-synopsis-1.png b/notebooks/PICS/Alhazen-synopsis-1.png index 396ade1f..b9f4467b 100644 Binary files a/notebooks/PICS/Alhazen-synopsis-1.png and b/notebooks/PICS/Alhazen-synopsis-1.png differ diff --git a/notebooks/PICS/Alhazen-synopsis-1.svg b/notebooks/PICS/Alhazen-synopsis-1.svg index b5e8c2a9..67ff8723 100644 --- a/notebooks/PICS/Alhazen-synopsis-1.svg +++ b/notebooks/PICS/Alhazen-synopsis-1.svg @@ -4,238 +4,145 @@ - + Tree - + 0 - -<lead-digit> <= 3.5 -gini = 0.5 -samples = 1433 -value = [1.0, 1.0] -class = BUG + +<lead-digit> <= 4.5 +gini = 0.5 +samples = 1377 +value = [1.0, 1.0] +class = BUG 1 - -<function> == 'sqrt' <= 0.5 -gini = 0.343 -samples = 435 -value = [0.982, 0.276] -class = BUG + +<function> == 'sqrt' <= 0.5 +gini = 0.338 +samples = 407 +value = [1.0, 0.274] +class = BUG 0->1 - - -True + + +True 10 - -<lead-digit> == '4' <= 0.5 -gini = 0.048 -samples = 998 -value = [0.018, 0.724] -class = NO_BUG + +gini = 0.0 +samples = 970 +value = [0.0, 0.726] +class = NO_BUG 0->10 - - -False + + +False 2 - -gini = -0.0 -samples = 221 -value = [0.0, 0.16] -class = NO_BUG + +gini = 0.0 +samples = 236 +value = [0.0, 0.177] +class = NO_BUG 1->2 - - + + - + -3 - -<term> <= -11.708 -gini = 0.189 -samples = 214 -value = [0.982, 0.116] -class = BUG - - +5 + +<value> <= 42.443 +gini = 0.163 +samples = 171 +value = [1.0, 0.098] +class = BUG + + -1->3 - - +1->5 + + - + -4 - -<term> <= -73.9 -gini = 0.07 -samples = 105 -value = [0.982, 0.037] -class = BUG - - +6 + +<term> == '-<value>' <= 0.5 +gini = 0.059 +samples = 82 +value = [1.0, 0.031] +class = BUG + + -3->4 - - +5->6 + + - + -7 - -gini = 0.0 -samples = 109 -value = [0.0, 0.079] -class = NO_BUG - - +9 + +gini = -0.0 +samples = 89 +value = [0.0, 0.067] +class = NO_BUG + + -3->7 - - +5->9 + + - + -5 +7 -gini = 0.0 -samples = 51 -value = [0.0, 0.037] +gini = -0.0 +samples = 42 +value = [0.0, 0.031] class = NO_BUG - + -4->5 - - +6->7 + + - + -6 - -gini = -0.0 -samples = 54 -value = [0.982, 0.0] -class = BUG - - +8 + +gini = -0.0 +samples = 40 +value = [1.0, 0.0] +class = BUG + + -4->6 - - - - - -11 - -gini = -0.0 -samples = 908 -value = [0.0, 0.659] -class = NO_BUG - - - -10->11 - - - - - -12 - -<integer> <= 40.5 -gini = 0.343 -samples = 90 -value = [0.018, 0.065] -class = NO_BUG - - - -10->12 - - - - - -13 - -<term> == '<value>' <= 0.5 -gini = 0.277 -samples = 6 -value = [0.018, 0.004] -class = BUG - - - -12->13 - - - - - -16 - -gini = -0.0 -samples = 84 -value = [0.0, 0.061] -class = NO_BUG - - - -12->16 - - - - - -14 - -gini = 0.0 -samples = 1 -value = [0.018, 0.0] -class = BUG - - - -13->14 - - - - - -15 - -gini = 0.0 -samples = 5 -value = [0.0, 0.004] -class = NO_BUG - - - -13->15 - - +6->8 + +