Changeset 11212 in ntrip for trunk/BNC/src/combination/bnccomb.cpp
- Timestamp:
- Nov 18, 2026, 12:25:58 PM (93 minutes ago)
- File:
-
- 1 edited
-
trunk/BNC/src/combination/bnccomb.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/src/combination/bnccomb.cpp
r11205 r11212 1262 1262 // Update and outlier detection loop 1263 1263 // --------------------------------- 1264 SymmetricMatrix QQ_sav = _QQ[sys]; 1264 SymmetricMatrix QQ_sav = _QQ[sys]; 1265 QVector<t_datumObs> datumObs; // all corrections of the epoch, incl. outliers 1265 1266 while (_running) { 1266 1267 … … 1273 1274 } 1274 1275 1276 if (datumObs.isEmpty()) { 1277 bool referredAC = false; 1278 for (int ii = 0; ii < corrs(sys).size(); ii++) { 1279 const cmbCorr* corr = corrs(sys)[ii]; 1280 t_datumObs dObs; 1281 dObs.ac = corr->_acName; 1282 dObs.prn = corr->_prn; 1283 dObs.value = ll(ii+1) + DotProduct(AA.Row(ii+1), x0); 1284 dObs.iAC = 0; 1285 dObs.iSat = 0; 1286 dObs.referred = !_biasInconsistent.contains(corr->_acName + sys) && corr->_refBiasesOK; 1287 dObs.rejected = false; 1288 referredAC = referredAC || dObs.referred; 1289 for (int iPar = 1; iPar <= nPar; iPar++) { 1290 const cmbParam* pp = _params[sys][iPar-1]; 1291 if (pp->type == cmbParam::offACgnss && pp->AC == corr->_acName) { 1292 dObs.iAC = iPar; 1293 } 1294 else if (pp->type == cmbParam::clkSat && pp->prn == corr->_prn) { 1295 dObs.iSat = iPar; 1296 } 1297 } 1298 datumObs.push_back(dObs); 1299 } 1300 if (!referredAC) { // as in createAmat: then all clocks define the datum 1301 for (t_datumObs& dObs : datumObs) { 1302 dObs.referred = true; 1303 } 1304 } 1305 } 1306 1275 1307 dx.ReSize(nPar); dx = 0.0; 1276 1308 kalman(AA, ll, PP, _QQ[sys], dx); … … 1278 1310 ColumnVector vv = ll - AA * dx; 1279 1311 1312 // outliers among the observations only (not the conditions) 1280 1313 int maxResIndex; 1281 double maxRes = vv.maximum_absolute_value1(maxResIndex); 1314 double maxRes = vv.Rows(1, corrs(sys).size()).maximum_absolute_value1(maxResIndex); 1282 1315 out.setRealNumberNotation(QTextStream::FixedNotation); 1283 1316 out.setRealNumberPrecision(3); … … 1300 1333 _outlierStat[sys][corrs(sys)[maxResIndex-1]->_acName + ' ' + 1301 1334 corrs(sys)[maxResIndex-1]->_prn.mid(0,3)].residuals.push_back(maxRes); 1335 for (t_datumObs& dObs : datumObs) { 1336 if (dObs.ac == corrs(sys)[maxResIndex-1]->_acName && 1337 dObs.prn == corrs(sys)[maxResIndex-1]->_prn) { 1338 dObs.rejected = true; 1339 } 1340 } 1302 1341 _QQ[sys] = QQ_sav; 1303 1342 delete corrs(sys)[maxResIndex-1]; … … 1317 1356 out.setFieldWidth(0); 1318 1357 } 1358 updateDatum(epoTime, sys, out, datumObs, x0 + dx); 1319 1359 break; 1320 1360 } … … 1401 1441 // exclusion the offsets are reset and not yet converged, so a single 1402 1442 // passing check does not prove consistency; a borderline AC would 1403 // otherwise change the clock datum every few minutes. 1404 const int REINCLUDE_CHECKS = 12; 1443 // otherwise change the clock datum every few minutes. Each change of the 1444 // datum shifts the combined clocks of the system, so the number of 1445 // passing checks required is doubled with each further exclusion of the 1446 // AC (up to 16 hours). 1447 const int REINCLUDE_CHECKS = 12 << std::min(4, std::max(0, _biasExclusions.value(key) - 1)); 1405 1448 if (spread < MIN_SPREAD || slope < MIN_SLOPE || corrCoeff < MIN_CORR) { 1406 1449 if (_biasInconsistent.contains(key) && ++_biasConsistentChecks[key] < REINCLUDE_CHECKS) { … … 1433 1476 if (!_biasInconsistent.contains(key)) { 1434 1477 _biasInconsistent.insert(key); 1478 ++_biasExclusions[key]; 1435 1479 msg += ", AC excluded from the clock datum"; 1436 1480 _biasCheckWarned.remove(key); … … 1515 1559 } 1516 1560 1561 // Robust clock datum 1562 //////////////////////////////////////////////////////////////////////////// 1563 // A persistent clock difference of one AC for a satellite cannot be absorbed 1564 // by its satellite offset as long as the offset is in the zero-sum condition 1565 // of the satellite: either it shifts the combined clock (accepted, e.g. at 1566 // the start of the filter) or the correction is rejected in every epoch 1567 // (outlier lock-in), depending on the history of the filter. Therefore, per 1568 // satellite, the satellite-specific clock difference of each AC referred to 1569 // the reference signals 1570 // u = clock - AC offset - combined clock 1571 // (rejected corrections included) is compared with the median of the ACs. 1572 // An offset rejected as outlier for DATUM_OUT_SEC leaves the zero-sum 1573 // conditions (satellite and AC) and is re-initialized: it then absorbs the 1574 // constant difference, and the AC contributes to the variation of the 1575 // combined clock only. This applies to any number of ACs, as long as another 1576 // offset of the satellite stays in the datum (otherwise a rejected offset in 1577 // the datum would shift the combined clock). For satellites with at least 1578 // DATUM_MIN_AC ACs, an offset deviating by more than DATUM_OUT_DEV for 1579 // DATUM_OUT_SEC leaves as well, as long as a majority of the ACs stays in. 1580 // An offset rejoins the datum after a deviation below DATUM_IN_DEV (at most 1581 // half of the maximum residual) without rejection for DATUM_IN_SEC. ACs not 1582 // referred to the reference signals are excluded from the datum anyway and 1583 // not judged. 1584 //////////////////////////////////////////////////////////////////////////// 1585 void bncComb::updateDatum(bncTime epoTime, char sys, QTextStream& out, 1586 const QVector<t_datumObs>& datumObs, const ColumnVector& xx) { 1587 1588 const int DATUM_MIN_AC = 3; 1589 const double DATUM_OUT_DEV = std::min(0.5, _MAX_RES); // [m] 1590 const double DATUM_OUT_SEC = 60.0; 1591 const double DATUM_IN_DEV = 0.5 * DATUM_OUT_DEV; // [m] 1592 const double DATUM_IN_SEC = 600.0; 1593 const double DATUM_FORGET = 3600.0; // state of offsets not provided for this time is dropped 1594 1595 QMap<QString, t_datumState>& states = _datumState[sys]; 1596 1597 // parameters observed by accepted corrections 1598 QSet<int> observed; 1599 for (const t_datumObs& dObs : datumObs) { 1600 if (!dObs.rejected) { 1601 observed << dObs.iAC << dObs.iSat; 1602 } 1603 } 1604 1605 // satellite-specific clock differences per satellite 1606 QMap<QString, QVector<const t_datumObs*> > satObs; 1607 QMap<QString, double> uu; // key "AC PRN" 1608 for (const t_datumObs& dObs : datumObs) { 1609 QString key = dObs.ac + ' ' + dObs.prn; 1610 states[key].lastSeen = epoTime; 1611 states[key].referred = dObs.referred; 1612 if (dObs.referred && dObs.iAC && dObs.iSat && 1613 observed.contains(dObs.iAC) && observed.contains(dObs.iSat)) { 1614 uu[key] = dObs.value - xx(dObs.iAC) - xx(dObs.iSat); 1615 satObs[dObs.prn].push_back(&dObs); 1616 } 1617 } 1618 1619 QMapIterator<QString, QVector<const t_datumObs*> > itSat(satObs); 1620 while (itSat.hasNext()) { 1621 itSat.next(); 1622 const QVector<const t_datumObs*>& obs = itSat.value(); 1623 const bool robust = (obs.size() >= DATUM_MIN_AC); // median meaningful 1624 QVector<double> uSat; 1625 for (const t_datumObs* dObs : obs) { 1626 uSat.push_back(uu[dObs->ac + ' ' + dObs->prn]); 1627 } 1628 std::sort(uSat.begin(), uSat.end()); 1629 int nn = uSat.size(); 1630 double median = (nn % 2) ? uSat[nn/2] : 0.5 * (uSat[nn/2-1] + uSat[nn/2]); 1631 1632 // a majority of the ACs stays in the datum (e.g. two groups of ACs with 1633 // a clock difference: the median is not meaningful); the offsets with the 1634 // largest deviations leave first 1635 const int minIn = std::max(2, (nn + 1) / 2); 1636 int numIn = 0; 1637 QVector<const t_datumObs*> order = obs; 1638 for (const t_datumObs* dObs : obs) { 1639 QString key = dObs->ac + ' ' + dObs->prn; 1640 states[key].dev = uu[key] - median; 1641 if (!states[key].out) { 1642 ++numIn; 1643 } 1644 } 1645 std::stable_sort(order.begin(), order.end(), 1646 [&states](const t_datumObs* aa, const t_datumObs* bb) { 1647 return fabs(states[aa->ac + ' ' + aa->prn].dev) > 1648 fabs(states[bb->ac + ' ' + bb->prn].dev); 1649 }); 1650 1651 for (const t_datumObs* dObs : order) { 1652 QString key = dObs->ac + ' ' + dObs->prn; 1653 t_datumState& state = states[key]; 1654 bool change = state.out ? (fabs(state.dev) < DATUM_IN_DEV && !dObs->rejected) 1655 : (dObs->rejected || (robust && fabs(state.dev) > DATUM_OUT_DEV)); 1656 if (!change) { 1657 state.since.reset(); 1658 continue; 1659 } 1660 if (!state.since.valid()) { 1661 state.since = epoTime; 1662 } 1663 double duration = epoTime - state.since; 1664 if (duration < (state.out ? DATUM_IN_SEC : DATUM_OUT_SEC)) { 1665 continue; 1666 } 1667 // a rejected offset leaves as long as another one stays in, a deviating 1668 // (accepted) one only as long as a majority stays in 1669 if (!state.out && numIn - 1 < (dObs->rejected ? 1 : minIn)) { 1670 continue; 1671 } 1672 QString msg; 1673 if (!state.out) { 1674 --numIn; 1675 state.out = true; 1676 state.outSince = epoTime; 1677 msg = QString("%1 %2 out of the clock datum: deviation %3 m from the median of %4 ACs%5") 1678 .arg(dObs->ac).arg(dObs->prn.mid(0,3)) 1679 .arg(state.dev, 0, 'f', 2).arg(nn) 1680 .arg(dObs->rejected ? QString(", rejected as outlier for %1 s").arg(duration, 0, 'f', 0) : QString()); 1681 // re-initialize the offset: it absorbs the difference from now on 1682 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) { 1683 cmbParam* pp = _params[sys][iPar-1]; 1684 if (pp->type == cmbParam::offACSat && pp->AC == dObs->ac && pp->prn == dObs->prn) { 1685 _QQ[sys].Row(iPar) = 0.0; 1686 _QQ[sys].Column(iPar) = 0.0; 1687 _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0; 1688 } 1689 } 1690 } 1691 else { 1692 ++numIn; 1693 state.out = false; 1694 msg = QString("%1 %2 back in the clock datum: deviation %3 m from the median of %4 ACs " 1695 "(below %5 m for %6 s)") 1696 .arg(dObs->ac).arg(dObs->prn.mid(0,3)) 1697 .arg(state.dev, 0, 'f', 2).arg(nn) 1698 .arg(DATUM_IN_DEV, 0, 'f', 2).arg(duration, 0, 'f', 0); 1699 } 1700 state.since.reset(); 1701 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str() << " " << msg << "\n"; 1702 emit newLogRecord(t_logRecord::message(t_logRecord::info, "bncComb: " + msg.toLatin1()), true); 1703 } 1704 } 1705 1706 // drop the state of offsets no longer provided 1707 QMutableMapIterator<QString, t_datumState> itState(states); 1708 while (itState.hasNext()) { 1709 itState.next(); 1710 if (epoTime - itState.value().lastSeen > DATUM_FORGET) { 1711 itState.remove(); 1712 } 1713 } 1714 } 1715 1517 1716 // Report AC satellites rejected as outliers in most epochs 1518 1717 //////////////////////////////////////////////////////////////////////////// 1519 // A persistent clock difference of oneAC for a satellite cannot be absorbed1520 // by itssatelliteoffset, as the offsets of all ACs of the satellite sum up1521 // to zero: the correction is rejected again in every epoch. Once per hour1522 // and system, AC satellites rejected in atleast half of their epochs are1523 // reported.1718 // Corrections of an AC for a satellite can still be rejected persistently, 1719 // e.g. for satellites with fewer than DATUM_MIN_AC ACs (see updateDatum) or 1720 // for noisy clocks. Once per hour and system, AC satellites rejected in at 1721 // least half of their epochs are reported, as well as the offsets out of 1722 // the clock datum. 1524 1723 //////////////////////////////////////////////////////////////////////////// 1525 1724 void bncComb::checkPersistentOutliers(bncTime epoTime, char sys, QTextStream& out) { … … 1552 1751 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str() << " " << msg << "\n"; 1553 1752 emit newLogRecord(t_logRecord::message(t_logRecord::warning, "bncComb: " + msg.toLatin1()), true); 1753 } 1754 QStringList outList; 1755 QMapIterator<QString, t_datumState> itState(_datumState[sys]); 1756 while (itState.hasNext()) { 1757 itState.next(); 1758 const t_datumState& state = itState.value(); 1759 if (state.out) { 1760 QStringList hlp = itState.key().split(' '); 1761 outList << QString("%1 %2 (%3 m, since %4 %5)") 1762 .arg(hlp[0]).arg(hlp[1].mid(0,3)).arg(state.dev, 0, 'f', 2) 1763 .arg(state.outSince.datestr().c_str()).arg(state.outSince.timestr(0).c_str()); 1764 } 1765 } 1766 if (!outList.isEmpty()) { 1767 QString msg = QString("%1 satellite offsets out of the clock datum: ").arg(sys) + outList.join(", "); 1768 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str() << " " << msg << "\n"; 1769 emit newLogRecord(t_logRecord::message(t_logRecord::info, "bncComb: " + msg.toLatin1()), true); 1554 1770 } 1555 1771 _outlierStat[sys].clear(); … … 1870 2086 } 1871 2087 2088 // Offsets out of the robust clock datum (see updateDatum) and the nominal 2089 // datum per satellite: offsets in the datum, provided within the last hour 2090 QSet<QString> outOfDatum; // "AC PRN" (full PRN) 2091 QMap<QString, QSet<QString> > nominalDatum; // PRN -> "AC PRN" 2092 if (_method == filter) { 2093 QMapIterator<QString, t_datumState> itState(_datumState[sys]); 2094 while (itState.hasNext()) { 2095 itState.next(); 2096 const t_datumState& state = itState.value(); 2097 if (state.out) { 2098 outOfDatum.insert(itState.key()); 2099 } 2100 else if (state.referred && 2101 !_biasInconsistent.contains(itState.key().section(' ', 0, 0) + sys)) { 2102 nominalDatum[itState.key().section(' ', 1, 1)].insert(itState.key()); 2103 } 2104 } 2105 } 2106 1872 2107 // ACs of this epoch, each with a zero-sum condition of its satellite offsets 1873 2108 QStringList epoACs; … … 1951 2186 // } 1952 2187 int iCond = 1; 2188 QSet<int> incrementRows; // conditions on the increments (continuity) 2189 QSet<int> offIncrement; // offsets in satellite conditions on the increments 1953 2190 QSet<int> offExcluded; // offsets excluded from the zero-sum condition of their satellite 1954 2191 QSet<int> offInDatum; // offsets in the zero-sum condition of their satellite … … 1960 2197 ++iCond; 1961 2198 PP(nObs+iCond) = Ph; 1962 QList<int> offAll, offConsistent; 2199 QList<int> offAll, offConsistent, offRobust; 2200 QSet<QString> robustKeys; 1963 2201 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) { 1964 2202 cmbParam* pp = _params[sys][iPar-1]; … … 1970 2208 if (!excludedOff.contains(pp->AC + ' ' + pp->prn)) { 1971 2209 offConsistent << iPar; 2210 if (!outOfDatum.contains(pp->AC + ' ' + pp->prn)) { 2211 offRobust << iPar; 2212 robustKeys.insert(pp->AC + ' ' + pp->prn); 2213 } 1972 2214 } 1973 2215 } 1974 2216 } 1975 // satellite observed by inconsistent ACs only: all its offsets are used 1976 const QList<int>& offUsed = offConsistent.isEmpty() ? offAll : offConsistent; 2217 // The condition refers to the values of the offsets (see below) only if 2218 // all offsets of the nominal datum of the satellite are present. If one 2219 // of them is missing in this epoch (data gap of the AC, correction 2220 // rejected as outlier in this iteration), the sum of the present ones 2221 // is kept (condition on the increments): otherwise the gap would shift 2222 // the combined clock by the offsets of the remaining ACs. 2223 const QSet<QString>& nominal = nominalDatum[prn]; 2224 bool complete = true; 2225 for (const QString& key : nominal) { 2226 if (!robustKeys.contains(key)) { 2227 complete = false; 2228 break; 2229 } 2230 } 2231 if (!complete) { 2232 incrementRows.insert(iCond); 2233 for (int iPar : offRobust) { 2234 offIncrement << iPar; 2235 } 2236 } 2237 // satellite observed by inconsistent ACs only: all its offsets are used; 2238 // all consistent offsets out of the robust datum: these are used. If 2239 // the nominal datum of the satellite is missing completely, the offsets 2240 // out of the datum only keep their sum (increments, see above) and are 2241 // not used in the conditions of their ACs: they must not define the 2242 // clock datum (their differences to the datum ACs are the reason for 2243 // their exclusion). 2244 const bool keepOnly = offRobust.isEmpty() && !nominal.isEmpty(); 2245 const QList<int>& offUsed = !offRobust.isEmpty() ? offRobust : 2246 !offConsistent.isEmpty() ? offConsistent : offAll; 1977 2247 for (int iPar : offAll) { 1978 if (offUsed.contains(iPar)) { 2248 if (keepOnly && offUsed.contains(iPar)) { 2249 AA(nObs+iCond, iPar) = 1.0; 2250 } 2251 else if (offUsed.contains(iPar)) { 1979 2252 AA(nObs+iCond, iPar) = 1.0; 1980 2253 offInDatum << iPar; … … 2002 2275 if (_params[sys][iPar-1]->AC == acName) { 2003 2276 AA(nObs+iCond, iPar) = 1.0; 2004 } 2277 // an offset kept by its satellite condition (increments) cannot 2278 // follow a condition of the AC on the values: both on the increments 2279 if (offIncrement.contains(iPar)) { 2280 incrementRows.insert(iCond); 2281 } 2282 } 2283 } 2284 } 2285 // The conditions refer to the parameter values, not to their increments: 2286 // with ll = 0, a sum would keep its value of the previous epoch, which 2287 // differs from zero after a change of the offsets in the condition (an 2288 // offset out of or back in the datum, a satellite no longer provided by 2289 // an AC for more than an hour), leaving the datum to the history of the 2290 // filter. Exception: incomplete nominal datum of a satellite (see above). 2291 for (int iCon = 1; iCon <= nCon; iCon++) { 2292 if (!incrementRows.contains(iCon)) { 2293 ll(nObs+iCon) = -DotProduct(AA.Row(nObs+iCon), x0); 2005 2294 } 2006 2295 }
Note:
See TracChangeset
for help on using the changeset viewer.
