Initial commit

This commit is contained in:
Denys Zaitsev
2026-04-03 23:25:54 +03:00
parent 531a1301d5
commit d7e1066c60
3843 changed files with 1554468 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import pytest
import numpy as np
from h03_robust_kernels import RobustKernels
@pytest.fixture
def kernels():
return RobustKernels()
class TestRobustKernels:
def test_huber_kernel_scalar(self, kernels):
# Inlier (r <= threshold): 0.5 * r^2
assert kernels.huber_loss(1.0, 2.0) == 0.5 * (1.0 ** 2)
assert kernels.compute_weight(1.0, "huber", {"threshold": 2.0}) == 1.0
# Outlier (r > threshold): threshold * (|r| - 0.5 * threshold)
assert kernels.huber_loss(3.0, 2.0) == 2.0 * (3.0 - 0.5 * 2.0)
assert kernels.compute_weight(3.0, "huber", {"threshold": 2.0}) == 2.0 / 3.0
def test_cauchy_kernel_scalar(self, kernels):
assert kernels.cauchy_loss(0.0, 1.0) == 0.0
assert np.isclose(kernels.cauchy_loss(1.0, 1.0), 0.5 * np.log(2.0))
assert kernels.compute_weight(0.0, "cauchy", {"k": 1.0}) == 1.0
assert kernels.compute_weight(1.0, "cauchy", {"k": 1.0}) == 0.5
assert kernels.compute_weight(3.0, "cauchy", {"k": 1.0}) == 0.1