🌍 Week 6 Homework β€” Feedback

Student: Bakytkul Baltabay
Assignment: Solow Model Calibration: Grid Search vs Optimization Tools


βœ… Overall Assessment

Result: ⚠️ Partial <50% Correct

Submission attempts all three optimization methods but contains critical errors in the objective function definition and grid search implementation. The objective function (line 24) is incorrectly defined, missing parentheses and squaring the sum instead of summing squared differences. The grid search uses fminsearch instead of finding the grid minimum, which defeats the purpose of manual grid search. fminsearch and fmincon are implemented but use the incorrect objective function. Missing timing measurements and proper comparison comments.


πŸ” Task-by-Task Check

Task Description Status Notes
1.1 Parameter structure setup βœ… All parameters correctly defined
1.2 Data generation or loading βœ… Synthetic data with noise correctly generated
2.1 Objective function definition ❌ Critical Error: Line 24: sum(solow_simulate(s_grid,params,T) - y_data)^2 is wrong - should be sum((solow_simulate(s,params,T) - y_data).^2)
3.1 Create grid s ∈ [0.05, 0.5] βœ… Grid created with 200 points
3.2 Compute SSE for each grid point ⚠️ Computes SSE but using incorrect objective function
3.3 Find minimum and extract s_hat_grid ❌ Critical Error: Line 44 uses fminsearch(obj, s_true) instead of extracting grid minimum
4.1 Implement sigmoid function βœ… Correct: sigmoid = @(x) 1./(1 + exp(-x))
4.2 Create objective wrapper βœ… Correct wrapper created
4.3 Call fminsearch and convert result ⚠️ Uses incorrect objective function
5.1 Set bounds [0, 1] correctly βœ… Bounds correctly set (lb=0, ub=1)
5.2 Call fmincon with proper syntax ⚠️ Syntax correct but uses wrong objective function
6.1 Display computation times ❌ Missing: No tic/toc measurements
6.2 Display optimization results ⚠️ Displays some results but incomplete
6.3 Comment comparing methods ⚠️ Partial: Basic comments provided but not comprehensive
7.1 Plot objective with all three optima ❌ Missing: Plot only shows grid search curve, no optima markers for fminsearch/fmincon
7.2 Plot model fit (data vs model) βœ… Plot created showing data vs fitted model
7.3 Save figures in Figures/ folder βœ… Figures correctly saved in PDF format

πŸ“ˆ Technical Implementation

  • Objective Function: ❌ Critical Error - Line 24: obj = @(s_grid)sum(solow_simulate(s_grid,params,T) - y_data)^2;
    • Missing parentheses: should be sum((model - data).^2) not sum(model - data)^2
    • The ^2 is applied to the sum, not to individual differences
    • Should be: obj = @(s) sum((solow_simulate(s, params, T) - y_data).^2);
  • Grid Search: ❌ Critical Error - Line 44 uses fminsearch(obj, s_true) instead of extracting the minimum from the grid: s_hat_grid = s_grid(idx_min);
  • fminsearch with Sigmoid: Uses incorrect objective function
  • fmincon: Uses incorrect objective function
  • Helper Function: Need to verify if solow_simulate() function is provided (not visible in main code)
  • Figure Management: Saves to Figures/ directory

πŸ’¬ Style & Clarity

  • Code Quality: Basic organization with clear sections
  • Variable Naming: Some inconsistencies (uses l0 instead of s0 for fmincon)
  • Comments: Minimal comments
  • Output: Uses fprintf appropriately
  • Organization: Basic structure but missing some elements

πŸ“Š Visual Output Assessment

Figure 1: Objective Function ⚠️

  • Layout: Plot showing SSE vs s
  • Features: Only shows grid search curve
  • Issue: Missing optima markers for fminsearch and fmincon on the objective plot
  • Saving: βœ… Saves PDF to Figures/ directory

Figure 2: Model Fit βœ…

  • Layout: Plot showing data vs fitted model
  • Features: Shows data and fitted model
  • Saving: βœ… Saves PDF to Figures/ directory

βœ… Suggestions for Improvement

  1. CRITICAL: Fix objective function definition (line 24):
    obj = @(s) sum((solow_simulate(s, params, T) - y_data).^2);
    

    Note: The parentheses and .^2 are essential - we need to square each difference first, then sum.

  2. CRITICAL: Fix grid search minimum extraction (line 44):
    [~, idx_min] = min(SSE);
    s_hat_grid = s_grid(idx_min);  % Extract from grid, don't use fminsearch!
    
  3. CRITICAL: Update objective plot to show all three optima:
    plot(s_hat_grid, obj(s_hat_grid), 'ro', 'MarkerSize', 8, 'DisplayName', 'Grid');
    plot(s_hat_nelder, obj(s_hat_nelder), 'bs', 'MarkerSize', 8, 'DisplayName', 'fminsearch');
    plot(s_hat_fmincon, obj(s_hat_fmincon), 'gd', 'MarkerSize', 8, 'DisplayName', 'fmincon');
    
  4. CRITICAL: Add timing measurements (tic/toc) for all three methods

  5. Important: Expand comparison comments to discuss speed, robustness, and similarity in detail

  6. Style: Provide solow_simulate() helper function if it’s not included

🎯 Summary

Submission with critical errors requiring correction. The student attempts all three optimization methods and includes both required figures. However, there are critical errors: (1) objective function is incorrectly defined (missing parentheses, squaring sum instead of summing squares), (2) grid search uses fminsearch instead of extracting grid minimum, and (3) all methods use the incorrect objective function. The code structure is basic with some organization, but missing timing measurements and comprehensive comparison comments. The objective plot only shows the curve without marking all three optima.

Grade Level: ⚠️ Partial <50% Correct (6/12 tasks fully correct, 3/12 partially correct, 3/12 incorrect)