# radio.jl — Honest Bayesian compliance radio (Julia) # © Albert Lane. All Rights Reserved. Proprietary and Confidential. # https://albertlane.net # Same logic as radio_bayesian.py / radio.rs: Bayes to reduce FALSE ALARMS, # never to force 100% compliance. All frames logged. # # Run: julia radio.jl mutable struct BayesianCompliance posterior::Float64 p_evidence_given_compliant::Float64 p_evidence_given_noncompliant::Float64 observations::Int end BayesianCompliance() = BayesianCompliance(0.5, 0.92, 0.18, 0) function observe!(radio::BayesianCompliance, looks_compliant::Bool) lik_c, lik_n = if looks_compliant (radio.p_evidence_given_compliant, radio.p_evidence_given_noncompliant) else (1 - radio.p_evidence_given_compliant, 1 - radio.p_evidence_given_noncompliant) end prior = radio.posterior num = lik_c * prior den = num + lik_n * (1 - prior) radio.posterior = den > 0 ? num / den : prior radio.observations += 1 return radio.posterior end function report(radio::BayesianCompliance) verdict = if radio.posterior > 0.85 "likely_compliant" elseif radio.posterior > 0.4 "uncertain" else "likely_noncompliant" end return (posterior_compliant=round(radio.posterior, digits=4), observations=radio.observations, verdict=verdict, note="estimate_from_observed_frames_not_a_guarantee") end function check_frame(xml::String) if !occursin("", xml) return (false, "missing channel") end if !occursin("", xml) || !occursin("<link>", xml) || !occursin("<description>", xml) return (false, "missing required channel title/link/description") end return (true, "well-formed RSS 2.0 frame") end function main() radio = BayesianCompliance() frames = [ "<?xml version=\"1.0\"?><rss version=\"2.0\"><channel><title>Arss://ghost-rss.py/nodes/Ax", "not xml at all", "Brss://ghost-rss.py/nodes/Bx", ] for f in frames ok, why = check_frame(f) p = observe!(radio, ok) println("looks_compliant=$ok ($why) -> posterior=$(round(p, digits=4))") end println(report(radio)) end main()