S2-Vorhersage: Pool ueber pool_in (Rueckfall Gleichverteilung), Zeitschnitt im Strom-Leser statt eigener Schleife
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//! (Knoten des Sitzes aus der Lage, wie `_gedaechtnis` mit `anfrage`) oder `{"id": ..., "vw": "<vw>", "knoten": code}`.
|
||||
//! Ausgabe je Zeile: `{"id", "code", "name", "p": [6 Haeufigkeiten], "n", "n_eff", "prior", "pool", "haende"}` (ungerundet) oder `{"id", "fehler"}`.
|
||||
//! Ohne `strom_bis` zaehlt nur basis.bin; mit `strom_bis` zusaetzlich die Haende aus strom.jsonl vor dieser Zeit.
|
||||
use crate::speicher::{hoch, knoten_aus_anfrage, name, schaetze_in, vw_zahl, Live};
|
||||
use crate::speicher::{knoten_aus_anfrage, name, pool_in, schaetze_in, vw_zahl, Live};
|
||||
use serde_json::{json, Value};
|
||||
use std::io::{BufRead, Write};
|
||||
|
||||
@@ -23,7 +23,7 @@ fn eine_zeile(l: &mut Live, z: &Value) -> Value {
|
||||
},
|
||||
};
|
||||
let s = schaetze_in(l, vw_zahl(&vw), code);
|
||||
let pool = (0..3).find_map(|lvl| l.m.pool_von(lvl, hoch(code, lvl as u8)));
|
||||
let pool = pool_in(l, code);
|
||||
let haende = vw_zahl(&vw).and_then(|i| l.sp.sp.get(&i)).map_or(0, |x| x.haende);
|
||||
json!({"id": id, "code": code, "name": name(code), "p": s.p, "n": s.n, "n_eff": s.n_eff, "prior": s.prior, "pool": pool, "haende": haende})
|
||||
}
|
||||
|
||||
@@ -778,7 +778,7 @@ pub struct Schaetzung {
|
||||
}
|
||||
|
||||
impl Modell {
|
||||
pub(crate) fn pool_von(&self, lvl: usize, c: u16) -> Option<[f64; A]> {
|
||||
fn pool_von(&self, lvl: usize, c: u16) -> Option<[f64; A]> {
|
||||
self.pool[lvl].get(&c).copied()
|
||||
}
|
||||
/// Haeufigkeit von Typ t (None = Pool) auf Stufe lvl, Knoten c (Code dieser Stufe).
|
||||
@@ -915,15 +915,9 @@ impl Live {
|
||||
pub fn aus_ordner(ordner: &str, strom_bis: Option<i64>) -> Option<Live> {
|
||||
let mut sp = Speicher::lies(&format!("{ordner}/basis.bin"))?;
|
||||
let m = Modell::lies(&format!("{ordner}/modell.json"))?;
|
||||
if let Some(bis) = strom_bis {
|
||||
if strom_bis.is_some() {
|
||||
let f = std::fs::File::open(format!("{ordner}/strom.jsonl")).ok()?;
|
||||
for z in std::io::BufReader::new(f).split(b'\n').map_while(Result::ok) {
|
||||
if let Ok(h) = serde_json::from_slice::<Value>(&z) {
|
||||
if h["t"].as_f64().is_some_and(|t| t < bis as f64) {
|
||||
sp.verbuche(&h);
|
||||
}
|
||||
}
|
||||
}
|
||||
strom_lesen_vor(&mut sp, std::io::BufReader::new(f), strom_bis);
|
||||
}
|
||||
Some(Live { sp, m, strom: None })
|
||||
}
|
||||
@@ -951,11 +945,18 @@ pub fn ordner() -> Option<String> {
|
||||
/// Verbucht den Strom Zeile fuer Zeile (Bytezeilen): eine kaputte Zeile (kein UTF-8, kein JSON, abgebrochen) wird uebergangen,
|
||||
/// die folgenden zaehlen weiter. Rueckgabe: Zahl der neu verbuchten Haende.
|
||||
pub fn strom_lesen(sp: &mut Speicher, r: impl std::io::BufRead) -> usize {
|
||||
strom_lesen_vor(sp, r, None)
|
||||
}
|
||||
|
||||
/// Wie `strom_lesen`, aber mit `vor` = Some(Unix-Sekunden) nur Haende mit Zeit `t` < `vor` (zeitlicher Schnitt fuer Pruefungen).
|
||||
pub fn strom_lesen_vor(sp: &mut Speicher, r: impl std::io::BufRead, vor: Option<i64>) -> usize {
|
||||
let mut n = 0;
|
||||
for z in r.split(b'\n') {
|
||||
let Ok(z) = z else { break };
|
||||
if let Ok(h) = serde_json::from_slice::<Value>(&z) {
|
||||
n += sp.verbuche(&h) as usize;
|
||||
if vor.is_none_or(|v| h["t"].as_f64().is_some_and(|t| t < v as f64)) {
|
||||
n += sp.verbuche(&h) as usize;
|
||||
}
|
||||
}
|
||||
}
|
||||
n
|
||||
@@ -1057,7 +1058,7 @@ pub(crate) fn schaetze_in(l: &mut Live, key: Option<u64>, c: u16) -> Schaetzung
|
||||
}
|
||||
|
||||
/// Pool-Haeufigkeiten am Knoten c, bei Luecke von der groeberen Stufe (wie die Schaetzung); ohne Pool gleichverteilt.
|
||||
fn pool_in(l: &Live, c: u16) -> [f64; A] {
|
||||
pub(crate) fn pool_in(l: &Live, c: u16) -> [f64; A] {
|
||||
(0..3).find_map(|lvl| l.m.pool_von(lvl, hoch(c, lvl as u8))).unwrap_or_else(gleich)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user