← 문제 목록/Hard Thresholding (L0 sparsity)
문제 해설

Hard Thresholding (L0 sparsity)

최적화 · easy

preview

Hard Thresholding

66번 Soft Thresholding 은 L1 정규화의 proximal 연산자 — 작은 값은 0, 큰 값은 축소. Hard thresholding 은 "축소" 없이 그대로 보존:

Hλ(x)={xx>λ0xλH_\lambda(x) = \begin{cases} x & |x| > \lambda \\ 0 & |x| \le \lambda \end{cases}

"작으면 버리고, 크면 안 건드린다".

Soft vs Hard

연산큰 값 처리Sparsity볼록성
Soft$x- \lambda$ 로 축소
Hard그대로희소비볼록 (L0 proximal)

어디에 쓰이나

  • Iterative Hard Thresholding (IHT): compressed sensing, sparse recovery.
  • OMP / Matching Pursuit: k-sparse 추정 (top-k 유지).
  • Sparse coding: dictionary learning 의 coefficient update.
  • 특성 선택: 작은 회귀 계수 제거 (post-hoc).

주의

  • x=λ|x| = \lambda 에서 왼쪽을 0 으로 (convention).
  • 경사하강엔 부적합: 불연속 → gradient 정의 안 됨.

과제

함수 hard_threshold(x, lam) 을 완성하세요.

  • 스칼라/배열 x, 양수 lam.
  • 반환: 같은 shape. |x| > lam 이면 x, 아니면 0.
  • 힌트: np.where(np.abs(x) > lam, x, 0).

테스트 케이스

#이름입력기대
1작은 값 → 0x=0.3, λ=0.50
2큰 양수 → 그대로x=1.2, λ=0.51.2 (축소 X)
3경계값x=0.5, λ=0.50
4벡터[-2, -0.3, 0, 0.3, 2], λ=0.5[-2, 0, 0, 0, 2]
5Soft 와 다름x=3, λ=1 → hard=3, soft=2
코드 작성
Loading...
실행 결과

코드를 작성하고 Run 을 눌러보세요.