diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9b5120ed..6f6cd0c9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -21,6 +21,7 @@ }, "extensions": [ "mhutchie.git-graph", + "donjayamanne.jupyter", ], "postCreateCommand": "pip install -r analysis-master/analysis-amd64/requirements.txt" } \ No newline at end of file diff --git a/analysis-master/analysis/.ipynb_checkpoints/equation-checkpoint.ipynb b/analysis-master/analysis/.ipynb_checkpoints/equation-checkpoint.ipynb new file mode 100644 index 00000000..9245ab26 --- /dev/null +++ b/analysis-master/analysis/.ipynb_checkpoints/equation-checkpoint.ipynb @@ -0,0 +1,35 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "string = \"3+4+5\"\n", + "re.sub(\"\\d+[+]{1}\\d+\", string, sum([int(i) for i in re.split(\"[+]{1}\", re.search(\"\\d+[+]{1}\\d+\", string).group())]))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/analysis-master/analysis/analysis.py b/analysis-master/analysis/analysis.py index c4cf49de..07ff32e6 100644 --- a/analysis-master/analysis/analysis.py +++ b/analysis-master/analysis/analysis.py @@ -7,10 +7,12 @@ # current benchmark of optimization: 1.33 times faster # setup: -__version__ = "1.2.1.002" +__version__ = "1.2.2.000" # changelog should be viewed using print(analysis.__changelog__) __changelog__ = """changelog: + 1.2.2.000: + - changed output of regressions to function strings instead of list of coefficients 1.2.1.002: - renamed ArrayTest class to Array 1.2.1.001: @@ -412,7 +414,8 @@ def regression(inputs, outputs, args): # inputs, outputs expects N-D array popt, pcov = scipy.optimize.curve_fit(lin, X, y) - regressions.append((popt.flatten().tolist(), None)) + coeffs = popt.flatten().tolist() + regressions.append(str(coeffs[0]) + "*x+" + str(coeffs[1])) except Exception as e: @@ -428,7 +431,8 @@ def regression(inputs, outputs, args): # inputs, outputs expects N-D array popt, pcov = scipy.optimize.curve_fit(log, X, y) - regressions.append((popt.flatten().tolist(), None)) + coeffs = popt.flatten().tolist() + regressions.append(str(coeffs[0]) + "*log(" + str(coeffs[1]) + "*(x+" + str(coeffs[2]) + "))+" + str(coeffs[3])) except Exception as e: @@ -444,7 +448,8 @@ def regression(inputs, outputs, args): # inputs, outputs expects N-D array popt, pcov = scipy.optimize.curve_fit(exp, X, y) - regressions.append((popt.flatten().tolist(), None)) + coeffs = popt.flatten().tolist() + regressions.append(str(coeffs[0]) + "*e^(" + str(coeffs[1]) + "*(x+" + str(coeffs[2]) + "))+" + str(coeffs[3])) except Exception as e: @@ -466,10 +471,14 @@ def regression(inputs, outputs, args): # inputs, outputs expects N-D array params = model.steps[1][1].intercept_.tolist() params = np.append(params, model.steps[1][1].coef_[0].tolist()[1::]) - params.flatten() - params = params.tolist() - - plys.append(params) + params = params.flatten().tolist() + + temp = "" + counter = 0 + for param in params: + temp += "(" + str(param) + "*x^" + str(counter) + ")" + counter += 1 + plys.append(temp) regressions.append(plys) @@ -483,7 +492,8 @@ def regression(inputs, outputs, args): # inputs, outputs expects N-D array popt, pcov = scipy.optimize.curve_fit(sig, X, y) - regressions.append((popt.flatten().tolist(), None)) + coeffs = popt.flatten().tolist() + regressions.append(str(coeffs[0]) + "*tanh(" + str(coeffs[1]) + "*(x+" + str(coeffs[2]) + "))+" + str(coeffs[3])) except Exception as e: diff --git a/analysis-master/analysis/equation.ipynb b/analysis-master/analysis/equation.ipynb new file mode 100644 index 00000000..0d8ef4ea --- /dev/null +++ b/analysis-master/analysis/equation.ipynb @@ -0,0 +1,162 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import re\n", + "from decimal import Decimal\n", + "from functools import reduce" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def add(string):\n", + " while(len(re.findall(\"[+]{1}[-]?\", string)) != 0):\n", + " string = re.sub(\"[-]?\\d+[.]?\\d*[+]{1}[-]?\\d+[.]?\\d*\", str(\"%f\" % reduce((lambda x, y: x + y), [Decimal(i) for i in re.split(\"[+]{1}\", re.search(\"[-]?\\d+[.]?\\d*[+]{1}[-]?\\d+[.]?\\d*\", string).group())])), string, 1)\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def sub(string):\n", + " while(len(re.findall(\"\\d+[.]?\\d*[-]{1,2}\\d+[.]?\\d*\", string)) != 0):\n", + " g = re.search(\"\\d+[.]?\\d*[-]{1,2}\\d+[.]?\\d*\", string).group()\n", + " if(re.search(\"[-]{1,2}\", g).group() == \"-\"):\n", + " r = re.sub(\"[-]{1}\", \"+-\", g, 1)\n", + " string = re.sub(g, r, string, 1)\n", + " elif(re.search(\"[-]{1,2}\", g).group() == \"--\"):\n", + " r = re.sub(\"[-]{2}\", \"+\", g, 1)\n", + " string = re.sub(g, r, string, 1)\n", + " else:\n", + " pass\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def mul(string):\n", + " while(len(re.findall(\"[*]{1}[-]?\", string)) != 0):\n", + " string = re.sub(\"[-]?\\d+[.]?\\d*[*]{1}[-]?\\d+[.]?\\d*\", str(\"%f\" % reduce((lambda x, y: x * y), [Decimal(i) for i in re.split(\"[*]{1}\", re.search(\"[-]?\\d+[.]?\\d*[*]{1}[-]?\\d+[.]?\\d*\", string).group())])), string, 1)\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "def div(string):\n", + " while(len(re.findall(\"[/]{1}[-]?\", string)) != 0):\n", + " string = re.sub(\"[-]?\\d+[.]?\\d*[/]{1}[-]?\\d+[.]?\\d*\", str(\"%f\" % reduce((lambda x, y: x / y), [Decimal(i) for i in re.split(\"[/]{1}\", re.search(\"[-]?\\d+[.]?\\d*[/]{1}[-]?\\d+[.]?\\d*\", string).group())])), string, 1)\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def exp(string):\n", + " while(len(re.findall(\"[\\^]{1}[-]?\", string)) != 0):\n", + " string = re.sub(\"[-]?\\d+[.]?\\d*[\\^]{1}[-]?\\d+[.]?\\d*\", str(\"%f\" % reduce((lambda x, y: x ** y), [Decimal(i) for i in re.split(\"[\\^]{1}\", re.search(\"[-]?\\d+[.]?\\d*[\\^]{1}[-]?\\d+[.]?\\d*\", string).group())])), string, 1)\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "def evaluate(string):\n", + " string = exp(string)\n", + " string = div(string)\n", + " string = mul(string)\n", + " string = sub(string)\n", + " print(string)\n", + " string = add(string)\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "output_type": "error", + "ename": "SyntaxError", + "evalue": "unexpected EOF while parsing (, line 1)", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m def parentheses(string):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n" + ] + } + ], + "source": [ + "def parentheses(string):" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "-158456325028528675187087900672.000000+0.8\n" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'-158456325028528675187087900672.000000'" + }, + "metadata": {}, + "execution_count": 22 + } + ], + "source": [ + "string = \"8^32*4/-2+0.8\"\n", + "evaluate(string)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6-final" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file