pub struct SynapseMatrix {
pub n_pre: usize,
pub n_post: usize,
pub config: STDPConfig,
/* private fields */
}Expand description
Matrix of synaptic connections
Fields§
§n_pre: usizeNumber of pre-synaptic neurons
n_post: usizeNumber of post-synaptic neurons
config: STDPConfigSTDP configuration
Implementations§
Source§impl SynapseMatrix
impl SynapseMatrix
Sourcepub fn with_config(n_pre: usize, n_post: usize, config: STDPConfig) -> Self
pub fn with_config(n_pre: usize, n_post: usize, config: STDPConfig) -> Self
Create with custom STDP config
Sourcepub fn add_synapse(&mut self, pre: usize, post: usize, weight: f64)
pub fn add_synapse(&mut self, pre: usize, post: usize, weight: f64)
Add a synapse
Sourcepub fn get_synapse(&self, pre: usize, post: usize) -> Option<&Synapse>
pub fn get_synapse(&self, pre: usize, post: usize) -> Option<&Synapse>
Get synapse if it exists
Sourcepub fn get_synapse_mut(
&mut self,
pre: usize,
post: usize,
) -> Option<&mut Synapse>
pub fn get_synapse_mut( &mut self, pre: usize, post: usize, ) -> Option<&mut Synapse>
Get mutable synapse if it exists
Sourcepub fn weight(&self, pre: usize, post: usize) -> f64
pub fn weight(&self, pre: usize, post: usize) -> f64
Get weight of a synapse (0 if doesn’t exist)
Sourcepub fn compute_weighted_sums(&self, pre_activations: &[f64]) -> Vec<f64>
pub fn compute_weighted_sums(&self, pre_activations: &[f64]) -> Vec<f64>
Compute weighted sum for all post-synaptic neurons given pre-synaptic activations
This is optimized to iterate only over existing synapses, avoiding O(n²) lookups. pre_activations[i] is the activation of pre-synaptic neuron i. Returns vector of weighted sums for each post-synaptic neuron.
Sourcepub fn weighted_sum_for_post(&self, post: usize, pre_activations: &[f64]) -> f64
pub fn weighted_sum_for_post(&self, post: usize, pre_activations: &[f64]) -> f64
Compute weighted sum for a single post-synaptic neuron
Sourcepub fn set_weight(&mut self, pre: usize, post: usize, weight: f64)
pub fn set_weight(&mut self, pre: usize, post: usize, weight: f64)
Set weight of a synapse (creates if doesn’t exist)
Sourcepub fn on_pre_spike(&mut self, pre: usize, time: SimTime)
pub fn on_pre_spike(&mut self, pre: usize, time: SimTime)
Record a pre-synaptic spike and perform STDP updates
Sourcepub fn on_post_spike(&mut self, post: usize, time: SimTime)
pub fn on_post_spike(&mut self, post: usize, time: SimTime)
Record a post-synaptic spike and perform STDP updates
Sourcepub fn process_spikes(&mut self, spikes: &[Spike])
pub fn process_spikes(&mut self, spikes: &[Spike])
Process multiple spikes with STDP
Sourcepub fn decay_eligibility(&mut self, dt: f64)
pub fn decay_eligibility(&mut self, dt: f64)
Decay all eligibility traces
Sourcepub fn apply_reward(&mut self, reward: f64)
pub fn apply_reward(&mut self, reward: f64)
Apply reward-modulated learning to all synapses
Sourcepub fn iter(&self) -> impl Iterator<Item = (&(usize, usize), &Synapse)>
pub fn iter(&self) -> impl Iterator<Item = (&(usize, usize), &Synapse)>
Get all synapses as an iterator
Sourcepub fn num_synapses(&self) -> usize
pub fn num_synapses(&self) -> usize
Get number of synapses
Sourcepub fn input_to(&self, post: usize, pre_activities: &[f64]) -> f64
pub fn input_to(&self, post: usize, pre_activities: &[f64]) -> f64
Compute total synaptic input to a post-synaptic neuron
Sourcepub fn from_dense(matrix: &[Vec<f64>]) -> Self
pub fn from_dense(matrix: &[Vec<f64>]) -> Self
Initialize from dense matrix
Sourcepub fn sync_to_graph<F>(&self, graph: &mut DynamicGraph, neuron_to_vertex: F)
pub fn sync_to_graph<F>(&self, graph: &mut DynamicGraph, neuron_to_vertex: F)
Synchronize weights with a DynamicGraph Maps neurons to vertices via a mapping function
Sourcepub fn sync_from_graph<F>(&mut self, graph: &DynamicGraph, vertex_to_neuron: F)
pub fn sync_from_graph<F>(&mut self, graph: &DynamicGraph, vertex_to_neuron: F)
Load weights from a DynamicGraph
Trait Implementations§
Source§impl Clone for SynapseMatrix
impl Clone for SynapseMatrix
Source§fn clone(&self) -> SynapseMatrix
fn clone(&self) -> SynapseMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SynapseMatrix
impl RefUnwindSafe for SynapseMatrix
impl Send for SynapseMatrix
impl Sync for SynapseMatrix
impl Unpin for SynapseMatrix
impl UnwindSafe for SynapseMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more