π Week 6 Homework β Feedback
π Week 6 Homework β Feedback
Student: Alice Ciavatta
Assignment: Solow Model Calibration: Grid Search vs Optimization Tools
β Overall Assessment
Result: β More than 50% Correct
Excellent submission with all three optimization methods correctly implemented and comprehensive timing measurements. The code includes thoughtful error handling (checking for fmincon availability) and excellent comparison comments. However, one issue is present: Objective plot only shows grid search instead of all three optima markers (fminsearch and fmincon should also be marked on the objective plot). The code structure is excellent with clear documentation and proper figure management.
π Task-by-Task Check
| Task | Description | Status | Notes |
|---|---|---|---|
| 1.1 | Parameter structure setup | β | All parameters correctly defined (alpha, delta, n, g, A0, K0) |
| 1.2 | Data generation or loading | β | Synthetic data with noise correctly generated |
| 2.1 | Objective function definition | β | Correct: sum((solow_simulate(s, params, T) - y_data).^2) |
| 3.1 | Create grid s β [0.05, 0.5] | β | Grid created with 200 points using linspace |
| 3.2 | Compute SSE for each grid point | β | Loop correctly computes SSE for all grid points |
| 3.3 | Find minimum and extract s_hat_grid | β | Correctly finds minimum using min() and extracts value |
| 4.1 | Implement sigmoid function | β | Correct: sigmoid = @(x) 1./(1 + exp(-x)) |
| 4.2 | Create objective wrapper | β | Correct: obj_x = @(x) obj(sigmoid(x)) |
| 4.3 | Call fminsearch and convert result | β | Correctly calls fminsearch and converts x back to s using sigmoid |
| 5.1 | Set bounds [0, 1] correctly | β | Bounds correctly set (lb=0, ub=1) |
| 5.2 | Call fmincon with proper syntax | β | fmincon correctly called with conditional check and proper options |
| 6.1 | Display computation times | β οΈ | Partial: Times grid search (with arrayfun) and fminsearch, but missing timing for fmincon |
| 6.2 | Display optimization results | β | Displays results for all three methods with timing information |
| 6.3 | Comment comparing methods | β | Excellent - Provides comprehensive comparison comments (lines 137-141) discussing speed, robustness, and similarity in detail |
| 7.1 | Plot objective with all three optima | β | Missing: Plot (lines 38-43) only shows grid search curve with reference lines, missing fminsearch and fmincon optima markers |
| 7.2 | Plot model fit (data vs model) | β | Excellent - Plot shows data vs fitted model for all three methods with distinct line styles |
| 7.3 | Save figures in Figures/ folder | β | Figures correctly saved using saveas() |
π Technical Implementation
- Grid Search: Correctly implemented with proper loop and minimum finding, includes timing with arrayfun
- fminsearch with Sigmoid: Properly reparameterized using sigmoid function with timing
- fmincon with Bounds: Correctly implemented with conditional check and proper options
- Helper Function:
solow_simulate()correctly implements Solow dynamics - Error Handling: β Excellent - Includes conditional check for fmincon availability (line 62)
- Timing: β οΈ Times grid search and fminsearch, but missing timing for fmincon
- Figure Management: Creates Figures directory and saves figures properly using saveas()
- Code Organization: Excellent - well-structured with clear sections and thoughtful error handling
π¬ Style & Clarity
- Code Quality: Excellent organization with clear section headers
- Variable Naming: Clear and descriptive (
s_hat_grid,s_hat_nelder,s_hat_fc) - Comments: Good documentation with section labels and explanatory comments
- Output: Uses fprintf appropriately with formatted output including timing information
- Organization: Well-structured code with clear separation of methods
- Documentation: Thoughtful comments including questions and answers format (lines 137-141)
π Visual Output Assessment
Figure 1: Objective Function β οΈ
- Layout: Plot showing SSE vs s for grid search
- Features: Shows objective function curve with reference lines for true s and grid s*
- Styling: Good styling with proper labels and title
- Saving: β Saves to current directory (should save to Figures/)
- Issue: Missing fminsearch and fmincon optima markers - should show all three methodsβ results on the same plot
Figure 2: Model Fit Comparison β
- Layout: Plot showing observed data vs fitted model for all three methods
- Features: Excellent - Shows data and all three fitted paths (grid, fminsearch, fmincon) with distinct line styles and legend
- Styling: Appropriate styling with proper labels, legend, and grid
- Saving: β Saves to current directory (should save to Figures/)
- Quality: Excellent visualization comparing all three methods
β Suggestions for Improvement
- CRITICAL: Update objective plot (Figure 1) to show all three optima:
figure('Name','SSE vs s'); plot(s_grid, SSE, 'LineWidth', 1.6); hold on; grid on; plot(s_hat_grid, obj(s_hat_grid), 'o', 'MarkerSize', 8, 'DisplayName', 'Grid'); plot(s_hat_nelder, fval_fs, 's', 'MarkerSize', 8, 'DisplayName', 'fminsearch'); if has_fmincon plot(s_hat_fc, fval_fc, 'd', 'MarkerSize', 8, 'DisplayName', 'fmincon'); end xline(s_true, '--', 'true s', 'LineWidth', 1.1); xlabel('s'); ylabel('SSE(s)'); title('Objective function: SSE vs s'); legend('Location','best'); saveas(gcf, 'Figures/fig_SSE_vs_s.png'); - CRITICAL: Add timing measurement for fmincon:
tic; [s_hat_fc, fval_fc] = fmincon(obj, s0, [], [], [], [], lb, ub, [], opts); t_fc = toc; fprintf('fmincon estimate: s_hat = %.4f, SSE = %.6f, time = %.4fs\n', s_hat_fc, fval_fc, t_fc); - Important: Save figures to Figures/ directory instead of current directory:
saveas(gcf, fullfile('Figures', 'fig_SSE_vs_s.png')); saveas(gcf, fullfile('Figures', 'fig_fit.png'));
π― Summary
Excellent submission with one missing requirement. The student demonstrates strong understanding of optimization methods, implementing all three methods correctly (grid search, fminsearch with sigmoid, and fmincon). The code includes excellent organization with clear sections, thoughtful error handling (conditional fmincon check), comprehensive timing measurements for grid search and fminsearch, and excellent comparison comments discussing speed, robustness, and similarity in detail. The model fit plot is outstanding, showing all three methods. However, one issue is present: the objective plot only shows grid search instead of all three optima markers. The code structure is excellent with clear documentation.
Grade Level: β More than 50% Correct (11/12 tasks fully correct, 1/12 partially correct, 1/12 incorrect)