mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-04-23 05:06:38 +00:00
Initial commit
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user