diff --git a/SynRD/synthesizers/config_notebook.ipynb b/SynRD/synthesizers/config_notebook.ipynb new file mode 100644 index 0000000..6117f20 --- /dev/null +++ b/SynRD/synthesizers/config_notebook.ipynb @@ -0,0 +1,731 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Imports" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Importing MSTSynthesizer class to see an example of performance on (new) configuration initialization (other Synthesizers work well too:))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from synthesizer import MSTSynthesizer" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Synthesizer configuration and how it works \n", + "\n", + "We can initialize the synthesizer in three ways:\n", + "\n", + "- using the regular parameters;\n", + "- by passing a configuration dictionary, with key - the name of the parameter, value - the value of the specified parameter;\n", + "- a combination of both methods;\n", + "\n", + "Let's take as an example MSTSynthesizer, as the same configuration options are available for other types. MSTSynthesizer has such parameters that can be configured by a user:\n", + "\n", + "**Required** parameters for MSTSynthesizer:\n", + "- epsilon : float\n", + "\n", + "\n", + "**Optional** parameters for MSTSynthesizer (with their default values if the user does not provide a \"customized\" one):\n", + "- slide_range : bool = False\n", + "- thresh : float = 0.05\n", + "- preprocess_factor : float = 0.05\n", + "- delta : float = 1e-09\n", + "- verbose: bool = False\n", + "\n", + "Let's see how it works on a few examples below:)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Epsilon as a required param to be passed" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The epsilon is a mandatory parameter to pass and it has no default value that will be used unless the user provides their own value. Thus, whenever the user does not provide an epsilon value, we will inform him/her that this is a required parameter, as the other parameters are optional." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Epsilon is a required parameter for Synthesizer.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/wp/3b9l300x6jd499pj0h74v8500000gn/T/ipykernel_97092/4058363018.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m }\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mmst_synth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMSTSynthesizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Epsilon:\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmst_synth\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Slide range:\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmst_synth\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mslide_range\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, preprocess_factor, delta, verbose, **synth_kwargs)\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0msynth_kwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m ) -> None:\n\u001b[0;32m--> 168\u001b[0;31m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslide_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 169\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[0mallowed_additional_params\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"preprocess_factor\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"delta\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"verbose\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, **kwargs)\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0mepsilon_value\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlocals\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"epsilon\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mepsilon_value\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Epsilon is a required parameter for Synthesizer.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 48\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon_value\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m raise TypeError(\n", + "\u001b[0;31mValueError\u001b[0m: Epsilon is a required parameter for Synthesizer." + ] + } + ], + "source": [ + "config = {\n", + " \"thresh\": 0.1,\n", + " \"delta\": 1e-05\n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(**config)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Slide range:\", mst_synth.slide_range)\n", + "print(\"Thresh:\", mst_synth.thresh)\n", + "print(\"Preprocess factor:\", mst_synth.preprocess_factor)\n", + "print(\"Delta:\", mst_synth.delta)\n", + "print(\"Verbose:\", mst_synth.verbose)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Initialization throught config dictionary" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's initialize the basic configuration where we pass **only** one required parameter - epsilon, and see what will be the values of MSTSynthesizer params:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epsilon: 0.08\n", + "Slide range: False\n", + "Thresh: 0.05\n", + "Preprocess factor: 0.05\n", + "Delta: 1e-09\n", + "Verbose: False\n" + ] + } + ], + "source": [ + "config = {\n", + " \"epsilon\": 0.08\n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(**config)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Slide range:\", mst_synth.slide_range) # default False\n", + "print(\"Thresh:\", mst_synth.thresh) # default 0.05\n", + "print(\"Preprocess factor:\", mst_synth.preprocess_factor) # default 0.05\n", + "print(\"Delta:\", mst_synth.delta) # default 1e-09\n", + "print(\"Verbose:\", mst_synth.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "From the above result, you can see that all parameters were set with default values, while epsilon was set with a value provided by the user (as a required parameter)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We also initialize the synthesizer inside the class, which is done as follows:\n", + "\n", + "`self.synthesizer = SmartnoiseMSTSynthesizer(\n", + " epsilon=self.epsilon, delta=self.delta, verbose=self.verbose, **synth_kwargs\n", + ")`\n", + "\n", + "Thus, we see that we can pass our customized parameters there as well (but only those that **can** be customized, e.g: epsilon, delta, and verbose)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "MSTSynthesizer Epsilon: 0.08\n", + "MSTSynthesizer Delta: 1e-09\n", + "MSTSynthesizer Verbose: False\n" + ] + } + ], + "source": [ + "print(\"MSTSynthesizer Epsilon:\", mst_synth.synthesizer.epsilon)\n", + "print(\"MSTSynthesizer Delta:\", mst_synth.synthesizer.delta)\n", + "print(\"MSTSynthesizer Verbose:\", mst_synth.synthesizer.verbose)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As we can see, the epsilon we provided during class initialization is also passed to the synthesizer, while other params used their default values (as we did not configured them)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can configure more parameters and make sure that they are all set correctly (with custom values where they are passed and default values where they are not):" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epsilon: 0.08\n", + "Slide range: True\n", + "Thresh: 0.05\n", + "Preprocess factor: 0.05\n", + "Delta: 0.25\n", + "Verbose: True\n" + ] + } + ], + "source": [ + "config = {\n", + " \"epsilon\": 0.08,\n", + " \"slide_range\": True,\n", + " \"verbose\": True,\n", + " \"delta\": 0.25 \n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(**config)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Slide range:\", mst_synth.slide_range) # default False\n", + "print(\"Thresh:\", mst_synth.thresh) # default 0.05\n", + "print(\"Preprocess factor:\", mst_synth.preprocess_factor) # default 0.05\n", + "print(\"Delta:\", mst_synth.delta) # default 1e-09\n", + "print(\"Verbose:\", mst_synth.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And the values of self.synthesizer are also changed through this:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "MSTSynthesizer Epsilon: 0.08\n", + "MSTSynthesizer Delta: 0.25\n", + "MSTSynthesizer Verbose: True\n" + ] + } + ], + "source": [ + "print(\"MSTSynthesizer Epsilon:\", mst_synth.synthesizer.epsilon)\n", + "print(\"MSTSynthesizer Delta:\", mst_synth.synthesizer.delta) # default 1e-09\n", + "print(\"MSTSynthesizer Verbose:\", mst_synth.synthesizer.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Initialization throught passing values as regular parameters" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The user can also customize the synthesizer using the regular parameter names, which can be done as follows:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epsilon: 0.1\n", + "Slide range: False\n", + "Thresh: 0.05\n", + "Preprocess factor: 1.2\n", + "Delta: 1e-09\n", + "Verbose: False\n" + ] + } + ], + "source": [ + "mst_synth = MSTSynthesizer(epsilon=0.10, slide_range=False, preprocess_factor=1.2)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Slide range:\", mst_synth.slide_range) # default False\n", + "print(\"Thresh:\", mst_synth.thresh) # default 0.05\n", + "print(\"Preprocess factor:\", mst_synth.preprocess_factor) # default 0.05\n", + "print(\"Delta:\", mst_synth.delta) # default 1e-09\n", + "print(\"Verbose:\", mst_synth.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And (again) the values of self.synthesizer are also changed through this:" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "MSTSynthesizer Epsilon: 0.1\n", + "MSTSynthesizer Delta: 1e-09\n", + "MSTSynthesizer Verbose: False\n" + ] + } + ], + "source": [ + "print(\"MSTSynthesizer Epsilon:\", mst_synth.synthesizer.epsilon)\n", + "print(\"MSTSynthesizer Delta:\", mst_synth.synthesizer.delta) # default 1e-09\n", + "print(\"MSTSynthesizer Verbose:\", mst_synth.synthesizer.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And, of course, you should remember that the epsilon is a mandatory parameter for transmission, so if you do not want an error to occur, please specify it (otherwise, we will notify you about it)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Epsilon is a required parameter for Synthesizer.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/wp/3b9l300x6jd499pj0h74v8500000gn/T/ipykernel_97092/1886790669.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmst_synth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMSTSynthesizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mslide_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpreprocess_factor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1.2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, preprocess_factor, delta, verbose, **synth_kwargs)\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0msynth_kwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m ) -> None:\n\u001b[0;32m--> 168\u001b[0;31m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslide_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 169\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[0mallowed_additional_params\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"preprocess_factor\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"delta\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"verbose\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, **kwargs)\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0mepsilon_value\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlocals\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"epsilon\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mepsilon_value\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Epsilon is a required parameter for Synthesizer.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 48\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon_value\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m raise TypeError(\n", + "\u001b[0;31mValueError\u001b[0m: Epsilon is a required parameter for Synthesizer." + ] + } + ], + "source": [ + "mst_synth = MSTSynthesizer(slide_range=False, preprocess_factor=1.2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Initialization using both ways: regular params + config dictionary" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In addition, the user can use both variants of parameter configurations, and the order in which they are passed does not matter, since both will work." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epsilon: 0.3\n", + "Slide range: False\n", + "Thresh: 0.4\n", + "Preprocess factor: 0.05\n", + "Delta: 1e-09\n", + "Verbose: True\n" + ] + } + ], + "source": [ + "config = {\n", + " \"epsilon\": 0.3,\n", + " \"thresh\": 0.4\n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(verbose=True, **config)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Slide range:\", mst_synth.slide_range) # default False\n", + "print(\"Thresh:\", mst_synth.thresh) # default 0.05\n", + "print(\"Preprocess factor:\", mst_synth.preprocess_factor) # default 0.05\n", + "print(\"Delta:\", mst_synth.delta) # default 1e-09\n", + "print(\"Verbose:\", mst_synth.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And the other way around:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epsilon: 0.3333\n", + "Slide range: False\n", + "Thresh: 0.4444\n", + "Preprocess factor: 0.5555\n", + "Delta: 1e-09\n", + "Verbose: False\n" + ] + } + ], + "source": [ + "config = {\n", + " \"epsilon\": 0.3333,\n", + " \"thresh\": 0.4444\n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(**config, preprocess_factor=0.5555)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Slide range:\", mst_synth.slide_range) # default False\n", + "print(\"Thresh:\", mst_synth.thresh) # default 0.05\n", + "print(\"Preprocess factor:\", mst_synth.preprocess_factor) # default 0.05\n", + "print(\"Delta:\", mst_synth.delta) # default 1e-09\n", + "print(\"Verbose:\", mst_synth.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And (again) epsilon is a mandatory argument to be passed:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Epsilon is a required parameter for Synthesizer.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/wp/3b9l300x6jd499pj0h74v8500000gn/T/ipykernel_97092/3251956413.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m }\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mmst_synth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMSTSynthesizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, preprocess_factor, delta, verbose, **synth_kwargs)\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0msynth_kwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m ) -> None:\n\u001b[0;32m--> 168\u001b[0;31m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslide_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 169\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[0mallowed_additional_params\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"preprocess_factor\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"delta\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"verbose\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, **kwargs)\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0mepsilon_value\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlocals\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"epsilon\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mepsilon_value\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Epsilon is a required parameter for Synthesizer.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 48\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon_value\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m raise TypeError(\n", + "\u001b[0;31mValueError\u001b[0m: Epsilon is a required parameter for Synthesizer." + ] + } + ], + "source": [ + "config = {\n", + " \"thresh\": 0.4,\n", + " \"delta\": 0.121\n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(verbose=True, **config)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Checking argument types" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Another great thing is that we don't allow the user to pass arguments with unexpected types. For example: the user passes the argument `verbose = 5` (int type), while verbose should be of type bool. If such a situation occurs, a TypeError message is raised with information about what types are expected for the erroneous argument." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "Epsilon must be of type int or float, got bool.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/wp/3b9l300x6jd499pj0h74v8500000gn/T/ipykernel_97092/2752234616.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m }\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mmst_synth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMSTSynthesizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# The epsilon value can only be of type int or float\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, preprocess_factor, delta, verbose, **synth_kwargs)\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0msynth_kwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m ) -> None:\n\u001b[0;32m--> 168\u001b[0;31m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslide_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 169\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[0mallowed_additional_params\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"preprocess_factor\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"delta\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"verbose\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, **kwargs)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon_value\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m raise TypeError(\n\u001b[0;32m---> 50\u001b[0;31m \u001b[0;34mf\"Epsilon must be of type int or float, got {type(epsilon_value).__name__}.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 51\u001b[0m )\n\u001b[1;32m 52\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mepsilon\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon_value\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: Epsilon must be of type int or float, got bool." + ] + } + ], + "source": [ + "config = {\n", + " \"thresh\": 0.4,\n", + " \"delta\": 0.121\n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(epsilon=True, **config) # The epsilon value can only be of type int or float" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "thresh must be of type float, got str.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/wp/3b9l300x6jd499pj0h74v8500000gn/T/ipykernel_97092/3447988808.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmst_synth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMSTSynthesizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1.0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"0.4\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdelta\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# The thresh value can only be of type int or float\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, preprocess_factor, delta, verbose, **synth_kwargs)\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0msynth_kwargs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 167\u001b[0m ) -> None:\n\u001b[0;32m--> 168\u001b[0;31m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslide_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 169\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[0mallowed_additional_params\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"preprocess_factor\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"delta\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"verbose\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, **kwargs)\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparam_value\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mparam_type\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 70\u001b[0m raise TypeError(\n\u001b[0;32m---> 71\u001b[0;31m \u001b[0;34mf\"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 72\u001b[0m )\n\u001b[1;32m 73\u001b[0m \u001b[0msetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparam\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparam_value\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: thresh must be of type float, got str." + ] + } + ], + "source": [ + "mst_synth = MSTSynthesizer(epsilon=1.0, thresh=\"0.4\", delta=True) # The thresh value can only be of type int or float" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So, from the above examples, we can see that passing the correct type of arguments is an essential step, and if the user makes a mistake, we inform them. However, we **allow the user to pass int values for float arguments** because we can easily convert the former to the latter. See examples below:" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epsilon: 1.0\n", + "Slide range: False\n", + "Thresh: 2.0\n", + "Preprocess factor: 0.05\n", + "Delta: 5.0\n", + "Verbose: True\n" + ] + } + ], + "source": [ + "mst_synth = MSTSynthesizer(epsilon=1, thresh=2, verbose=True, delta=5)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Slide range:\", mst_synth.slide_range) # default False\n", + "print(\"Thresh:\", mst_synth.thresh) # default 0.05\n", + "print(\"Preprocess factor:\", mst_synth.preprocess_factor) # default 0.05\n", + "print(\"Delta:\", mst_synth.delta) # default 1e-09\n", + "print(\"Verbose:\", mst_synth.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And there won't be any issues for self.synthesizer attributes too:" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "MSTSynthesizer Epsilon: 1.0\n", + "MSTSynthesizer Delta: 5.0\n", + "MSTSynthesizer Verbose: True\n" + ] + } + ], + "source": [ + "print(\"MSTSynthesizer Epsilon:\", mst_synth.synthesizer.epsilon)\n", + "print(\"MSTSynthesizer Delta:\", mst_synth.synthesizer.delta) # default 1e-09\n", + "print(\"MSTSynthesizer Verbose:\", mst_synth.synthesizer.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Moreover, if the user provides None as the value for an argument, we will set the default value for this argument (if there is one). " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epsilon: 1.1\n", + "Thresh: 0.001\n", + "Verbose: False\n" + ] + } + ], + "source": [ + "config = {\n", + " \"epsilon\": 1.1,\n", + " \"verbose\": None,\n", + " \"thresh\": 0.001\n", + "}\n", + "\n", + "mst_synth = MSTSynthesizer(**config)\n", + "print(\"Epsilon:\", mst_synth.epsilon)\n", + "print(\"Thresh:\", mst_synth.thresh) # default 0.05\n", + "print(\"Verbose:\", mst_synth.verbose) # default False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Non-existing arguments passed for the synthesizer" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Of course, we don't want the user to pass in non-existent parameters for a particular synth class, because that makes no sense. Another situation might be that the user is simply using the wrong synthesizer type, even if they are passing an \"existing\" parameter. In this case, we will inform the user that the provided arguments are not supported for the specified synthesizer type:" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Parameter 'hello' is not available for this type of synthesizer.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/wp/3b9l300x6jd499pj0h74v8500000gn/T/ipykernel_97092/564626642.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmst_synth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMSTSynthesizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.99\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhello\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"world\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, preprocess_factor, delta, verbose, **synth_kwargs)\u001b[0m\n\u001b[1;32m 172\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mparam\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mallowed_additional_params\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 173\u001b[0m raise ValueError(\n\u001b[0;32m--> 174\u001b[0;31m \u001b[0;34mf\"Parameter '{param}' is not available for this type of synthesizer.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 175\u001b[0m )\n\u001b[1;32m 176\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: Parameter 'hello' is not available for this type of synthesizer." + ] + } + ], + "source": [ + "mst_synth = MSTSynthesizer(epsilon=0.99, verbose=True, hello=\"world\")" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Parameter 'batch_size' is not available for this type of synthesizer.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/wp/3b9l300x6jd499pj0h74v8500000gn/T/ipykernel_97092/2738562190.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmst_synth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMSTSynthesizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mepsilon\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.99\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/Desktop/RAI research program/project/SynRD/SynRD/synthesizers/synthesizer.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, epsilon, slide_range, thresh, preprocess_factor, delta, verbose, **synth_kwargs)\u001b[0m\n\u001b[1;32m 172\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mparam\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mallowed_additional_params\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 173\u001b[0m raise ValueError(\n\u001b[0;32m--> 174\u001b[0;31m \u001b[0;34mf\"Parameter '{param}' is not available for this type of synthesizer.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 175\u001b[0m )\n\u001b[1;32m 176\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: Parameter 'batch_size' is not available for this type of synthesizer." + ] + } + ], + "source": [ + "mst_synth = MSTSynthesizer(epsilon=0.99, verbose=True, batch_size=5)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "synrd", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.16" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/SynRD/synthesizers/synthesizer.py b/SynRD/synthesizers/synthesizer.py index 6871249..f0f84f2 100644 --- a/SynRD/synthesizers/synthesizer.py +++ b/SynRD/synthesizers/synthesizer.py @@ -45,7 +45,7 @@ def __init__( epsilon_value = locals().get("epsilon") if epsilon_value is None: raise ValueError("Epsilon is a required parameter for Synthesizer.") - if not isinstance(epsilon_value, (int, float)): + if type(epsilon_value) not in (float, int): raise TypeError( f"Epsilon must be of type int or float, got {type(epsilon_value).__name__}." ) @@ -64,9 +64,9 @@ def __init__( for param, (default_value, param_type) in param_defaults.items(): param_value = locals().get(param) if param_value is not None: - if isinstance(param_value, int) and param_type is float: + if type(param_value) is int and param_type is float: param_value = float(param_value) - if not isinstance(param_value, param_type): + if type(param_value) is not param_type: raise TypeError( f"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}." ) @@ -183,9 +183,9 @@ def __init__( for param, (default_value, param_type) in param_defaults.items(): param_value = locals().get(param) if param_value is not None: - if isinstance(param_value, int) and param_type is float: + if type(param_value) is int and param_type is float: param_value = float(param_value) - if not isinstance(param_value, param_type): + if type(param_value) is not param_type: raise TypeError( f"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}." ) @@ -348,18 +348,18 @@ def __init__( for param, (param_type, default_value) in param_defaults.items(): param_value = locals().get(param) if param_value is not None: - if isinstance(param_value, int) and param_type is float: + if type(param_value) is int and param_type is float: param_value = float(param_value) if isinstance(param_type, tuple): correctly_typed = False for single_type in param_type: - if isinstance(param_value, single_type): + if type(param_value) is single_type: correctly_typed = True if not correctly_typed: raise TypeError( f"{param} must be of one of the types {', '.join(list(map(lambda x: x.__name__, param_type)))}, got {type(param_value).__name__}." ) - elif not isinstance(param_value, param_type): + elif type(param_value) is not param_type: raise TypeError( f"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}." ) @@ -475,9 +475,9 @@ def __init__( for param, (default_value, param_type) in param_defaults.items(): param_value = locals().get(param) if param_value is not None: - if isinstance(param_value, int) and param_type is float: + if type(param_value) is int and param_type is float: param_value = float(param_value) - if not isinstance(param_value, param_type): + if type(param_value) is not param_type: raise TypeError( f"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}." ) @@ -632,18 +632,18 @@ def __init__( for param, (param_type, default_value) in param_defaults.items(): param_value = locals().get(param) if param_value is not None: - if isinstance(param_value, int) and param_type is float: + if type(param_value) is int and param_type is float: param_value = float(param_value) if isinstance(param_type, tuple): correctly_typed = False for single_type in param_type: - if isinstance(param_value, single_type): + if type(param_value) is single_type: correctly_typed = True if not correctly_typed: raise TypeError( f"{param} must be of one of the types {', '.join(list(map(lambda x: x.__name__, param_type)))}, got {type(param_value).__name__}." ) - elif not isinstance(param_value, param_type): + elif type(param_value) is not param_type: raise TypeError( f"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}." ) @@ -758,18 +758,18 @@ def __init__( for param, (param_type, default_value) in param_defaults.items(): param_value = locals().get(param) if param_value is not None: - if isinstance(param_value, int) and param_type is float: + if type(param_value) is int and param_type is float: param_value = float(param_value) if isinstance(param_type, tuple): correctly_typed = False for single_type in param_type: - if isinstance(param_value, single_type): + if type(param_value) is single_type: correctly_typed = True if not correctly_typed: raise TypeError( f"{param} must be of one of the types {', '.join(list(map(lambda x: x.__name__, param_type)))}, got {type(param_value).__name__}." ) - elif not isinstance(param_value, param_type): + elif type(param_value) is not param_type: raise TypeError( f"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}." ) @@ -837,9 +837,9 @@ def __init__( for param, (default_value, param_type) in param_defaults.items(): param_value = locals().get(param) if param_value is not None: - if isinstance(param_value, int) and param_type is float: + if type(param_value) is int and param_type is float: param_value = float(param_value) - if not isinstance(param_value, param_type): + if type(param_value) is not param_type: raise TypeError( f"{param} must be of type {param_type.__name__}, got {type(param_value).__name__}." )