Files
Masterprojekt-Campusnetz/Parameterschaetzung.py
2025-12-09 16:03:27 +01:00

41 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from typing import Dict, Any
import sympy as sp
def ausgleichung_mit_vks_iterativ(
A: sp.Matrix,
l: sp.Matrix,
modell: StochastischesModell,
max_iter: int = 10,
tol: float = 1e-3,
) -> Dict[str, Any]:
"""
Führt eine iterative Ausgleichung mit Varianzkomponentenschätzung durch.
Ablauf:
- starte mit σ0,g² aus modell.sigma0_groups (meist alle = 1.0)
- wiederhole:
* Ausgleichung
* VKS
* Aktualisierung σ0,g²
bis sich alle σ̂0,g² ~ 1.0 (oder max_iter erreicht).
"""
history = [] # optional: Zwischenergebnisse speichern
for it in range(max_iter):
result = ausgleichung_einmal(A, l, modell)
history.append(result)
sigma_hat = result["sigma_hat"]
# Prüfkriterium: alle σ̂ nahe bei 1.0?
if all(abs(val - 1.0) < tol for val in sigma_hat.values()):
print(f"Konvergenz nach {it+1} Iterationen.")
break
# sonst: Modell-σ0,g² mit VKS-Ergebnis updaten
modell.update_sigma0_von_vks(sigma_hat)
# letztes Ergebnis + History zurückgeben
result["history"] = history
return result