Files
Masterprojekt-Campusnetz/Stochastisches_Modell.py
2025-12-16 14:03:31 +01:00

59 lines
2.4 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.

import sympy as sp
from dataclasses import dataclass, field
from typing import Dict, Tuple, Iterable
@dataclass
class StochastischesModell:
sigma_beob: Iterable[float] #σ a priori der einzelnen Beobachtung
gruppe_beob: Iterable[int] #Gruppenzugehörigkeit jeder Beobachtung (Distanz, Richtung, GNSS, Nivellement,...,)
sigma0_gruppe: Dict[int, float] = field(default_factory=dict) #σ0² für jede Gruppe
def __post_init__(self):
self.sigma_beob = sp.Matrix(list(self.sigma_beob)) #Spaltenvektor
self.gruppe_beob = sp.Matrix(list(self.gruppe_beob)) #Spaltenvektor
if self.sigma_beob.rows != self.gruppe_beob.rows:
raise ValueError("sigma_obs und group_ids müssen gleich viele Einträge haben.")
unique_groups = sorted({int(g) for g in self.gruppe_beob}) #jede Beobachtungsgruppe wird genau einmal berücksichtigt
for g in unique_groups:
if g not in self.sigma0_gruppe: #Fehlende Gruppen mit σ_0j^2 = 1.0
self.sigma0_gruppe[g] = 1.0
@property
def n_beob(self) -> int:
return int(self.sigma_beob.rows)
def berechne_Qll_P(self) -> Tuple[sp.Matrix, sp.Matrix]:
n = self.n_beob
Q_ll = sp.zeros(n, n)
P = sp.zeros(n, n)
for i in range(self.n_beob):
sigma_i = self.sigma_beob[i, 0] #σ-Wert der i-ten Beobachtung holen
g = int(self.gruppe_beob[i, 0]) #Gruppenzugehörigkeit der Beobachtung bestimmen
sigma0_sq = self.sigma0_gruppe[g] #Den Varianzfaktor der Gruppe holen
q_ii = sigma_i**2 #σ² berechnen
Q_ll[i, i] = q_ii #Diagonale
P[i, i] = 1 / (sigma0_sq * q_ii) #durch VKS nicht mehr P=Qll^-1
return Q_ll, P
def berechne_Qvv(self, A: sp.Matrix, P: sp.Matrix, Q_xx: sp.Matrix) -> sp.Matrix:
Q_vv = P.inv() - A * Q_xx * A.T
return Q_vv #Kofaktormatrix der Beobachtungsresiduen
def berechne_R(self, Q_vv: sp.Matrix, P: sp.Matrix) -> sp.Matrix:
R = Q_vv * P
return R #Redundanzmatrix
def berechne_r(self, R: sp.Matrix) -> sp.Matrix:
n = R.rows
r = sp.zeros(n, 1)
for i in range(n):
r[i, 0] = R[i, i]
return r #Redundanzanteile