fix: исправить drift bug в PyTorch net.py (критический)

PyTorch _apply_s2 имел ту же ошибку что и core.py:
- отсутствовал completion-of-square factor exp(b²τ/(4a))
- отсутствовал drift phase shift exp(2πi·k·b_mean·τ)

Это приводило к неправильным результатам RemizovNet и
EquationDiscoverer для уравнений с b≠0.

Добавлены тесты:
- test_s2_fft_matches_direct_with_drift (core, b=1.0)
- test_s2_with_drift (PyTorch layer)
- ужесточён tolerance: atol=0.15 → rtol=0.05

21 тестов проходят.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-05 22:27:53 +10:00
co-authored by Claude Opus 4.6
parent e79e2c64f3
commit 10d2aa284a
3 changed files with 52 additions and 15 deletions
+14 -3
View File
@@ -37,14 +37,25 @@ class TestChernoffStep:
np.testing.assert_allclose(result[interior], 3.0, atol=0.1)
def test_s2_fft_matches_direct(self):
"""FFT-based S₂ should approximate direct computation."""
"""FFT-based S₂ should approximate direct computation (b=0)."""
f = np.exp(-self.x**2)
# For constant coefficients, FFT should be close to direct
result_direct = self.step.apply_s2(f, tau=0.05)
result_fft = self.step.apply_s2_fft(f, tau=0.05)
interior = slice(20, 80)
np.testing.assert_allclose(
result_fft[interior], result_direct[interior], atol=0.15
result_fft[interior], result_direct[interior], rtol=0.05,
)
def test_s2_fft_matches_direct_with_drift(self):
"""FFT-based S₂ should match direct computation when b != 0."""
coeffs = ODECoefficients(a=0.5, b=1.0, c=0.0)
step = ChernoffStep(coeffs, self.x)
f = np.exp(-self.x**2)
result_direct = step.apply_s2(f, tau=0.05)
result_fft = step.apply_s2_fft(f, tau=0.05)
interior = slice(20, 80)
np.testing.assert_allclose(
result_fft[interior], result_direct[interior], rtol=0.05,
)
def test_potential_computation(self):