s42chen's picture
Publish 11 evaluated Astra histories with reproducible checkpoint artifacts (part 54)
b75888f verified
Raw History Blame Contribute Delete
932 Bytes
"""Categorical logical probabilities keyed only by 24 hard detection events."""
import numpy as np
from scipy.special import expit
def codes(packed):
assert packed.dtype == np.uint8 and packed.ndim == 2 and packed.shape[1] == 3
return np.sum(packed.astype(np.uint32) * np.array([1, 256, 65536], np.uint32),
axis=1, dtype=np.uint32)
def predict(packed, state, fallback, mode='raw'):
assert mode in ['raw', 'equal']
key = codes(packed)
known = state['codes']
at = np.searchsorted(known, key)
safe = np.minimum(at, len(known)-1)
seen = (at < len(known)) & (known[safe] == key)
p = np.asarray(fallback, dtype=np.float32).copy()
assert p.shape == (len(packed),)
learned = expit(state['prior_logits'][safe[seen]] + state['residual_logits'][safe[seen]]).astype(np.float32)
p[seen] = learned if mode == 'raw' else ((learned + p[seen])/2).astype(np.float32)
return p