66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
from typing import Dict, Any
|
|
import sympy as sp
|
|
from Stochastisches_Modell import StochastischesModell
|
|
|
|
def iterative_ausgleichung(
|
|
A: sp.Matrix,
|
|
l: sp.Matrix,
|
|
modell: StochastischesModell,
|
|
max_iter: int = 100,
|
|
tol: float = 1e-3,
|
|
) -> Dict[str, Any]:
|
|
|
|
ergebnisse_iter = [] #Liste für Zwischenergebnisse
|
|
|
|
for it in range(max_iter):
|
|
Q_ll, P = modell.berechne_Qll_P() #Stochastisches Modell: Qll und P berechnen
|
|
|
|
N = A.T * P * A #Normalgleichungsmatrix N
|
|
Q_xx = N.inv() #Kofaktormatrix der Unbekannten Qxx
|
|
n = A.T * P * l #Absolutgliedvektor n
|
|
|
|
dx = N.LUsolve(n) #Zuschlagsvektor dx
|
|
|
|
v = l - A * dx #Residuenvektor v
|
|
|
|
Q_vv = modell.berechne_Qvv(A, Q_ll, Q_xx) #Kofaktormatrix der Verbesserungen Qvv
|
|
R = modell.berechne_R(Q_vv, P) #Redundanzmatrix R
|
|
r = modell.berechne_r(R) #Redundanzanteile als Vektor r
|
|
|
|
sigma_hat = modell.berechne_vks(v, P, r) #Varianzkomponentenschätzung durchführen
|
|
|
|
ergebnisse_iter.append({ #Zwischenergebnisse speichern in Liste
|
|
"iter": it + 1,
|
|
"Q_ll": Q_ll,
|
|
"P": P,
|
|
"N": N,
|
|
"Q_xx": Q_xx,
|
|
"dx": dx,
|
|
"v": v,
|
|
"Q_vv": Q_vv,
|
|
"R": R,
|
|
"r": r,
|
|
"sigma_hat": sigma_hat,
|
|
"sigma0_groups": dict(modell.sigma0_groups),
|
|
})
|
|
|
|
if all(abs(val - 1.0) < tol for val in sigma_hat.values()): #Abbruchkriterium
|
|
print(f"Konvergenz nach {it + 1} Iterationen erreicht.")
|
|
break
|
|
|
|
modell.update_sigma0_von_vks(sigma_hat)
|
|
|
|
return {
|
|
"dx": dx,
|
|
"v": v,
|
|
"Q_ll": Q_ll,
|
|
"P": P,
|
|
"N": N,
|
|
"Q_xx": Q_xx,
|
|
"Q_vv": Q_vv,
|
|
"R": R,
|
|
"r": r,
|
|
"sigma_hat": sigma_hat,
|
|
"sigma0_groups": dict(modell.sigma0_groups),
|
|
"history": ergebnisse_iter,
|
|
} |