This commit is contained in:
TerenceLiu98 2022-08-22 07:46:17 +00:00
parent 5f4e45445f
commit 2b693f2d35
6 changed files with 80 additions and 84 deletions

View File

@ -2,53 +2,87 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"id": "af1d5646-4b13-4039-9f76-8042bc9dbda3", "id": "af1d5646-4b13-4039-9f76-8042bc9dbda3",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "0a5c51d2-8b18-4143-b6f1-73a909ccb623", "id": "15c6e757-cde3-422b-be7e-3f55b7752142",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"gd2 = gradient_descent_2d()" "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", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "8c0f6766-4f41-419b-94a0-916a379ebcd1", "id": "120ecde5-cee1-47c0-b1bc-c99b0cb1098e",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"import os\n",
"running_in_voila = os.environ.get('SERVER_SOFTWARE','jupyterlab').startswith('voila')"
]
} }
], ],
"metadata": { "metadata": {

View File

@ -7,7 +7,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from optimization.gd import gradient_descent_1d, gradient_descent_2d" "from optimization.gd import *"
] ]
}, },
{ {
@ -19,7 +19,7 @@
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "7a9a1093220546d3b7e4cd7606a7c704", "model_id": "6da434bb5623479ea2b213b20390410a",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
@ -33,7 +33,7 @@
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "11824eb29354454eb05a41c4fd7e6539", "model_id": "603367462f0f463ea4594c07f3a20bdd",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
@ -47,7 +47,7 @@
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "23bd6107b7ea4f8280ab57d100ab4619", "model_id": "90dd308b94f547c3805ff23d5ad62c6f",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
@ -60,58 +60,15 @@
} }
], ],
"source": [ "source": [
"gd1 = gradient_descent_1d()" "gd1 = gradient_descent_1d(environ=\"jupyterlab\")"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"id": "15c6e757-cde3-422b-be7e-3f55b7752142", "id": "15c6e757-cde3-422b-be7e-3f55b7752142",
"metadata": {}, "metadata": {},
"outputs": [ "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"
}
],
"source": [ "source": [
"gd2 = gradient_descent_2d()" "gd2 = gradient_descent_2d()"
] ]
@ -122,7 +79,10 @@
"id": "120ecde5-cee1-47c0-b1bc-c99b0cb1098e", "id": "120ecde5-cee1-47c0-b1bc-c99b0cb1098e",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"import os\n",
"running_in_voila = os.environ.get('SERVER_SOFTWARE','jupyterlab').startswith('voila')"
]
} }
], ],
"metadata": { "metadata": {

View File

@ -12,13 +12,13 @@ from tqdm import tqdm
import plotly.graph_objects as go import plotly.graph_objects as go
import plotly.io as pio import plotly.io as pio
pio.renderers.default = 'iframe' # or 'notebook' or 'colab' or 'jupyterlab'
import warnings import warnings
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
class gradient_descent_1d(object): 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)", self.wg_expr = widgets.Text(value="x**3 - x**(1/2)",
description="Expression:", description="Expression:",
style={'description_width': 'initial'}) style={'description_width': 'initial'})
@ -101,7 +101,8 @@ class gradient_descent_1d(object):
class gradient_descent_2d(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", self.wg_expr = widgets.Text(value="(sin(x1) - 2) ** 2 + (sin(x2) - 2) ** 2",
description="Expression:") #style={'description_width': 'initial'}) description="Expression:") #style={'description_width': 'initial'})

View File

View File

@ -12,13 +12,13 @@ from tqdm import tqdm
import plotly.graph_objects as go import plotly.graph_objects as go
import plotly.io as pio import plotly.io as pio
pio.renderers.default = 'notebook' # or 'notebook' or 'colab' or 'jupyterlab'
import warnings import warnings
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
class gradient_descent_1d(object): 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)", self.wg_expr = widgets.Text(value="x**3 - x**(1/2)",
description="Expression:", description="Expression:",
style={'description_width': 'initial'}) style={'description_width': 'initial'})
@ -101,7 +101,8 @@ class gradient_descent_1d(object):
class gradient_descent_2d(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", self.wg_expr = widgets.Text(value="(sin(x1) - 2) ** 2 + (sin(x2) - 2) ** 2",
description="Expression:") #style={'description_width': 'initial'}) description="Expression:") #style={'description_width': 'initial'})