4b64409036
Cycle B of milestone "The World — parameter-space & sweep". A blueprint is now value-empty: a leaf holds a param-generic recipe, not a built node, and a positional Scalar vector is bound slot-by-slot at bootstrap — so one blueprint bootstraps into many distinct instances under different vectors, with no cdylib rebuild (C12/C19). This is the binding primitive a sweep (#32) drives. Ratified design (brainstorm): value-empty reconstruct-through-new() over mutate-in-place and over a default-bearing variant. The value lives only in the injected vector (no baked default), keeping the blueprint a pure param-generic recipe (C19); every injected value flows through the node's own constructor (the single sizing/validation gate). - aura-core: LeafFactory { name, params, build } — the recipe (params -> sized node through `new`); Scalar::as_i64/as_f64 value accessors. Node trait unchanged. - aura-std: each of the 7 nodes exposes factory() (SMA length:I64, Exposure scale:F64, LinComb arity x weights[i]:F64; Sub/Add/SimBroker/Recorder paramless, capturing their non-param construction args — pip_size, the Recorder channel). - aura-engine: BlueprintNode::Leaf(LeafFactory), From<LeafFactory>; param_space() reads factory.params() pre-build; compile_with_params/bootstrap_with_params build each leaf from its kind-checked slice while lowering (build-then-wire), arity checked up front via param_space().len(); CompileError::{ParamKindMismatch, ParamArity}. compile/inline/edge-rewrite are structurally unchanged, so the compilat stays bit-identical for a given point (the bit-identity and both param_space mirror tests stay green). The vestigial pre-build Composite::schema / BlueprintNode::schema (no live caller — interface resolution is structural on the built flat nodes) are removed. - aura-cli: the blueprint view labels leaves by bare type via LeafFactory::label() (`[SMA]`) — the ascii-dag renderer cannot render wide cluster-sibling labels (see spec); the compiled view still labels valued (`SMA(2)`). The sample supplies its point as a vector; the mis-wiring swap moved to the compiled view. The #34 dual-traversal drift hazard is subsumed: compile_with_params consumes the vector in the same recipe walk param_space() reports, so the two share one traversal. Verified: cargo build/test --workspace green (127 tests, incl. bit-identity, both mirror tests, and 4 new injection tests — different-vector-different-run, kind mismatch, arity, determinism); clippy --workspace --all-targets -D warnings clean; `aura graph` blueprint view renders cleanly. Scope: one vector -> one instance. Deferred: sweep enumeration (#32), domain validation (#32/C20), single-run authoring convenience (#35). closes #31
99 lines
3.4 KiB
Rust
99 lines
3.4 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, InputSpec, LeafFactory, Node, NodeSchema, ParamSpec, 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 leaf: 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 factory() -> LeafFactory {
|
|
LeafFactory::new(
|
|
"Exposure",
|
|
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 schema(&self) -> NodeSchema {
|
|
NodeSchema {
|
|
inputs: vec![InputSpec { kind: ScalarKind::F64, lookback: 1, firing: Firing::Any }],
|
|
output: vec![FieldSpec { name: "exposure", kind: ScalarKind::F64 }],
|
|
params: vec![ParamSpec { name: "scale".into(), kind: ScalarKind::F64 }],
|
|
}
|
|
}
|
|
|
|
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 factory_params_match_built_node_schema() {
|
|
let f = Exposure::factory();
|
|
let built = f.build(&[Scalar::F64(0.5)]);
|
|
assert_eq!(f.params(), built.schema().params.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);
|
|
}
|
|
}
|