Skip to content

Fix gradient_descent returning after first epoch due to indentation bug#2

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/vscode-mmi6luie-0sdo
Draft

Fix gradient_descent returning after first epoch due to indentation bug#2
Copilot wants to merge 2 commits into
mainfrom
copilot/vscode-mmi6luie-0sdo

Conversation

Copilot AI commented Mar 8, 2026

Copy link
Copy Markdown

gradient_descent was silently returning after a single epoch because return [W1, w2] was indented inside the for loop body. This meant weights were never actually trained regardless of epochs, making all Task 2.9 plots useless.

Change

  • gradient_descent in DL-Assignment01.ipynb: dedented return [W1, w2] from 8 spaces to 4 spaces so it executes after the loop completes.
# Before — returns after epoch 1
    for _ in range(epochs):
        ...
        return [W1, w2]  # inside loop

# After — returns after all epochs
    for _ in range(epochs):
        ...
    return [W1, w2]  # outside loop
Original prompt

can’t see your notebook from this workspace (the project folder is empty on my side), so I can’t directly judge your exact plots yet.

For Task 2.9, a “good” result is usually:

The predicted curve follows the data trend across the full required range (X0: [-3,3], X1: [-4,4], X2: [-6,5]).
It is smooth and plausible (not wildly oscillating between points).
Train and validation/test loss are both low and not far apart.
Different network types give consistent fits, with complexity matching dataset difficulty.
Quick way to decide “good or not”:

Compare MSE (or your loss) on validation/test for all 3 networks per dataset.
Pick the one with lowest validation/test loss, then confirm the plot is not clearly overfit (wiggly curve) or underfit (too flat/simple).
Common reasons plots look “not promising”:

Wrong R passed to plotting.
Model left in training mode during prediction (model.eval() missing, if PyTorch).
Input/output scaling mismatch during plotting.
Too few epochs or poor learning rate.
Using non-optimized hyperparameters by mistake.
If you paste your Task 2.9 code cell + one plot screenshot, I can pinpoint what’s wrong.

create one large figure

figure = pyplot.figure(figsize=(15,9))
trained_thetas = [
[Theta0_X0, Theta0_X1, Theta0_X2], # model_type 0
[Theta1_X0, Theta1_X1, Theta1_X2], # model_type 1
[Theta2_X0, Theta2_X1, Theta2_X2] # model_type 2
]

ranges = [
[-3, 3], # for X0
[-4, 4], # for X1
[-6, 5] # for X2
]

iterate over the model types

for model_type in range(3):
# iterate over the datasets
for i, X in enumerate([X0, X1, X2]):
# activate correct plot
pyplot.subplot(3, 3, 3*model_type+i+1)
# call the plot function with the correct dataset with their ranges, and model type with their trained Theta parameters
plot(X, model_type, trained_thetas[model_type][i], ranges[i])
pyplot.title(f"N{model_type} on X{i}")

pyplot.tight_layout()
pyplot.show()

Created from VS Code.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…pochs run

Co-authored-by: sing-git <183478851+sing-git@users.noreply.github.com>
Copilot AI changed the title [WIP] Evaluate model fits and prediction curves for task 2.9 Fix gradient_descent returning after first epoch due to indentation bug Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants