📖 একটি ছোট গল্প
একটি bowl-এর ভেতরে marble ছেড়ে দিন — যেদিকেই গড়াক, শেষে একই bottom-এ গিয়ে থামে। এটাই convex function-এর সৌন্দর্য — একটিমাত্র global minimum, কোনো local trap নেই। Optimization-এ convexity = guarantee।
Convex Set & Function
Convex set
Set C convex যদি যেকোনো x, y ∈ C-এর জন্য line segment λx + (1−λ)y ∈ C (∀λ ∈ [0,1])।
Convex function
f(λx + (1−λ)y) ≤ λf(x) + (1−λ)f(y)
অর্থাৎ chord function-এর উপরে। Strict inequality হলে strictly convex।
Convexity Tests
- First-order: f(y) ≥ f(x) + ∇f(x)ᵀ(y−x) — tangent function-এর নিচে।
- Second-order: Hessian ∇²f ⪰ 0 (positive semi-definite)।
- 1D: f″(x) ≥ 0।
Examples
- Convex: x², ex, |x|, −log x, MSE, logistic loss।
- Non-convex: sin x, deep neural network loss, x³।
Convexity-Preserving Operations
- Non-negative weighted sum: α₁f₁ + α₂f₂ convex (αᵢ ≥ 0)।
- Pointwise max: max(f₁, f₂) convex।
- Composition with affine: f(Ax + b) convex।
- L2 regularizer + convex loss = convex problem।
কেন AI-তে গুরুত্বপূর্ণ
- Convex problem-এ local min = global min — gradient descent guaranteed optimal।
- Linear/Logistic regression, SVM, Lasso — সব convex।
- Deep neural network non-convex — তবুও SGD ভালো solution পায় (over-parameterization-এর জাদু)।
💡 ইনসাইট
Modern theory: large neural net-এর loss landscape "mostly benign" — অনেক local min প্রায় equally ভালো। Saddle point বেশি problematic, কিন্তু SGD-এর noise সহজে escape করে।
Python Implementation
pythonPython · NumPy
import numpy as np
# Check convexity numerically: f(λx + (1-λ)y) ≤ λf(x) + (1-λ)f(y)
def is_convex(f, low=-5, high=5, n=200):
xs = np.random.uniform(low, high, n)
ys = np.random.uniform(low, high, n)
lambdas = np.random.uniform(0, 1, n)
lhs = f(lambdas * xs + (1 - lambdas) * ys)
rhs = lambdas * f(xs) + (1 - lambdas) * f(ys)
return np.all(lhs <= rhs + 1e-9)
print("x^2 convex?", is_convex(lambda x: x**2))
print("e^x convex?", is_convex(lambda x: np.exp(x)))
print("|x| convex?", is_convex(lambda x: np.abs(x)))
print("sin x convex?", is_convex(lambda x: np.sin(x)))
print("-x^2 convex?", is_convex(lambda x: -x**2)) # concave
# Hessian test for f(x,y) = x^2 + 3y^2
H = np.array([[2, 0], [0, 6]])
eigs = np.linalg.eigvalsh(H)
print(f"\nHessian eigenvalues: {eigs} → PSD? {np.all(eigs >= 0)}")AI/ML সংযোগ
- Linear regression MSE = convex quadratic — closed form solution।
- Logistic regression NLL = convex — global optimum guaranteed।
- SVM hinge loss + L2 = convex quadratic program।
- Deep nets non-convex, কিন্তু কিছু layer (last linear layer, BN) locally convex behavior দেখায়।
Common Mistakes
- "Smooth" এবং "convex" একই ভাবা — |x| convex কিন্তু non-smooth।
- Concave function-কে convex বলা — sign flip করলেই হবে।
- Composition rule ভুল apply — f(g(x)) convex হতে g monotone হওয়া দরকার।
Practice Tasks
- f(x) = x⁴ convex কিনা — second derivative দিয়ে দেখান।
- f(x, y) = x² + y² − 2xy-এর Hessian বের করে convexity check।
- Softplus log(1 + eˣ) convex কিনা?
Assignment
৫টি common ML loss function (MSE, MAE, Huber, Logistic, Hinge) plot করে দেখান কোনগুলো convex। প্রত্যেকটির জন্য first ও second derivative analytically derive করুন এবং convexity prove/disprove করুন।
Interview Questions
- Convex function-এ local min = global min কেন?
- Neural network loss non-convex হওয়া সত্ত্বেও কেন SGD কাজ করে?
- L1 vs L2 regularizer — দুটোই convex?
Mini Project
"Convexity Visualizer" — 2D function-এর Hessian eigenvalue দেখিয়ে color-code করুন (positive = convex region, negative = concave, mixed = saddle)।
Summary · সারসংক্ষেপ
- Convex function = chord function-এর উপরে; Hessian PSD।
- Convex problem-এ local min = global min — optimization easy।
- Classical ML (LR, SVM) convex; deep learning non-convex কিন্তু practice-এ tractable।
- Convexity-preserving operations দিয়ে নতুন convex problem build করা যায়।
✨ পরবর্তী পদক্ষেপ
Chapter 28-এ Cost Functions — model কীভাবে "ভুল" মাপে।