e304dbaae1
PortSpec gains a non-load-bearing `name: String`, so an input port is named just as FieldSpec.name (output) and ParamSpec.name (param) already are — input ports were the lone unnamed member of the node signature. Identity stays positional by slot (C23); the name is render/debug only, never read by bootstrap or the run loop. PortSpec drops Copy (String is not Copy), exactly as ParamSpec already does. - Every aura-std node names its input slots: SMA/EMA "series", Sub/Add "lhs"/"rhs", Exposure "signal", SimBroker "exposure"/"price" (the slots become self-documenting), LinComb "term[i]" and Recorder "col[i]" generated in their build loops (mirroring LinComb's existing weights[i] param loop). - derive_signature carries a composite's Role.name into the derived input port (it was dropped before — the output side already carried FieldSpec.name), so the graph model is homogeneously named at both levels. - model_to_json (port_json + the composite-header inputs in scope_json) emits the name as a third tuple element: ["f64","any","exposure"]. The byte golden was re-captured (machine bytes) and its substring twins updated; the model is now fully named across inputs/outputs/params. - All 16 PortSpec construction sites threaded in one compile-gate change; test fixtures carry fixture names. C8 realization note added to the design ledger. Why name-only, no validation: the name is a pure debug symbol. Wire-by-name was rejected (it would be a C23 contract change). Bootstrap slot-wiring validation (which would close #21's same-kind swap footgun) is deferred to its own cycle — a name alone does not catch the swap; it makes the slots self-documenting and gives a future validation something to check against. Verified: cargo test --workspace 168 green; clippy --all-targets -D warnings clean; cargo build --workspace clean. Read-only render path (C9), no serde (C14), scalar kinds unchanged (C4). closes #50 refs #21 refs #51
98 lines
3.3 KiB
Rust
98 lines
3.3 KiB
Rust
//! `Exposure` — shapes a raw signal score into a bounded exposure (intent).
|
|
//! The decision/sizing node of C10's chain `signals -> decision/sizing node ->
|
|
//! exposure stream`: one f64 input, one f64 output `clamp(signal / scale, -1, +1)`.
|
|
//! `scale` sets which signal magnitude maps to full exposure (sizing lives here).
|
|
|
|
use aura_core::{
|
|
Ctx, FieldSpec, Firing, Node, NodeSchema, ParamSpec, PortSpec, PrimitiveBuilder, Scalar,
|
|
ScalarKind,
|
|
};
|
|
|
|
/// Bounded exposure from a raw signal score: `clamp(signal / scale, -1.0, +1.0)`.
|
|
/// Emits `None` until its input is present (warm-up filter, C8).
|
|
pub struct Exposure {
|
|
scale: f64,
|
|
out: [Scalar; 1],
|
|
}
|
|
|
|
impl Exposure {
|
|
/// Build an exposure node with saturation magnitude `scale` (must be > 0).
|
|
pub fn new(scale: f64) -> Self {
|
|
assert!(scale > 0.0, "Exposure scale must be > 0");
|
|
Self { scale, out: [Scalar::F64(0.0)] }
|
|
}
|
|
|
|
/// The param-generic recipe for a blueprint primitive: declares `scale` and builds
|
|
/// through `Exposure::new` (the single sizing/validation gate; the slice is
|
|
/// kind-checked before `build` runs, so the typed read is total).
|
|
pub fn builder() -> PrimitiveBuilder {
|
|
PrimitiveBuilder::new(
|
|
"Exposure",
|
|
NodeSchema {
|
|
inputs: vec![PortSpec { kind: ScalarKind::F64, firing: Firing::Any, name: "signal".into() }],
|
|
output: vec![FieldSpec { name: "exposure", kind: ScalarKind::F64 }],
|
|
params: vec![ParamSpec { name: "scale".into(), kind: ScalarKind::F64 }],
|
|
},
|
|
|p| Box::new(Exposure::new(p[0].as_f64().expect("scale slot is F64"))),
|
|
)
|
|
}
|
|
}
|
|
|
|
impl Node for Exposure {
|
|
fn lookbacks(&self) -> Vec<usize> {
|
|
vec![1]
|
|
}
|
|
|
|
fn eval(&mut self, ctx: Ctx<'_>) -> Option<&[Scalar]> {
|
|
let w = ctx.f64_in(0);
|
|
if w.is_empty() {
|
|
return None; // not yet warmed up (C8 filter)
|
|
}
|
|
self.out[0] = Scalar::F64((w[0] / self.scale).clamp(-1.0, 1.0));
|
|
Some(&self.out)
|
|
}
|
|
|
|
fn label(&self) -> String {
|
|
format!("Exposure({})", self.scale)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use aura_core::{AnyColumn, Timestamp};
|
|
|
|
#[test]
|
|
fn exposure_clamps_to_unit_band() {
|
|
let mut e = Exposure::new(0.5);
|
|
let mut inputs = vec![AnyColumn::with_capacity(ScalarKind::F64, 1)];
|
|
// (raw signal, expected clamped exposure) for scale 0.5
|
|
let cases = [
|
|
(0.1_f64, 0.2_f64), // within band
|
|
(0.5, 1.0), // at the high edge
|
|
(1.0, 1.0), // saturates high
|
|
(-0.1, -0.2), // within band, negative
|
|
(-1.0, -1.0), // saturates low
|
|
];
|
|
for (sig, want) in cases {
|
|
inputs[0].push(Scalar::F64(sig)).unwrap();
|
|
assert_eq!(
|
|
e.eval(Ctx::new(&inputs, Timestamp(0))),
|
|
Some([Scalar::F64(want)].as_slice())
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn exposure_is_none_until_input_present() {
|
|
let mut e = Exposure::new(0.5);
|
|
let inputs = vec![AnyColumn::with_capacity(ScalarKind::F64, 1)];
|
|
assert_eq!(e.eval(Ctx::new(&inputs, Timestamp(0))), None);
|
|
}
|
|
|
|
#[test]
|
|
fn input_slot_is_named_signal() {
|
|
assert_eq!(Exposure::builder().schema().inputs[0].name, "signal");
|
|
}
|
|
}
|