41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
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 |