রাতের অন্ধকারে একটি পাহাড়ি উপত্যকায় নেমে আসছেন। প্রতিটি পদক্ষেপে নিচের দিকে যাওয়ার চেষ্টা করছেন। কিন্তু হঠাৎ দেখলেন — সামনে একটি ছোট গর্ত, তারপর আবার উঁচু। আপনি কি সত্যিকারের নিচুতম জায়গায় আছেন, নাকি একটি local minimum-এ আটকে গেছেন?
এই অধ্যায়ে আমরা optimization landscape-এর topology বুঝব — কোথায় global minimum, কোথায় local minimum, কোথায় saddle point — আর gradient descent কখন কী পায়।
Convex Function = নিরাপদ Landscape
Function f convex যদি:
Geometric অর্থ: যেকোনো দুই বিন্দুর মধ্যে chord graph-এর উপর বা উপরে থাকে।
- Convex → একটিমাত্র global minimum — gradient descent সবসময় সেখানেই পৌঁছায়।
- Non-convex → অনেক local minima, saddle points — gradient descent আটকে যেতে পারে।
Critical Points — Landscape-এর Topology
∇f = 0 যেখানে — সব critical points:
- Global minimum: সবচেয়ে নিচু। deep learning-এ rare — local minima-ই সাধারণত good enough।
- Local minimum: আশেপাশে সবচেয়ে নিচু, কিন্তু আরও নিচু আছে দূরে।
- Saddle point: কিছু direction-এ minimum, কিছু direction-এ maximum। gradient = 0 কিন্তু Hessian-এর eigenvalue mixed sign।
- Plateau: gradient ≈ 0, কিন্তু কোনো critical point নয় — ধীর learning।
- সব positive → local minimum
- সব negative → local maximum
- Mixed sign → saddle point
Loss Landscape Visualization
Deep learning loss landscape-এর কিছু বৈশিষ্ট্য:
- High-dimensional: মিলিয়ন dimension — local minima কম common than expected।
- Saddle points are abundant: high dimension-এ saddle point-এর সংখ্যা local minimum-এর চেয়ে exponentially বেশি।
- Wide minima generalize better: sharp minimum (বড় Hessian eigenvalue) → overfitting; wide minimum → better generalization।
- Flat regions: batch gradient-এ plateau, SGD-এ noise সাহায্য করে escape।
Convergence Conditions
Gradient descent কখন converge?
- Strongly convex: exponential convergence — প্রতিটি step-ে error নির্দিষ্ট ratio-এ কমে।
- Convex, smooth: O(1/√T) rate — T step-এর পর error 1/√T হারে কমে।
- Non-convex: stationary point (gradient ≈ 0) পর্যন্ত converge — global minimum-এর guarantee নেই।
Smoothness condition (Lipschitz gradient):
Learning rate η ≤ 1/L হলে stable, η > 2/L হলে diverge।
Python Implementation
import numpy as np
import matplotlib.pyplot as plt
# 1) Convex vs Non-convex landscape
x = np.linspace(-3, 3, 400)
# Convex: f(x) = x^2
f_convex = x**2
# Non-convex: f(x) = x^2 + 2*sin(3x)
f_nonconvex = x**2 + 2*np.sin(3*x)
plt.figure(figsize=(12,4))
plt.subplot(1,2,1); plt.plot(x, f_convex); plt.title("Convex: x²")
plt.subplot(1,2,2); plt.plot(x, f_nonconvex); plt.title("Non-convex: x² + 2sin(3x)")
plt.tight_layout(); plt.show()
# 2) Gradient descent on non-convex function
# Starting from different points leads to different minima
def f(x): return x**2 + 2*np.sin(3*x)
def df(x): return 2*x + 6*np.cos(3*x)
lr = 0.05
for x0 in [-2.5, -1.0, 0.5, 2.0]:
x = x0
path = [x]
for _ in range(100):
x = x - lr * df(x)
path.append(x)
print(f"x0={x0:+.1f} → converged to x={path[-1]:+.4f}, f={f(path[-1]):.4f}")
# 3) 2D Saddle point: f(x,y) = x^2 - y^2
# Gradient = [2x, -2y] → (0,0) is a saddle
def f2d(x, y): return x**2 - y**2
def grad_f2d(x, y): return np.array([2*x, -2*y])
# Starting near saddle — can escape in y-direction
x, y = 0.1, 0.1
lr = 0.1
for step in range(20):
g = grad_f2d(x, y)
x -= lr * g[0]
y -= lr * g[1]
print(f"step {step:2d}: x={x:+.4f}, y={y:+.4f}, f={f2d(x,y):.4f}")
# Note: x shrinks to 0, but y explodes — saddle point!
# 4) Hessian eigenvalues at (0,0) for saddle
H = np.array([[2, 0], [0, -2]])
eigenvals, eigenvecs = np.linalg.eig(H)
print("Hessian eigenvalues:", eigenvals) # [2, -2] → saddleAI/ML সংযোগ
- Linear regression / logistic regression: convex — guaranteed global optimum।
- Deep neural networks: non-convex — local minima, saddle points, plateaus সবই আছে।
- Escape from saddle points: SGD noise + momentum — saddle point থেকে বের হওয়ার key।
- Wide vs sharp minima: learning rate decay + weight decay wide minimum prefer করে — better generalization।
- BatchNorm: loss landscape smooth করে — saddle point ও plateau কম স্পষ্ট হয়।
Common Mistakes
- Non-convex problem-কে convex ভেবে global optimum-এর guarantee ধরে নেওয়া।
- Saddle point-কে local minimum ভাবা — gradient 0 কিন্তু escape সম্ভব।
- Learning rate বড় হলে oscillation, ছোট হলে plateau-এ আটকে যাওয়া — দুটোই সমস্যা।
- All local minima are bad — reality: deep net-এ local minima often good enough।
Practice Tasks
- f(x) = x⁴ − 3x² + 2x-এর critical points বের করুন। কোনটা min, কোনটা max, কোনটা saddle?
- উপরের function-এ gradient descent চালান, দুটি ভিন্ন x₀ থেকে শুরু করে। কি পার্থক্য দেখেন?
- f(x,y) = x² + 4y²-এর contour plot draw করুন। gradient descent path দেখান।
- Convex function-এর definition দিয়ে prove করুন f(x) = x² convex।
Assignment
f(x, y) = (x² + y − 11)² + (x + y² − 7)² — Himmelblau's function — এ gradient descent চালান। ৫টি ভিন্ন starting point থেকে শুরু করে কোন local minimum-এ converge করে দেখুন। প্রতিটি minimum-এর function value ও coordinate লিখুন। (Hint: known global minima ≈ (3, 2), (−2.805, 3.131), (−3.779, −3.283), (3.584, −1.848))
Interview Questions
- Convex function-এর ৩টি equivalent definition বলুন।
- Deep neural network-এর loss landscape-এ local minima কতটা সমস্যা — why or why not?
- Saddle point থেকে escape করার উপায় কী?
- Wide minimum vs sharp minimum — কোনটা prefer করেন এবং কেন?
Mini Project
"Loss Landscape Explorer" — একটি 2D function (যেমন Himmelblau বা Rastrigin) এর contour plot আঁকুন। ১০টি random starting point থেকে gradient descent চালান এবং প্রতিটি path color-coded করে দেখান। কতগুলো distinct basin of attraction আছে তা গণনা করুন।
Summary · সারসংক্ষেপ
- Convex function → global minimum guaranteed, non-convex → multiple local optima।
- Critical points: local min, local max, saddle, plateau — saddle points high-D-তে বেশি common।
- Gradient descent converge, কিন্তু global minimum-এর guarantee শুধু convex-এ।
- Wide minima generalize better; SGD noise saddle escape ও wide minimum খুঁজতে সাহায্য করে।