@@ -6,20 +6,34 @@ struct Overlay {
66 seen_sources : u64 ,
77}
88impl Overlay {
9- fn apply ( & mut self , source_id : u8 , pre : f64 , post : f64 , eta : f64 ) -> Result < bool , & ' static str > {
10- if source_id >= 64 || !pre. is_finite ( ) || !post. is_finite ( )
11- || !eta. is_finite ( ) || !( 0.0 ..=1.0 ) . contains ( & eta) {
9+ fn apply (
10+ & mut self ,
11+ source_id : u8 ,
12+ pre : f64 ,
13+ post : f64 ,
14+ eta : f64 ,
15+ ) -> Result < bool , & ' static str > {
16+ if source_id >= 64
17+ || !pre. is_finite ( )
18+ || !post. is_finite ( )
19+ || !eta. is_finite ( )
20+ || !( 0.0 ..=1.0 ) . contains ( & eta)
21+ {
1222 return Err ( "invalid update contract" ) ;
1323 }
1424 let source = 1_u64 << source_id;
15- if self . seen_sources & source != 0 { return Ok ( false ) ; }
25+ if self . seen_sources & source != 0 {
26+ return Ok ( false ) ;
27+ }
1628 // Hypothesis under test, NOT NARS revision or a proven Bayesian update.
1729 let damping = 1.0 - self . latent . abs ( ) . tanh ( ) ;
1830 self . latent = ( self . latent + eta * pre * post * damping) . clamp ( -8.0 , 8.0 ) ;
1931 self . seen_sources |= source;
2032 Ok ( true )
2133 }
22- fn bounded_readout ( & self ) -> f64 { self . latent . tanh ( ) }
34+ fn bounded_readout ( & self ) -> f64 {
35+ self . latent . tanh ( )
36+ }
2337}
2438#[ test]
2539fn repeated_eligible_updates_remain_bounded_and_do_not_move_reference ( ) {
@@ -41,5 +55,8 @@ fn a_duplicate_root_does_not_reinforce_the_synapse_again() {
4155 assert ! ( !synapse. apply( 4 , 0.8 , 0.9 , 0.1 ) . unwrap( ) ) ;
4256 assert_eq ! ( synapse. latent, first) ;
4357 assert ! ( synapse. apply( 5 , -0.8 , 0.9 , 0.1 ) . unwrap( ) ) ;
44- assert ! ( synapse. latent < first, "anticorrelated activation must decrease the overlay" ) ;
58+ assert ! (
59+ synapse. latent < first,
60+ "anticorrelated activation must decrease the overlay"
61+ ) ;
4562}
0 commit comments