diff --git a/algorithm/.ipynb_checkpoints/interactive-checkpoint.ipynb b/algorithm/.ipynb_checkpoints/interactive-checkpoint.ipynb index 9167237..fe13a87 100644 --- a/algorithm/.ipynb_checkpoints/interactive-checkpoint.ipynb +++ b/algorithm/.ipynb_checkpoints/interactive-checkpoint.ipynb @@ -2,53 +2,87 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "af1d5646-4b13-4039-9f76-8042bc9dbda3", "metadata": {}, "outputs": [], "source": [ - "from optimization.gd import gradient_descent_1d, gradient_descent_2d" + "from optimization.gd import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "0a5c51d2-8b18-4143-b6f1-73a909ccb623", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6da434bb5623479ea2b213b20390410a", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(HBox(children=(VBox(children=(Text(value='x**3 - x**(1/2)', description='Expression:', style=De…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "603367462f0f463ea4594c07f3a20bdd", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "90dd308b94f547c3805ff23d5ad62c6f", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "gd1 = gradient_descent_1d(environ=\"jupyterlab\")" ] }, { "cell_type": "code", "execution_count": null, - "id": "0a5c51d2-8b18-4143-b6f1-73a909ccb623", + "id": "15c6e757-cde3-422b-be7e-3f55b7752142", "metadata": {}, "outputs": [], "source": [ "gd2 = gradient_descent_2d()" ] }, - { - "cell_type": "code", - "execution_count": 3, - "id": "f254549d-d9b0-43ac-a502-e65b7c462d05", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "plotly.graph_objs._scatter3d.Scatter3d" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import plotly.graph_objects as go\n", - "go.Scatter3d" - ] - }, { "cell_type": "code", "execution_count": null, - "id": "8c0f6766-4f41-419b-94a0-916a379ebcd1", + "id": "120ecde5-cee1-47c0-b1bc-c99b0cb1098e", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import os\n", + "running_in_voila = os.environ.get('SERVER_SOFTWARE','jupyterlab').startswith('voila')" + ] } ], "metadata": { diff --git a/algorithm/interactive.ipynb b/algorithm/interactive.ipynb index 8a6b827..fe13a87 100644 --- a/algorithm/interactive.ipynb +++ b/algorithm/interactive.ipynb @@ -7,7 +7,7 @@ "metadata": {}, "outputs": [], "source": [ - "from optimization.gd import gradient_descent_1d, gradient_descent_2d" + "from optimization.gd import *" ] }, { @@ -19,7 +19,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "7a9a1093220546d3b7e4cd7606a7c704", + "model_id": "6da434bb5623479ea2b213b20390410a", "version_major": 2, "version_minor": 0 }, @@ -33,7 +33,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "11824eb29354454eb05a41c4fd7e6539", + "model_id": "603367462f0f463ea4594c07f3a20bdd", "version_major": 2, "version_minor": 0 }, @@ -47,7 +47,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "23bd6107b7ea4f8280ab57d100ab4619", + "model_id": "90dd308b94f547c3805ff23d5ad62c6f", "version_major": 2, "version_minor": 0 }, @@ -60,58 +60,15 @@ } ], "source": [ - "gd1 = gradient_descent_1d()" + "gd1 = gradient_descent_1d(environ=\"jupyterlab\")" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "15c6e757-cde3-422b-be7e-3f55b7752142", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f3cbcf4a398647d787391f02fea55a8e", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "VBox(children=(HBox(children=(VBox(children=(Text(value='(sin(x1) - 2) ** 2 + (sin(x2) - 2) ** 2', description…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c12e073565ee4053b890cd4dcded4610", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "3be9b459745d48dd9c367b5a7866c2bc", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "gd2 = gradient_descent_2d()" ] @@ -122,7 +79,10 @@ "id": "120ecde5-cee1-47c0-b1bc-c99b0cb1098e", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import os\n", + "running_in_voila = os.environ.get('SERVER_SOFTWARE','jupyterlab').startswith('voila')" + ] } ], "metadata": { diff --git a/algorithm/optimization/.ipynb_checkpoints/gd-checkpoint.py b/algorithm/optimization/.ipynb_checkpoints/gd-checkpoint.py index 3ac8420..a3f858a 100644 --- a/algorithm/optimization/.ipynb_checkpoints/gd-checkpoint.py +++ b/algorithm/optimization/.ipynb_checkpoints/gd-checkpoint.py @@ -12,13 +12,13 @@ from tqdm import tqdm import plotly.graph_objects as go import plotly.io as pio -pio.renderers.default = 'iframe' # or 'notebook' or 'colab' or 'jupyterlab' import warnings warnings.filterwarnings("ignore") class gradient_descent_1d(object): - def __init__(self): + def __init__(self, environ:str="jupyterlab"): + pio.renderers.default = environ # 'notebook' or 'colab' or 'jupyterlab' self.wg_expr = widgets.Text(value="x**3 - x**(1/2)", description="Expression:", style={'description_width': 'initial'}) @@ -101,7 +101,8 @@ class gradient_descent_1d(object): class gradient_descent_2d(object): - def __init__(self): + def __init__(self, environ:str="jupyterlab"): + pio.renderers.default = environ # 'notebook' or 'colab' or 'jupyterlab' self.wg_expr = widgets.Text(value="(sin(x1) - 2) ** 2 + (sin(x2) - 2) ** 2", description="Expression:") #style={'description_width': 'initial'}) diff --git a/algorithm/optimization/__init__.py b/algorithm/optimization/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/algorithm/optimization/__pycache__/gd.cpython-310.pyc b/algorithm/optimization/__pycache__/gd.cpython-310.pyc index 7b5f97c..7e33b9b 100644 Binary files a/algorithm/optimization/__pycache__/gd.cpython-310.pyc and b/algorithm/optimization/__pycache__/gd.cpython-310.pyc differ diff --git a/algorithm/optimization/gd.py b/algorithm/optimization/gd.py index a8f1bd0..a3f858a 100644 --- a/algorithm/optimization/gd.py +++ b/algorithm/optimization/gd.py @@ -12,13 +12,13 @@ from tqdm import tqdm import plotly.graph_objects as go import plotly.io as pio -pio.renderers.default = 'notebook' # or 'notebook' or 'colab' or 'jupyterlab' import warnings warnings.filterwarnings("ignore") class gradient_descent_1d(object): - def __init__(self): + def __init__(self, environ:str="jupyterlab"): + pio.renderers.default = environ # 'notebook' or 'colab' or 'jupyterlab' self.wg_expr = widgets.Text(value="x**3 - x**(1/2)", description="Expression:", style={'description_width': 'initial'}) @@ -101,7 +101,8 @@ class gradient_descent_1d(object): class gradient_descent_2d(object): - def __init__(self): + def __init__(self, environ:str="jupyterlab"): + pio.renderers.default = environ # 'notebook' or 'colab' or 'jupyterlab' self.wg_expr = widgets.Text(value="(sin(x1) - 2) ** 2 + (sin(x2) - 2) ** 2", description="Expression:") #style={'description_width': 'initial'})