Skip to main content

sc_neurocore_engine/neurons/hardware/
loihi_cuba.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Commercial license available
3// © Concepts 1996–2026 Miroslav Šotek. All rights reserved.
4// © Code 2020–2026 Miroslav Šotek. All rights reserved.
5// ORCID: 0009-0009-3560-0851
6// Contact: www.anulum.li | protoscience@anulum.li
7// SC-NeuroCore — Loihi CUBA Neuron Emulator
8
9/// Loihi CUBA LIF — Intel Loihi 1 fixed-point neuron. Davies et al. 2018.
10#[derive(Clone, Debug)]
11pub struct LoihiCUBANeuron {
12    pub v: i32,
13    pub u: i32,
14    pub tau_v: i32,
15    pub tau_u: i32,
16    pub v_threshold: i32,
17    pub v_reset: i32,
18}
19
20impl LoihiCUBANeuron {
21    pub fn new() -> Self {
22        Self {
23            v: 0,
24            u: 0,
25            tau_v: 10,
26            tau_u: 5,
27            v_threshold: 1000,
28            v_reset: 0,
29        }
30    }
31    pub fn step(&mut self, weighted_input: i32) -> i32 {
32        self.u = self.u - self.u / self.tau_u + weighted_input;
33        self.v = self.v - self.v / self.tau_v + self.u;
34        if self.v >= self.v_threshold {
35            self.v = self.v_reset;
36            1
37        } else {
38            0
39        }
40    }
41    pub fn reset(&mut self) {
42        self.v = 0;
43        self.u = 0;
44    }
45}
46impl Default for LoihiCUBANeuron {
47    fn default() -> Self {
48        Self::new()
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn loihi_cuba_fires() {
58        let mut n = LoihiCUBANeuron::new();
59        let t: i32 = (0..200).map(|_| n.step(100)).sum();
60        assert!(t > 0);
61    }
62    #[test]
63    fn loihi_cuba_silent() {
64        let mut n = LoihiCUBANeuron::new();
65        let t: i32 = (0..200).map(|_| n.step(0)).sum();
66        assert_eq!(t, 0);
67    }
68    #[test]
69    fn loihi_cuba_reset() {
70        let mut n = LoihiCUBANeuron::new();
71        for _ in 0..50 {
72            n.step(100);
73        }
74        n.reset();
75        assert_eq!(n.v, 0);
76        assert_eq!(n.u, 0);
77    }
78    #[test]
79    fn loihi_cuba_bounded() {
80        let mut n = LoihiCUBANeuron::new();
81        for _ in 0..1000 {
82            n.step(10000);
83        }
84    }
85}