import {NeuronModel} from './brain-activity-models.js?v=brain-discovery-45'; /** The names connect a six-unit teaching model with anatomical landmarks. * They are not regional population models or physiological fitted parameters. */ export const circuitStages=[ {id:'input',region:'chiasm',name:'Visual input',landmark:'Optic chiasm · input landmark',role:'Light is converted into signals in the retina. Retinal ganglion-cell axons carry signals toward the brain, with some crossing at the optic chiasm.',model:'This driven input unit stands for an incoming signal. The highlighted chiasm is a pathway landmark; it is not a model of retinal photoreceptors.'}, {id:'relay',region:'thalamus',name:'Visual relay',landmark:'Thalamus · visual relay',role:'The lateral geniculate nucleus is a visual relay within the thalamus, linking retinal input with primary visual cortex.',model:'One relay unit receives delayed pulses. The highlighted shape represents the broader thalamus, not a precisely localized LGN.'}, {id:'visual',region:'occipital',name:'Visual processing',landmark:'Occipital lobe · visual cortex',role:'Visual cortical areas process visual information. The occipital lobe provides a useful landmark for locating early visual cortex.',model:'One threshold unit illustrates how incoming events can influence later activity. It does not recognize an image or reproduce visual cortical organization.'}, {id:'context',region:'association',name:'Context',landmark:'Association cortex · teaching landmark',role:'Distributed association systems help combine information with context. These systems interact with sensory and action-related networks.',model:'This stage is a placeholder for combining information. It contains no semantic knowledge, memory, or attention mechanism.'}, {id:'plan',region:'frontal',name:'Planning',landmark:'Frontal cortex · teaching landmark',role:'Frontal systems contribute to goals, planning, and the control of behavior in interaction with other brain systems.',model:'The planning label connects the diagram with that broader idea. This unit only integrates pulses; it does not form a goal or choose a plan.'}, {id:'output',region:'motor',name:'Movement output',landmark:'Motor cortex · teaching landmark',role:'Motor cortex contributes to voluntary movement through wider circuits involving other cortical, subcortical, brainstem, and spinal systems.',model:'The final spike count is an output of the toy chain, not a muscle command or a prediction of a person’s movement.'} ]; export class BrainCircuitModel { constructor(){this.enabled=circuitStages.map(()=>true);this.reset();} reset(){this.t=0;this.units=circuitStages.map(()=>new NeuronModel());this.pending=[];this.events=[];} fire(index,time,strength,delay){this.events.push({unit:index,t:time});if(index=this.units.length)throw Error('Choose a model stage.');this.enabled[index]=Boolean(enabled);} step(duration,{drive=22,strength=18,delay=6,inhibition=0,inhibitUnit=2}={}){ if(!Number.isFinite(duration)||duration<0||duration>5000||![drive,strength,delay,inhibition].every(Number.isFinite)||delay<.5||strength<0||drive<0||inhibition<0||!Number.isInteger(inhibitUnit)||inhibitUnit<0||inhibitUnit>=this.units.length)throw Error('Invalid circuit settings.'); const end=this.t+duration; while(this.tevent.t<=this.t+1e-8);this.pending=this.pending.filter(event=>event.t>this.t+1e-8); for(const event of arriving){if(!this.enabled[event.target])continue;const unit=this.units[event.target],before=unit.count;unit.pulse(event.amount);if(unit.count>before)this.fire(event.target,this.t,strength,delay);} const dt=Math.min(.5,end-this.t); this.units.forEach((unit,index)=>{if(!this.enabled[index]){unit.v=-65;unit.refractory=0;}const before=unit.count;unit.step(dt,{excitation:this.enabled[index]&&index===0?drive:0,inhibition:this.enabled[index]&&index===inhibitUnit?inhibition:0});if(unit.count>before)this.fire(index,this.t+dt,strength,delay);}); this.t+=dt; } this.events=this.events.filter(event=>event.t>=this.t-1000); return this; } }