🌍 Week 6 Homework β€” Feedback

Student: Felice Urciuoli
Assignment: Solow Model Calibration: Grid Search vs Optimization Tools


βœ… Overall Assessment

Result: βœ… More than 50% Correct

Solid submission with good code organization and robust error handling. All three optimization methods are correctly implemented (grid search, fminsearch with sigmoid reparameterization, and fmincon with bounds). However, there are several missing requirements: (1) No timing measurements (tic/toc) for comparing computation speeds, (2) Objective plot only shows grid minimum instead of all three optima, and (3) Missing comparison comments discussing speed, robustness, and similarity of results. The code includes thoughtful error handling and economic interpretation.


πŸ” 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 (conditional but properly implemented)
6.1 Display computation times ❌ Missing: No tic/toc measurements for any method
6.2 Display optimization results ⚠️ Partial: Displays grid and fminsearch results, fmincon is conditional (only if exists)
6.3 Comment comparing methods ❌ Missing: No written comparison discussing speed, robustness, or similarity
7.1 Plot objective with all three optima ⚠️ Partial: Only shows grid minimum, missing fminsearch and fmincon optima markers
7.2 Plot model fit (data vs model) βœ… Correct plot showing data vs fitted model output over time
7.3 Save figures in Figures/ folder βœ… Figures correctly saved in PNG format

πŸ“ˆ Technical Implementation

  • Grid Search: Correctly implemented with proper loop and minimum finding
  • fminsearch with Sigmoid: Properly reparameterized using sigmoid function to enforce bounds
  • fmincon with Bounds: Correctly implemented with conditional check (if fmincon exists) and proper error handling
  • Helper Function: solow_simulate() correctly implements Solow dynamics
  • Error Handling: βœ… Excellent - Includes robust directory creation, try-catch for fmincon, and path handling for figure saving
  • Figure Management: Creates Figures directory with robust path handling and saves figures properly
  • Code Organization: Well-structured with clear sections and comments
  • Advanced Features: Includes economic interpretation comments and thoughtful error handling

πŸ’¬ Style & Clarity

  • Code Quality: Excellent organization with clear sections
  • Variable Naming: Clear and descriptive (s_hat_grid, s_hat_nelder, params)
  • Comments: Good documentation with economic interpretation at the end
  • Output: Uses fprintf appropriately to display results
  • Organization: Well-structured with labeled sections
  • Documentation: Includes helpful comments and economic interpretation

πŸ“Š Visual Output Assessment

Figure 1: SSE Grid Search ⚠️

  • Layout: Plot showing SSE vs s with grid search minimum
  • Features: Shows objective function curve and marks grid minimum with red circle
  • Styling: Good styling with proper labels, legend, and reference lines (true s, min SSE)
  • Saving: βœ… Saves to Figures/ directory
  • Issue: Missing fminsearch and fmincon optima markers - should show all three methods’ results on the same plot

Figure 2: Model Fit βœ…

  • Layout: Plot showing observed data vs fitted model output over time
  • Features: Shows both data (blue) and fitted model from fminsearch (red), plus fmincon if available (black dashed)
  • Styling: Appropriate styling with proper labels, legend, and grid
  • Saving: βœ… Saves to Figures/ directory
  • Note: Includes both fminsearch and fmincon fits when fmincon is available

βœ… Suggestions for Improvement

  1. CRITICAL: Add timing measurements (tic/toc) for all three methods to enable speed comparison:
    tic;
    % ... grid search code ...
    time_grid = toc;
       
    tic;
    % ... fminsearch code ...
    time_fminsearch = toc;
       
    tic;
    % ... fmincon code ...
    time_fmincon = toc;
    
  2. CRITICAL: Update objective plot (Figure 1) to show all three optima:
    plot(s_hat_grid, obj(s_hat_grid), 'ko', 'MarkerSize', 8, 'DisplayName', 'Grid');
    plot(s_hat_nelder, obj(s_hat_nelder), 'rs', 'MarkerSize', 8, 'DisplayName', 'fminsearch');
    if use_fmincon
        plot(s_hat_fmincon, obj(s_hat_fmincon), 'bd', 'MarkerSize', 8, 'DisplayName', 'fmincon');
    end
    
  3. CRITICAL: Add comparison comments (2-3 lines) discussing:
    • Which solver is faster (need timing measurements first)
    • Which is more robust
    • Whether they give similar s_hat values
  4. Style: Consider using arrayfun() for grid search SSE computation (more MATLAB-idiomatic):
    SSE = arrayfun(obj, s_grid);
    

    (Though the loop approach is perfectly fine and may be clearer)


🎯 Summary

Good submission with missing requirements. The student demonstrates solid understanding of optimization methods and implements all three methods correctly (grid search, fminsearch with sigmoid, and fmincon). The code includes excellent error handling and robust figure directory management. However, several required elements are missing: (1) no timing measurements for comparing computation speeds, (2) objective plot only shows grid minimum instead of all three optima, and (3) missing comparison comments. The code structure is well-organized with clear sections and good documentation.

Grade Level: βœ… More than 50% Correct (11/12 tasks fully correct, 2/12 partially correct, 2/12 incorrect)