code wiki / _hdl_build / nx_source_grade.nx
nx_source_grade.nx source
↩ module page · 214 lines · 8765 B
1// nx_source_grade.nx -- the SOURCE-CRITICISM organ: qualitative + quantitative accuracy grading
2// of the sources an analysis stands on. Operator: "clarity on what we see in real terms,
3// measuring qualitatively and quantitatively the accuracy based on first-party sources, their
4// biases, their actual research method." Built from CORROBORATED tradecraft research
5// (knowledge/library/analyst-tradecraft-best-practices-2026-06-10.txt):
6// - NATO/Admiralty 6x6 (C2): source RELIABILITY A..F and information CREDIBILITY 1..6 are
7// rated INDEPENDENTLY, then composed. F and 6 are honest "cannot judge" states -- they are
8// NEVER actionable and owe a fetch-task (like the Analyst's narrative nodes).
9// - First-party DISTANCE + METHOD rung (C6): primary>secondary>tertiary; measured-record >
10// systematic-aggregation > survey > expert-estimate > marketing-claim.
11// - INDEPENDENCE RULE (C5, the sharpest upgrade): two sources in the SAME incentive class are
12// ECHOES of one interest, not corroboration. A claim is corroborated only across >=2 DISTINCT
13// bias classes; agreement between OPPOSED incentive classes is the strongest signal.
14// - ICD 203 (C1,C3): CONFIDENCE (how sure: 1=LOW 2=MODERATE 3=HIGH, driven by source quality +
15// independence) is a SEPARATE dimension from LIKELIHOOD (7 estimative bands); the two must
16// never be combined in one sentence -- sg_separation_ok encodes the law for report emitters.
17// Quantitative score = permil composition of the four axes; qualitative grade = the (letter,
18// digit) Admiralty pair, kept alongside, never replaced by the number.
19// LAWS: struct-free, integer-only (permil), no &&/||. license_tier: ORIGINAL
20
21import "nx_syscalls.nx"
22
23// ---- Admiralty axes (C2): reliability A..F -> 1..6, credibility 1..6; 6th = cannot-judge ----
24const SG_REL_A: i64 = 1
25const SG_REL_F: i64 = 6 // reliability cannot be judged
26const SG_CRED_CONFIRMED: i64 = 1
27const SG_CRED_UNJUDGED: i64 = 6 // truth cannot be judged
28
29// first-party distance (C6)
30const SG_PRIMARY: i64 = 1 // the entity's own record (filing, posted price, instrument data)
31const SG_SECONDARY: i64 = 2 // reporting on a primary
32const SG_TERTIARY: i64 = 3 // aggregator synthesis of secondaries
33
34// research-method rung (C6), best -> worst
35const SG_M_MEASURED: i64 = 5 // measured/primary record (audited filing, census, posted price)
36const SG_M_SYSTEMATIC:i64 = 4 // systematic aggregation (e.g. 200+ P&Ls)
37const SG_M_SURVEY: i64 = 3 // survey / price-guide aggregation
38const SG_M_EXPERT: i64 = 2 // expert estimate / industry rule-of-thumb
39const SG_M_MARKETING: i64 = 1 // marketing claim / anecdote
40
41// corroboration strength (C5)
42const SG_ECHO: i64 = 0 // <2 distinct bias classes: echoes of one interest
43const SG_CORROB: i64 = 1 // >=2 distinct classes
44const SG_OPPOSED: i64 = 2 // >=2 distinct classes INCLUDING an opposed pair (strongest)
45
46// ICD 203 confidence (C3) -- separate from likelihood, always
47const SG_CONF_LOW: i64 = 1
48const SG_CONF_MED: i64 = 2
49const SG_CONF_HIGH: i64 = 3
50
51// ---- validity (loud-fail boundary: out-of-range grades are defects, not defaults) ----
52func sg_valid(rel: i64, cred: i64, party: i64, method: i64) -> i64 {
53 if rel < 1 { return 0 }
54 if rel > 6 { return 0 }
55 if cred < 1 { return 0 }
56 if cred > 6 { return 0 }
57 if party < 1 { return 0 }
58 if party > 3 { return 0 }
59 if method < 1 { return 0 }
60 if method > 5 { return 0 }
61 return 1
62}
63
64// ---- actionability: A..C reliability AND 1..3 credibility; F/6 NEVER actionable (C2) ----
65func sg_actionable(rel: i64, cred: i64) -> i64 {
66 if rel > 3 { return 0 }
67 if cred > 3 { return 0 }
68 return 1
69}
70
71// a source graded cannot-judge on either axis owes the Researcher a fetch-task (go establish it)
72func sg_fetch_owed(rel: i64, cred: i64) -> i64 {
73 if rel == SG_REL_F { return 1 }
74 if cred == SG_CRED_UNJUDGED { return 1 }
75 return 0
76}
77
78// ---- the quantitative axis weights (the gate-spec contract, mirrored by the gate) ----
79func sg_rel_permil(rel: i64) -> i64 {
80 if rel == 1 { return 1000 }
81 if rel == 2 { return 800 }
82 if rel == 3 { return 600 }
83 if rel == 4 { return 300 }
84 if rel == 5 { return 100 }
85 return 0
86}
87
88func sg_cred_permil(cred: i64) -> i64 {
89 if cred == 1 { return 1000 }
90 if cred == 2 { return 800 }
91 if cred == 3 { return 600 }
92 if cred == 4 { return 300 }
93 if cred == 5 { return 100 }
94 return 0
95}
96
97func sg_party_permil(party: i64) -> i64 {
98 if party == SG_PRIMARY { return 1000 }
99 if party == SG_SECONDARY { return 850 }
100 return 700
101}
102
103func sg_method_permil(method: i64) -> i64 {
104 if method == SG_M_MEASURED { return 1000 }
105 if method == SG_M_SYSTEMATIC { return 850 }
106 if method == SG_M_SURVEY { return 650 }
107 if method == SG_M_EXPERT { return 400 }
108 return 150
109}
110
111// composed permil accuracy score; -1 = invalid grades (loud, never a silent 0).
112// Monotone: degrading any axis never raises the score.
113func sg_score_permil(rel: i64, cred: i64, party: i64, method: i64) -> i64 {
114 if sg_valid(rel, cred, party, method) == 0 { return 0 - 1 }
115 var s: i64 = (sg_rel_permil(rel) * sg_cred_permil(cred)) / 1000
116 s = (s * sg_party_permil(party)) / 1000
117 s = (s * sg_method_permil(method)) / 1000
118 return s
119}
120
121// ---- the INDEPENDENCE RULE (C5) ----
122func sg_independent(class_a: i64, class_b: i64) -> i64 {
123 if class_a == class_b { return 0 }
124 return 1
125}
126
127// count DISTINCT values among vals[0..n) -- distinct bias classes behind one claim.
128func sg_distinct(vals: *i64, n: i64) -> i64 {
129 var c: i64 = 0
130 var i: i64 = 0
131 while i < n {
132 var seen: i64 = 0
133 var j: i64 = 0
134 while j < i {
135 if vals[j] == vals[i] { seen = 1 }
136 j = j + 1
137 }
138 if seen == 0 { c = c + 1 }
139 i = i + 1
140 }
141 return c
142}
143
144// corroboration strength of a claim: distinct-class count + whether an OPPOSED pair backs it.
145// has_opposed is computed by the caller from its declared opposed-class pairs (case data).
146func sg_strength(distinct_classes: i64, has_opposed: i64) -> i64 {
147 if distinct_classes < 2 { return SG_ECHO }
148 if has_opposed == 1 { return SG_OPPOSED }
149 return SG_CORROB
150}
151
152// does the class list contain the declared opposed pair (oa, ob)? (either order)
153func sg_has_opposed(vals: *i64, n: i64, oa: i64, ob: i64) -> i64 {
154 var found_a: i64 = 0
155 var found_b: i64 = 0
156 var i: i64 = 0
157 while i < n {
158 if vals[i] == oa { found_a = 1 }
159 if vals[i] == ob { found_b = 1 }
160 i = i + 1
161 }
162 if found_a == 1 { if found_b == 1 { return 1 } }
163 return 0
164}
165
166// ---- ICD 203 confidence (C3): from the WORST admitted row (a chain is its weakest link) ----
167func sg_confidence(worst_strength: i64, worst_score: i64) -> i64 {
168 if worst_strength < SG_CORROB { return SG_CONF_LOW }
169 if worst_score >= 800 { return SG_CONF_HIGH }
170 if worst_score >= 500 { return SG_CONF_MED }
171 return SG_CONF_LOW
172}
173
174// ---- ICD 203 estimative bands (C3): permil likelihood -> band 1..7 ----
175func sg_wep_band(permil: i64) -> i64 {
176 if permil <= 50 { return 1 } // almost no chance (1-5%)
177 if permil <= 200 { return 2 } // very unlikely (5-20%)
178 if permil <= 450 { return 3 } // unlikely (20-45%)
179 if permil <= 550 { return 4 } // roughly even (45-55%)
180 if permil <= 800 { return 5 } // likely (55-80%)
181 if permil <= 950 { return 6 } // very likely (80-95%)
182 return 7 // almost certain (95-99%)
183}
184
185func sg_wep_name(band: i64) -> *u8 {
186 if band == 1 { return "almost-no-chance" as *u8 }
187 if band == 2 { return "very-unlikely" as *u8 }
188 if band == 3 { return "unlikely" as *u8 }
189 if band == 4 { return "roughly-even-chance" as *u8 }
190 if band == 5 { return "likely" as *u8 }
191 if band == 6 { return "very-likely" as *u8 }
192 return "almost-certain" as *u8
193}
194
195func sg_conf_name(conf: i64) -> *u8 {
196 if conf == SG_CONF_HIGH { return "HIGH" as *u8 }
197 if conf == SG_CONF_MED { return "MODERATE" as *u8 }
198 return "LOW" as *u8
199}
200
201// ---- the SEPARATION LAW (C3): confidence and likelihood never share a sentence ----
202// report emitters pass 1 if they are about to put both in one sentence; 0 = legal layout.
203func sg_separation_ok(same_sentence: i64) -> i64 {
204 if same_sentence == 1 { return 0 }
205 return 1
206}
207
208// ---- REPRODUCIBILITY (the standing exceed): same grades -> same score, every run ----
209func sg_is_reproducible(rel: i64, cred: i64, party: i64, method: i64) -> i64 {
210 let s1: i64 = sg_score_permil(rel, cred, party, method)
211 let s2: i64 = sg_score_permil(rel, cred, party, method)
212 if s1 == s2 { return 1 }
213 return 0
214}