PUBLISHED FINAL REPORT
This commit is contained in:
parent
86cc300055
commit
10d754e5a3
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,146 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "e8104954-e923-4bfc-b868-d0daafbaa9e6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "ModuleNotFoundError",
|
||||
"evalue": "No module named 'numpy'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
||||
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
|
||||
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnumpy\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnp\u001b[39;00m\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpd\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mmatplotlib\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mpyplot\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mplt\u001b[39;00m\n",
|
||||
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'numpy'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 1. Parameters and Data Generation ---\n",
|
||||
"k = 11 # From Pattanaphol\n",
|
||||
"N = 30\n",
|
||||
"R = 1 + k/100 # 1.11\n",
|
||||
"sigma = 0.05\n",
|
||||
"np.random.seed(42) # for reproducibility\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Generate x values\n",
|
||||
"x = np.linspace(0.1, R, N)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# True function: y_true = 5x^4 - 3x^3 + 2x^2 - x + 1\n",
|
||||
"y_true_func = lambda x: 5*x**4 - 3*x**3 + 2*x**2 - x + 1\n",
|
||||
"y_true = y_true_func(x)\n",
|
||||
"noise = np.random.normal(0, sigma, N)\n",
|
||||
"y_noisy = y_true + noise\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 2. Helper Functions ---\n",
|
||||
"def vandermonde_matrix(x, degree):\n",
|
||||
" \"\"\"Constructs the Vandermonde matrix A = [x^n, ..., x^1, 1]\"\"\"\n",
|
||||
" return np.vander(x, degree + 1, increasing=False)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def estimate_coefficients(A, B, rho=0):\n",
|
||||
" \"\"\"Calculates coefficients X* for LS (rho=0) or Ridge (rho>0).\"\"\"\n",
|
||||
" # X* = (A^T A + rho*I)^-1 * A^T B\n",
|
||||
" AT = A.T\n",
|
||||
" ATA = AT @ A\n",
|
||||
" I = np.identity(ATA.shape[0])\n",
|
||||
" \n",
|
||||
" # Calculate X* using the generalized solution\n",
|
||||
" XTX_plus_rhoI_inv = np.linalg.inv(ATA + rho * I)\n",
|
||||
" X_star = XTX_plus_rhoI_inv @ AT @ B\n",
|
||||
" return X_star\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def poly_val(x_plot, X_star):\n",
|
||||
" \"\"\"Evaluates the polynomial on x_plot using coefficients X_star.\"\"\"\n",
|
||||
" degree = len(X_star) - 1\n",
|
||||
" A_plot = np.vander(x_plot, degree + 1, increasing=False)\n",
|
||||
" return A_plot @ X_star\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 3. Coefficient Estimation (LS & RR) ---\n",
|
||||
"B = y_noisy.reshape(-1, 1)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Calculate all models for plotting\n",
|
||||
"X_star1 = estimate_coefficients(vandermonde_matrix(x, 1), B, rho=0)\n",
|
||||
"X_star7_ls = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0)\n",
|
||||
"X_star7_rr2 = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0.1)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 4. Plotting ---\n",
|
||||
"x_plot = np.linspace(x.min(), x.max(), 500)\n",
|
||||
"y_model1 = poly_val(x_plot, X_star1)\n",
|
||||
"y_model7_ls = poly_val(x_plot, X_star7_ls)\n",
|
||||
"y_model7_rr2 = poly_val(x_plot, X_star7_rr2)\n",
|
||||
"y_true_plot = y_true_func(x_plot)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.figure(figsize=(12, 8))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Raw Data (Scatter Plot)\n",
|
||||
"plt.scatter(x, y_noisy, label='Original Noisy Raw Data $(x_i, y_i)$', color='k', marker='o', s=30)\n",
|
||||
"plt.plot(x_plot, y_true_plot, label='True Underlying Polynomial $y_{true}$ (Degree 4)', color='gray', linestyle='--')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Estimated Models (Line Plots)\n",
|
||||
"plt.plot(x_plot, y_model1, label='1) Model $n=1$ (Least Squares)', color='r', linestyle='-', linewidth=2)\n",
|
||||
"plt.plot(x_plot, y_model7_ls, label='3) Model $n=7$ (Least Squares, Overfit)', color='g', linestyle='-', linewidth=2)\n",
|
||||
"plt.plot(x_plot, y_model7_rr2, label=r'4.2) Model $n=7$ (Ridge, $\\rho=0.1$, Stabilized)', color='b', linestyle='-', linewidth=2)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.title('Noisy Polynomial Model Estimation: LS vs Ridge Regression')\n",
|
||||
"plt.xlabel('$x$')\n",
|
||||
"plt.ylabel('$y$')\n",
|
||||
"plt.legend()\n",
|
||||
"plt.grid(True, linestyle=':', alpha=0.6)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "94c872cc-d8c3-454b-9d62-42b03378e2d9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.14.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
# --- 1. Parameters and Data Generation ---
|
||||
k = 11 # From Pattanaphol
|
||||
N = 30
|
||||
R = 1 + k/100 # 1.11
|
||||
sigma = 0.05
|
||||
np.random.seed(42) # for reproducibility
|
||||
|
||||
|
||||
# Generate x values
|
||||
x = np.linspace(0.1, R, N)
|
||||
|
||||
|
||||
# True function: y_true = 5x^4 - 3x^3 + 2x^2 - x + 1
|
||||
y_true_func = lambda x: 5*x**4 - 3*x**3 + 2*x**2 - x + 1
|
||||
y_true = y_true_func(x)
|
||||
noise = np.random.normal(0, sigma, N)
|
||||
y_noisy = y_true + noise
|
||||
|
||||
|
||||
# --- 2. Helper Functions ---
|
||||
def vandermonde_matrix(x, degree):
|
||||
"""Constructs the Vandermonde matrix A = [x^n, ..., x^1, 1]"""
|
||||
return np.vander(x, degree + 1, increasing=False)
|
||||
|
||||
|
||||
def estimate_coefficients(A, B, rho=0):
|
||||
"""Calculates coefficients X* for LS (rho=0) or Ridge (rho>0)."""
|
||||
# X* = (A^T A + rho*I)^-1 * A^T B
|
||||
AT = A.T
|
||||
ATA = AT @ A
|
||||
I = np.identity(ATA.shape[0])
|
||||
|
||||
# Calculate X* using the generalized solution
|
||||
XTX_plus_rhoI_inv = np.linalg.inv(ATA + rho * I)
|
||||
X_star = XTX_plus_rhoI_inv @ AT @ B
|
||||
return X_star
|
||||
|
||||
|
||||
def poly_val(x_plot, X_star):
|
||||
"""Evaluates the polynomial on x_plot using coefficients X_star."""
|
||||
degree = len(X_star) - 1
|
||||
A_plot = np.vander(x_plot, degree + 1, increasing=False)
|
||||
return A_plot @ X_star
|
||||
|
||||
|
||||
# --- 3. Coefficient Estimation (LS & RR) ---
|
||||
B = y_noisy.reshape(-1, 1)
|
||||
|
||||
|
||||
# Calculate all models for plotting
|
||||
X_star1 = estimate_coefficients(vandermonde_matrix(x, 1), B, rho=0)
|
||||
X_star7_ls = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0)
|
||||
X_star7_rr2 = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0.1)
|
||||
|
||||
|
||||
# --- 4. Plotting ---
|
||||
x_plot = np.linspace(x.min(), x.max(), 500)
|
||||
y_model1 = poly_val(x_plot, X_star1)
|
||||
y_model7_ls = poly_val(x_plot, X_star7_ls)
|
||||
y_model7_rr2 = poly_val(x_plot, X_star7_rr2)
|
||||
y_true_plot = y_true_func(x_plot)
|
||||
|
||||
|
||||
plt.figure(figsize=(12, 8))
|
||||
|
||||
|
||||
# Raw Data (Scatter Plot)
|
||||
plt.scatter(x, y_noisy, label='Original Noisy Raw Data $(x_i, y_i)$', color='k', marker='o', s=30)
|
||||
plt.plot(x_plot, y_true_plot, label='True Underlying Polynomial $y_{true}$ (Degree 4)', color='gray', linestyle='--')
|
||||
|
||||
|
||||
# Estimated Models (Line Plots)
|
||||
plt.plot(x_plot, y_model1, label='1) Model $n=1$ (Least Squares)', color='r', linestyle='-', linewidth=2)
|
||||
plt.plot(x_plot, y_model7_ls, label='3) Model $n=7$ (Least Squares, Overfit)', color='g', linestyle='-', linewidth=2)
|
||||
plt.plot(x_plot, y_model7_rr2, label=r'4.2) Model $n=7$ (Ridge, $\rho=0.1$, Stabilized)', color='b', linestyle='-', linewidth=2)
|
||||
|
||||
|
||||
|
||||
|
||||
plt.title('Noisy Polynomial Model Estimation: LS vs Ridge Regression')
|
||||
plt.xlabel('$x$')
|
||||
plt.ylabel('$y$')
|
||||
plt.legend()
|
||||
plt.grid(True, linestyle=':', alpha=0.6)
|
||||
|
||||
|
||||
plt.show()
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,146 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "e8104954-e923-4bfc-b868-d0daafbaa9e6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "ModuleNotFoundError",
|
||||
"evalue": "No module named 'numpy'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
||||
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
|
||||
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnumpy\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnp\u001b[39;00m\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpd\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mmatplotlib\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mpyplot\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mplt\u001b[39;00m\n",
|
||||
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'numpy'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 1. Parameters and Data Generation ---\n",
|
||||
"k = 11 # From Pattanaphol\n",
|
||||
"N = 30\n",
|
||||
"R = 1 + k/100 # 1.11\n",
|
||||
"sigma = 0.05\n",
|
||||
"np.random.seed(42) # for reproducibility\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Generate x values\n",
|
||||
"x = np.linspace(0.1, R, N)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# True function: y_true = 5x^4 - 3x^3 + 2x^2 - x + 1\n",
|
||||
"y_true_func = lambda x: 5*x**4 - 3*x**3 + 2*x**2 - x + 1\n",
|
||||
"y_true = y_true_func(x)\n",
|
||||
"noise = np.random.normal(0, sigma, N)\n",
|
||||
"y_noisy = y_true + noise\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 2. Helper Functions ---\n",
|
||||
"def vandermonde_matrix(x, degree):\n",
|
||||
" \"\"\"Constructs the Vandermonde matrix A = [x^n, ..., x^1, 1]\"\"\"\n",
|
||||
" return np.vander(x, degree + 1, increasing=False)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def estimate_coefficients(A, B, rho=0):\n",
|
||||
" \"\"\"Calculates coefficients X* for LS (rho=0) or Ridge (rho>0).\"\"\"\n",
|
||||
" # X* = (A^T A + rho*I)^-1 * A^T B\n",
|
||||
" AT = A.T\n",
|
||||
" ATA = AT @ A\n",
|
||||
" I = np.identity(ATA.shape[0])\n",
|
||||
" \n",
|
||||
" # Calculate X* using the generalized solution\n",
|
||||
" XTX_plus_rhoI_inv = np.linalg.inv(ATA + rho * I)\n",
|
||||
" X_star = XTX_plus_rhoI_inv @ AT @ B\n",
|
||||
" return X_star\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def poly_val(x_plot, X_star):\n",
|
||||
" \"\"\"Evaluates the polynomial on x_plot using coefficients X_star.\"\"\"\n",
|
||||
" degree = len(X_star) - 1\n",
|
||||
" A_plot = np.vander(x_plot, degree + 1, increasing=False)\n",
|
||||
" return A_plot @ X_star\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 3. Coefficient Estimation (LS & RR) ---\n",
|
||||
"B = y_noisy.reshape(-1, 1)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Calculate all models for plotting\n",
|
||||
"X_star1 = estimate_coefficients(vandermonde_matrix(x, 1), B, rho=0)\n",
|
||||
"X_star7_ls = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0)\n",
|
||||
"X_star7_rr2 = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0.1)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- 4. Plotting ---\n",
|
||||
"x_plot = np.linspace(x.min(), x.max(), 500)\n",
|
||||
"y_model1 = poly_val(x_plot, X_star1)\n",
|
||||
"y_model7_ls = poly_val(x_plot, X_star7_ls)\n",
|
||||
"y_model7_rr2 = poly_val(x_plot, X_star7_rr2)\n",
|
||||
"y_true_plot = y_true_func(x_plot)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.figure(figsize=(12, 8))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Raw Data (Scatter Plot)\n",
|
||||
"plt.scatter(x, y_noisy, label='Original Noisy Raw Data $(x_i, y_i)$', color='k', marker='o', s=30)\n",
|
||||
"plt.plot(x_plot, y_true_plot, label='True Underlying Polynomial $y_{true}$ (Degree 4)', color='gray', linestyle='--')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Estimated Models (Line Plots)\n",
|
||||
"plt.plot(x_plot, y_model1, label='1) Model $n=1$ (Least Squares)', color='r', linestyle='-', linewidth=2)\n",
|
||||
"plt.plot(x_plot, y_model7_ls, label='3) Model $n=7$ (Least Squares, Overfit)', color='g', linestyle='-', linewidth=2)\n",
|
||||
"plt.plot(x_plot, y_model7_rr2, label=r'4.2) Model $n=7$ (Ridge, $\\rho=0.1$, Stabilized)', color='b', linestyle='-', linewidth=2)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.title('Noisy Polynomial Model Estimation: LS vs Ridge Regression')\n",
|
||||
"plt.xlabel('$x$')\n",
|
||||
"plt.ylabel('$y$')\n",
|
||||
"plt.legend()\n",
|
||||
"plt.grid(True, linestyle=':', alpha=0.6)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "94c872cc-d8c3-454b-9d62-42b03378e2d9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.14.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
# --- 1. Parameters and Data Generation ---
|
||||
k = 11 # From Pattanaphol
|
||||
N = 30
|
||||
R = 1 + k/100 # 1.11
|
||||
sigma = 0.05
|
||||
np.random.seed(42) # for reproducibility
|
||||
|
||||
|
||||
# Generate x values
|
||||
x = np.linspace(0.1, R, N)
|
||||
|
||||
|
||||
# True function: y_true = 5x^4 - 3x^3 + 2x^2 - x + 1
|
||||
y_true_func = lambda x: 5*x**4 - 3*x**3 + 2*x**2 - x + 1
|
||||
y_true = y_true_func(x)
|
||||
noise = np.random.normal(0, sigma, N)
|
||||
y_noisy = y_true + noise
|
||||
|
||||
|
||||
# --- 2. Helper Functions ---
|
||||
def vandermonde_matrix(x, degree):
|
||||
"""Constructs the Vandermonde matrix A = [x^n, ..., x^1, 1]"""
|
||||
return np.vander(x, degree + 1, increasing=False)
|
||||
|
||||
|
||||
def estimate_coefficients(A, B, rho=0):
|
||||
"""Calculates coefficients X* for LS (rho=0) or Ridge (rho>0)."""
|
||||
# X* = (A^T A + rho*I)^-1 * A^T B
|
||||
AT = A.T
|
||||
ATA = AT @ A
|
||||
I = np.identity(ATA.shape[0])
|
||||
|
||||
# Calculate X* using the generalized solution
|
||||
XTX_plus_rhoI_inv = np.linalg.inv(ATA + rho * I)
|
||||
X_star = XTX_plus_rhoI_inv @ AT @ B
|
||||
return X_star
|
||||
|
||||
|
||||
def poly_val(x_plot, X_star):
|
||||
"""Evaluates the polynomial on x_plot using coefficients X_star."""
|
||||
degree = len(X_star) - 1
|
||||
A_plot = np.vander(x_plot, degree + 1, increasing=False)
|
||||
return A_plot @ X_star
|
||||
|
||||
|
||||
# --- 3. Coefficient Estimation (LS & RR) ---
|
||||
B = y_noisy.reshape(-1, 1)
|
||||
|
||||
|
||||
# Calculate all models for plotting
|
||||
X_star1 = estimate_coefficients(vandermonde_matrix(x, 1), B, rho=0)
|
||||
X_star7_ls = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0)
|
||||
X_star7_rr2 = estimate_coefficients(vandermonde_matrix(x, 7), B, rho=0.1)
|
||||
|
||||
|
||||
# --- 4. Plotting ---
|
||||
x_plot = np.linspace(x.min(), x.max(), 500)
|
||||
y_model1 = poly_val(x_plot, X_star1)
|
||||
y_model7_ls = poly_val(x_plot, X_star7_ls)
|
||||
y_model7_rr2 = poly_val(x_plot, X_star7_rr2)
|
||||
y_true_plot = y_true_func(x_plot)
|
||||
|
||||
|
||||
plt.figure(figsize=(12, 8))
|
||||
|
||||
|
||||
# Raw Data (Scatter Plot)
|
||||
plt.scatter(x, y_noisy, label='Original Noisy Raw Data $(x_i, y_i)$', color='k', marker='o', s=30)
|
||||
plt.plot(x_plot, y_true_plot, label='True Underlying Polynomial $y_{true}$ (Degree 4)', color='gray', linestyle='--')
|
||||
|
||||
|
||||
# Estimated Models (Line Plots)
|
||||
plt.plot(x_plot, y_model1, label='1) Model $n=1$ (Least Squares)', color='r', linestyle='-', linewidth=2)
|
||||
plt.plot(x_plot, y_model7_ls, label='3) Model $n=7$ (Least Squares, Overfit)', color='g', linestyle='-', linewidth=2)
|
||||
plt.plot(x_plot, y_model7_rr2, label=r'4.2) Model $n=7$ (Ridge, $\rho=0.1$, Stabilized)', color='b', linestyle='-', linewidth=2)
|
||||
|
||||
|
||||
|
||||
|
||||
plt.title('Noisy Polynomial Model Estimation: LS vs Ridge Regression')
|
||||
plt.xlabel('$x$')
|
||||
plt.ylabel('$y$')
|
||||
plt.legend()
|
||||
plt.grid(True, linestyle=':', alpha=0.6)
|
||||
|
||||
|
||||
plt.show()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,82 @@
|
|||
SEN-103 Programming Multi-Module Appllications
|
||||
|
||||
Assessment Activity SEN-103:00030
|
||||
|
||||
Designing a Distributed Multi-Component System
|
||||
|
||||
Last update: 24 January 2024
|
||||
|
||||
|
||||
|
||||
Assignment Summary
|
||||
|
||||
For this assessment, you must create a high-level architectural design for a distributed, web-based application. You do not need to do any programming to complete this assessment.
|
||||
|
||||
|
||||
|
||||
Detailed Instructions
|
||||
|
||||
You have been asked to design a web application called FitNet which will be accessible via the URL http://www.fit-net.comLinks to an external site.. This application is intended for people interested in sports and fitness. It provides useful information about locations and businesses related to fitness, including (though not necessarily limited to):
|
||||
|
||||
|
||||
|
||||
Public parks;
|
||||
Public swimming pools;
|
||||
Private sports facilities – tennis courts, football courts, basketball courts, swimming pools, etc.
|
||||
Gyms and fitness clubs;
|
||||
Physical therapy and sports medicine clinics;
|
||||
Business that sell fitness equipment.
|
||||
|
||||
|
||||
There are three categories of users, who have different available actions:
|
||||
|
||||
General public (unregistered);
|
||||
Registered users;
|
||||
Facility or business owners (registered and verified).
|
||||
|
||||
|
||||
The application will also include an administrator dashboard for user and content management.
|
||||
|
||||
The application must provide the following capabilities:
|
||||
|
||||
Register (unregistered user);
|
||||
Login (registered user);
|
||||
Search for facilities by type and/or location (any user);
|
||||
See facility locations on a map (any user);
|
||||
View details (opening hours, restrictions, capacity, contact info, etc.) for a particular facility (any user);
|
||||
See reviews for a facility (any user);
|
||||
Get directions from a specified location to a specific facility (any user);
|
||||
Review a facility (registered users only);
|
||||
Add a facility (facility owners only);
|
||||
Delete a facility (admin only);
|
||||
Delete a user (admin only);
|
||||
Verify a commercial user (admin only);
|
||||
Modify details for a facility (admin only).
|
||||
|
||||
|
||||
To complete this assessment, you must create an architecture design document that has the following content:
|
||||
|
||||
|
||||
|
||||
Title page with your name, nickname, date, competency;
|
||||
|
||||
Component diagram showing the important modules in the system and their connections/interactions. Note that your design can use external modules such as geocoding modules (see, for instance, https://positionstack.com/documentationLinks to an external site.) or web mapping modules; be sure to label them correctly in the diagram.
|
||||
|
||||
Component explanation table, similar to the table created in the first AIC-103 lab. This should describe the main capabilities of each module, plus list the other modules whose services a module will use.
|
||||
|
||||
REST API design. Create a table of all the API endpoints your system will provide. For each endpoint, specify:
|
||||
|
||||
The HTTP method used (GET, POST, etc.);
|
||||
The arguments or other data required as input (if any);
|
||||
The information returned (if any);
|
||||
|
||||
|
||||
You do not need to express this in JSON although you can if you want, but this must be fully detailed and clear. Be sure your API is complete; it should contain an endpoint for each of the required capabilities listed above.
|
||||
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
table.JPG (in the folder)
|
||||
|
||||
Submit your assessment to Canvas, as a single A4 PDF document.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,31 @@
|
|||
In this lab exercise, you will break up your single-source program matrilineal.c into three source modules which have lower coupling and better cohesion.
|
||||
|
||||
|
||||
|
||||
Instructions
|
||||
|
||||
Start with your program from SEN-107 (Data Structures) Lab 3, the mother-daughter tree.
|
||||
|
||||
If you have not yet done this lab, you can start from scratch. The instructions for SEN-107 Lab 3 explain in detail what this program should do.
|
||||
|
||||
Create a new program that includes three C source files and two header files:
|
||||
|
||||
|
||||
|
||||
matrilineal.c – This will hold the main function and the top level menu only. It will call functions in the other source files (probably just operations.c).
|
||||
tree.c – This will hold the tree data structure, with functions for manipulating that tree. For instance, you might have a function for adding a node to the tree, a function for finding a node in the tree, and so on.
|
||||
tree.h – This header file should include declarations for any functions in tree.c that will be called from other modules. If you need to define any structure types that will be shared with other modules, put those definitions in this header file as well. If you have “private” functions in tree.c which are not used in any other module, do not include them in tree.h.
|
||||
operations.c – This file will hold the functions that get input data for each operation, call the tree functions, and print results. This module should #include tree.h.
|
||||
operations.h – This header file should include definitions of any functions that will be called by matrilineal.c. It should be #included in matrilineal.c.
|
||||
|
||||
|
||||
Write and test the code for each of these modules, then put them together. The result should be the same as for the original, single-source version of SEN-107 Lab 3.
|
||||
|
||||
|
||||
|
||||
If you prefer, you may do this lab assignment using Python. You should create three Python scripts: matrilineal.py, operations.py and tree.py.
|
||||
|
||||
|
||||
|
||||
To submit this lab exercise, create and upload a Zip file called Lab2.zip that contains all your source files (.c and .h, or .py).
|
||||
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
SEN-103 Programming Multi-Module Applications
|
||||
|
||||
Lab 3 Practice Assignment
|
||||
|
||||
Using External Libraries
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Overview
|
||||
|
||||
In this lab exercise, you create a simple program that uses the capabilities in libgd, the GD graphics library.
|
||||
|
||||
|
||||
|
||||
Instructions
|
||||
|
||||
Preparation
|
||||
|
||||
Start by downloading and installing the GD library.
|
||||
|
||||
You will find the full source and information here:
|
||||
|
||||
|
||||
|
||||
https://github.com/libgd/libgd/releasesLinks to an external site.
|
||||
|
||||
|
||||
|
||||
If you are using Windows, you should download the source Zip file. (It may be easier if you do this lab using Linux.)
|
||||
|
||||
|
||||
|
||||
You will need to build (compile) the libraries on your own computer. To do this, read the README file and other documentation that comes in the release package. This is a big part of the exercise – doing the necessary reading and detective work to get GD working on your computer.
|
||||
|
||||
|
||||
|
||||
I strongly recommend that you do this assignment in C. There is a Python wrapper for GD. You can use this if you want, but I warn you, there is almost no documentation.
|
||||
|
||||
|
||||
|
||||
If you want to use Python for your own program, you must download the Python wrapper code:
|
||||
|
||||
|
||||
|
||||
https://github.com/NOAA-ORR-ERD/py_gdLinks to an external site.
|
||||
|
||||
|
||||
|
||||
Note that you will still need the compiled C version of the library. However, it looks like the conda Python installer will handle a lot of this mess for you. See the information in the py_gd README file.
|
||||
|
||||
|
||||
|
||||
https://github.com/NOAA-ORR-ERD/py_gd/blob/master/README.mdLinks to an external site.
|
||||
|
||||
|
||||
|
||||
Assignment Instructions
|
||||
|
||||
|
||||
|
||||
For the lab assignment, write a program called gdSample.c or gd_sample.py that uses the GD library to do the following:
|
||||
|
||||
|
||||
|
||||
Create an empty, in-memory image that is 1000 pixels wide by 700 pixels wide.
|
||||
Draw a filled orange circle, in the upper left part of the image.
|
||||
Draw an unfilled blue rectangle with line width of 10 pixels, in the upper right part of the image.
|
||||
Draw an unfilled red convex polygon with 7 vertices and a line width of 10 pixels, in the lower left part of the image.
|
||||
Draw a filled purple square, in the lower right part of the image.
|
||||
Draw a string with your full name in the middle of the image.
|
||||
Write out the image as an JPG file.
|
||||
|
||||
|
||||
|
||||
|
||||
To do this assignment, you will need to use the GD documentation for reference. The top level page for the online documentation is here:
|
||||
|
||||
|
||||
|
||||
https://libgd.github.io/manuals/2.3.3/files/preamble-txt.htmlLinks to an external site.
|
||||
|
||||
|
||||
|
||||
There is a set of links in the sidebar which take you to documentation for different topics.
|
||||
|
||||
|
||||
|
||||
I found the page below (accessible via Index/Functions) useful. It lists all the functions in GD in alphabetical order. If you click on a function name, you will see the arguments – but no real explanation of what the function does. Fortunately, the functions are named in a systematic and pretty clear way.
|
||||
|
||||
|
||||
|
||||
https://libgd.github.io/manuals/2.3.3/index/Functions.htmlLinks to an external site.
|
||||
|
||||
|
||||
|
||||
The py_gd documentation seems to be pretty sparse or non-existent. There is one example here:
|
||||
|
||||
|
||||
|
||||
https://github.com/NOAA-ORR-ERD/py_gd/blob/master/docs/examples/mandelbrot.pyLinks to an external site.
|
||||
|
||||
|
||||
|
||||
You can also get some clues as to how to use the Python binding from the test scripts:
|
||||
|
||||
|
||||
|
||||
https://github.com/NOAA-ORR-ERD/py_gd/tree/master/py_gd/testLinks to an external site.
|
||||
|
||||
|
||||
|
||||
Note that even if you use Python, you will probably need to look at the functions in the C version to see what information you need to supply.
|
||||
|
||||
|
||||
|
||||
Write and test your gdSample.c or gd_sample.py program until it works correctly. Then upload your C or Python source file to Canvas + a screenshot showing your program work.
|
||||
|
||||
|
|
@ -0,0 +1,246 @@
|
|||
SEN-103 Programming Multi-Module Applications
|
||||
|
||||
Lab 4 Practice Assignment
|
||||
|
||||
Creating a System with Multiple Executables
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Overview
|
||||
|
||||
In this lab exercise, you will create a taxi dispatching system, which will have two cooperating executables, one to make a request for a taxi and one to dispatch taxis (associate a request with a taxi, and track its progress).
|
||||
|
||||
|
||||
|
||||
Instructions
|
||||
|
||||
For this exercise you will create two programs, taxiRequest and taxiDispatcher. You may do this exercise in Python or C. It might be easier in C since the overall structure of the program is quite similar to the auction demo. If you do the lab in C, you may use my filesearch.c source module to search for and return a list of files that match a pattern.
|
||||
|
||||
|
||||
|
||||
The taxiRequest program will loop, gathering information about taxi reservation requests and writing this information to a file with a specific name pattern (e.g. request_nnnnn.txt) in a well-defined format. It might have a user interface like the following:
|
||||
|
||||
|
||||
|
||||
./taxiRequest
|
||||
|
||||
Enter your phone number <Return to exit>: 0987736262
|
||||
|
||||
Enter your destination: Siam Square
|
||||
|
||||
Enter your current location: CMKL University
|
||||
|
||||
Creating taxi reservation request…
|
||||
|
||||
|
||||
|
||||
Enter your phone number <Return to exit>: 0821219999
|
||||
|
||||
Enter your destination: Don Muang Airport
|
||||
|
||||
Enter your current location: Victory Monument
|
||||
|
||||
Creating taxi reservation request…
|
||||
|
||||
|
||||
|
||||
Enter your phone number <Return to exit>:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
A request file might look like this:
|
||||
|
||||
|
||||
|
||||
0987736262
|
||||
|
||||
Siam Square
|
||||
|
||||
CMKL University
|
||||
|
||||
|
||||
|
||||
The taxiDispatcher program is more complicated. It will loop forever, simulating the passage of time using the sleep() function. Assume that each second of computer time is equivalent to one minute of real world time.
|
||||
|
||||
|
||||
|
||||
Like the auctionControl program, the taxiDispatcher should sleep for ten seconds. Then it should wake up and process requests and on-going trips, as described below.
|
||||
|
||||
|
||||
|
||||
The dispatcher has two jobs:
|
||||
|
||||
|
||||
|
||||
Process and enqueue requests: Look for files that indicate taxi requests, created by taxiRequest. For each file that is found, read the file and create a structure representing the request, then delete the file so it will not be processed again. The structure should include the phone number, destination and current location from the request. It should also include an integer tripDuration field which will hold the number of minutes the trip will take. The program should set this field by generating a random number between 10 and 60. After creating the request structure, the program should add it to the end of a linked list that represents taxis that are en route to their destinations.
|
||||
|
||||
|
||||
|
||||
Update trip durations and remove taxis that have arrived: Start at the beginning of the list of ongoing trips. For each ongoing trip, subtract 10 (10 minutes) from the tripDuration. If the new tripDuration is less than or equal to zero, announce that the taxi has arrived, then remove the item from the linked list.
|
||||
|
||||
|
||||
|
||||
Here is an example of what the output from taxiDispatcher might look like:
|
||||
|
||||
|
||||
|
||||
./taxiDispatcher
|
||||
|
||||
Starting dispatcher
|
||||
|
||||
|
||||
|
||||
Checking for requests
|
||||
|
||||
--- No requests found
|
||||
|
||||
|
||||
|
||||
Checking for arrivals
|
||||
|
||||
--- No taxis have arrived at their destination
|
||||
|
||||
|
||||
|
||||
Waiting ten minutes
|
||||
|
||||
|
||||
|
||||
Checking for requests
|
||||
|
||||
--- Assigned taxi to customer 0987736262 going from CMKL University to Siam Square
|
||||
|
||||
Estimated trip duration 55 minutes
|
||||
|
||||
|
||||
|
||||
Checking for arrivals
|
||||
|
||||
--- No taxis have arrived at their destination
|
||||
|
||||
|
||||
|
||||
Waiting 10 minutes
|
||||
|
||||
|
||||
|
||||
Checking for requests
|
||||
|
||||
--- Assigned taxi to customer 0821219999 going from Victory Monument to Don Muang Airport
|
||||
|
||||
Estimated trip duration 20 minutes
|
||||
|
||||
|
||||
|
||||
--- Assigned taxi to customer 0971212222 going from Mega Bangna to Rangsit
|
||||
|
||||
Estimated trip duration 10 minutes.
|
||||
|
||||
|
||||
|
||||
Checking for arrivals
|
||||
|
||||
--- No taxis have arrived at their destination
|
||||
|
||||
|
||||
|
||||
Waiting ten minutes
|
||||
|
||||
|
||||
|
||||
Checking for requests
|
||||
|
||||
--- No requests found
|
||||
|
||||
|
||||
|
||||
Checking for arrivals
|
||||
|
||||
--- No taxis have arrived at their destination
|
||||
|
||||
|
||||
|
||||
Waiting ten minutes
|
||||
|
||||
|
||||
|
||||
Checking for requests
|
||||
|
||||
--- No requests found
|
||||
|
||||
|
||||
|
||||
Checking for arrivals
|
||||
|
||||
--- Customer 0971212222 going from Mega Bangna to Rangsit has arrived.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
The taxi dispatcher program will loop forever, until you hit Ctrl-C to exit.
|
||||
|
||||
|
||||
|
||||
Additional Challenge
|
||||
|
||||
|
||||
|
||||
Like the auction system, the communication between executables in this system goes only in one direction, from the request application to the dispatching application. In a real taxi dispatching system, the dispatcher module would send information back to the request module when a taxi has been assigned.
|
||||
|
||||
|
||||
|
||||
Add this capability to your programs. Specifically:
|
||||
|
||||
|
||||
|
||||
Modify the dispatcher so it assigns a four character alphanumeric taxi registration code to each queued request. You can generate registration codes randomly, or create an array of strings for registration codes and use a counter to choose the next code in the array. (When you get to the end of the array, use the modulus operator on the counter to start at the beginning again.)
|
||||
Inside the dispatcher, add the registration number to the structure in the trip queue.
|
||||
In the dispatcher, when a taxi request is accepted, after creating the structure and adding it to the queue, write a file with a known filename pattern and structure, that holds the customer phone number, taxi registration number and estimated duration.
|
||||
In the request program, sleep for five seconds before asking for the next request.
|
||||
In the request program, before asking for the next request, have the request program check for any reply files. If any are found, read them, print the information, then delete them.
|
||||
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
|
||||
./taxiRequest
|
||||
|
||||
Enter your phone number <Return to exit>: 0987736262
|
||||
|
||||
Enter your destination: Siam Square
|
||||
|
||||
Enter your current location: CMKL University
|
||||
|
||||
Creating taxi reservation request…
|
||||
|
||||
|
||||
|
||||
Enter your phone number <Return to exit>: 0821219999
|
||||
|
||||
Enter your destination: Don Muang Airport
|
||||
|
||||
Enter your current location: Victory Monument
|
||||
|
||||
Creating taxi reservation request…
|
||||
|
||||
|
||||
|
||||
–-- Dispatcher message: Taxi AB223 assigned to customer 0987736262
|
||||
|
||||
Estimated trip duration 55 minutes.
|
||||
|
||||
|
||||
|
||||
Enter your phone number <Return to exit>:
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
|
||||
Submit a zip file containing the code files (.c or .py) and screenshots of the code operation (showing that it works)
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
SEN-103 Programming Multi-Module Applications
|
||||
|
||||
Lab 5 Practice Assignment
|
||||
|
||||
Using REST APIs with Postman
|
||||
|
||||
|
||||
|
||||
Overview
|
||||
|
||||
Understanding how to construct and to use a set of REST API endpoints is a critical skill for building modern distributed applications. This lab exercise gives you practice executing HTTP requests using the Postman utility, a widely-used tool for exploring, building and debugging REST APIs.
|
||||
|
||||
|
||||
|
||||
Instructions
|
||||
|
||||
1. Go to https://www.postman.comLinks to an external site. and sign up for a free account if you do not already have one. Go to My Workspace. Click on New, then choose HTTP. Postman gives you a form for setting up your HTTP request.
|
||||
|
||||
2. Open a Word/LibreOffice/GoogleDocs document that you can use to save and submit the results of your work. Write your nickname and the date at the top.
|
||||
|
||||
3. Go to https://open-meteo.com/en/docsLinks to an external site. This site provides a free REST API for getting weather data about a location or set of locations. This API provides only a single endpoint, a GET request with the base URL https://api.open-meteo.com/v1/forecast However, you can specify a very large number of different parameters, including the location (or a set of locations), the weather variables in which you are interested, the reporting interval, etc. The possibilities are all documented on the site.
|
||||
|
||||
4. Create a request in Postman to access the Open-Meteo API and return the temperature and the relative humidity for the area near CMKL, hourly for the next seven days. Use the latitude/longitude coordinates 13.7243333, 100.7701839 and the time zone Asia/Bangkok.
|
||||
|
||||
5. Execute your request in Postman. When you get it to execute successfully (this may take a few tries), copy and paste the full request URL into your document. Then copy and paste the JSON response which Postman displays. Do you understand the contents of this response?
|
||||
|
||||
6. Modify your request to ask for the temperature, the cloud cover and rainfall in Boston (latitude 42.364506, longitude 71.038887) for the date range 2024-02-08 through 2024-02-14. When you get your request to execute successfully, copy and paste both the full request and the response into your document.
|
||||
|
||||
7. Next we will use https://timeapi.io to create a POST request that will convert a time from one timezone to another. Go to https://timeapi.io/swagger/index.htmlLinks to an external site. Use the documentation to figure out how to create a request using the /api/Conversion/ConvertTimeZone endpoint. Note that for a POST request, you must provide the arguments to the API using a Body, which is a snippet of data in JSON format. You can find examples in the timeapi.io documentation. Convert the current time in Bangkok to the equivalent time in Boston. Then convert the current time in Bangkok to the the equivalent time in London.
|
||||
|
||||
8. Copy and paste the full request, the body, and the response into your document, for each of these requests.
|
||||
|
||||
9. Upload your document in PDF format.
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
SEN-103 Programming Multi-Module Applications
|
||||
|
||||
Lab 6 Practice Assignment
|
||||
|
||||
Calling REST APIs from HTML using JavaScript
|
||||
|
||||
|
||||
|
||||
Overview
|
||||
|
||||
In this assignment, you will adapt the demonstration examples to call the OpenMeteo API and display the results.
|
||||
|
||||
|
||||
|
||||
Instructions
|
||||
|
||||
Download the demonstration HTML files for this week (Week7Demos.zip Download Week7Demos.zip). Unzip. Copy Example4.html to a new file called Lab6.html. Edit the comment at the top to indicate that this is a submission for SEN-103 Lab 6, and to include your nickname as the author.
|
||||
|
||||
|
||||
Create a button that says “CMKL Forecast”. Then create a JavaScript function that will call the https://api.open-meteo.com/v1/forecast REST API endpoint to request seven days of daily maximum and minimum temperatures for the area around CMKL. (See Lab 5 instructions for more details.) When the API call returns (if the result is successful), display the result in a table as follows:
|
||||
|
||||
|
||||
CMKL 7 Day Forecast
|
||||
|
||||
Date Max Temp (Celcius) Min Temp (Celcius)
|
||||
|
||||
2024-04-08 37.7 28.4
|
||||
|
||||
2024-04-09 37.4 27.4
|
||||
|
||||
2024-04-10 36.7 26.3
|
||||
|
||||
2024-04-11 38.4 26.7
|
||||
|
||||
2024-04-12 36.3 28.1
|
||||
|
||||
2024-04-13 36.3 28.4
|
||||
|
||||
2024-04-14 37.1 28.5
|
||||
|
||||
|
||||
|
||||
Note that HTML has a set of tags for creating tables: <table>...</table>, <tr>...</tr> and <td>...</td>.
|
||||
|
||||
|
||||
|
||||
Once you have this working, expand your example to include a drop-down list of locations. You can use the following location list. You should not show the lat/long in the drop-down list. You will need to make corresponding arrays of coordinates and time zones.
|
||||
|
||||
|
||||
Boston 42.364506, 71.038887 America/New_York
|
||||
|
||||
Tokyo 35.652832, 139.839478 Asia/Tokyo
|
||||
|
||||
Hobart (Tasmania) -42.882137, 147.327194 Australia/Hobart
|
||||
|
||||
Los Angeles 34.052235, -118.243683 America/Los_Angeles
|
||||
|
||||
Mexico City 19.432608, -99.133209 America/Mexico_City
|
||||
|
||||
Prague 50.075539, 14.437800 Europe/Prague
|
||||
|
||||
Novobirsk (Russia) 55.008354, 82.935730 Asia/Novobirsk
|
||||
|
||||
|
||||
|
||||
Change your button to say “7 Day Forecast”. When the user clicks on this button, find whatever location has been selected in the drop down list and use that information for your forecast API call. Display the results in the same format.
|
||||
|
||||
|
||||
|
||||
|
||||
Upload your modified HTML file to Canvas.
|
||||
|
|
@ -1 +0,0 @@
|
|||
,winsdominoes,aurora,24.11.2025 22:16,file:///var/mnt/wd-passport/Optiplex/home/winsdominoes/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue