-
Notifications
You must be signed in to change notification settings - Fork 22
Added LIF neuron. #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Added LIF neuron. #189
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e5bf902
Added basic LIF neuron: #188
DavidIkov f357238
Added sonata saving for LIF neuron: #188
DavidIkov ff71f52
Added LIF neuron logic into cpu backend: #188
DavidIkov 03b6659
Added LIF neuron tests: #188
DavidIkov 817c37a
Added comments to LIF neuron traits: #188
DavidIkov 774ce92
Added basic LIF neuron: #188
DavidIkov 15cc616
Added sonata saving for LIF neuron: #188
DavidIkov 11fbb44
Added LIF neuron logic into cpu backend: #188
DavidIkov dd38d2a
Added LIF neuron tests: #188
DavidIkov f870b6b
Added comments to LIF neuron traits: #188
DavidIkov 1c72310
Merge remote-tracking branch 'origin/lif_neuron' into lif_neuron
DavidIkov 4c3d8f8
Fixed comments: #188
DavidIkov 4c5587d
Removed double declaration of calculate_population for lif neuron: #188
DavidIkov 5eacec6
Removed old parameters from lif test: #188
DavidIkov 7fe3f26
Fixes according to PR: #189
DavidIkov c63d97d
Added LIF to multithreaded cpu backend, changed namespace in lif neur…
DavidIkov 416f946
Added potential reset value for lif neuron: #188
DavidIkov d0f0afb
Added tests for save/load different neuron types in sonata, and fixed…
DavidIkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
...ds/cpu/cpu-library/include/knp/backends/cpu-library/impl/populations/lif/lif_dispatcher.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * @file lif_dispatcher.h | ||
| * @brief Specification of population interface for lif neuron population. | ||
| * @kaspersky_support Postnikov D. | ||
| * @date 08.12.2025 | ||
| * @license Apache 2.0 | ||
| * @copyright © 2025 AO Kaspersky Lab | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <knp/core/projection.h> | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "lif_impl.h" | ||
|
|
||
|
|
||
| namespace knp::backends::cpu::populations::impl | ||
| { | ||
|
|
||
| /** | ||
| * @brief Calculate pre impact state of single neuron. | ||
| * @param neuron Neuron. | ||
| */ | ||
| inline void calculate_pre_impact_single_neuron_state_dispatch( | ||
| knp::neuron_traits::neuron_parameters<knp::neuron_traits::LIFNeuron> &neuron) | ||
| { | ||
| lif::calculate_pre_impact_single_neuron_state_impl(neuron); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @brief Impact neuron. | ||
| * @param neuron Neuron. | ||
| * @param impact Impact message. | ||
| * @param is_forcing Is impact forced. | ||
| */ | ||
| inline void impact_neuron_dispatch( | ||
| knp::neuron_traits::neuron_parameters<knp::neuron_traits::LIFNeuron> &neuron, | ||
| const knp::core::messaging::SynapticImpact &impact, bool is_forcing) | ||
| { | ||
| lif::impact_neuron_impl(neuron, impact, is_forcing); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @brief Calculate post impact state of single neuron. | ||
| * @param neuron Neuron. | ||
| * @return Should neuron produce spike or should not. | ||
| */ | ||
| inline bool calculate_post_impact_single_neuron_state_dispatch( | ||
| knp::neuron_traits::neuron_parameters<knp::neuron_traits::LIFNeuron> &neuron) | ||
| { | ||
| return lif::calculate_post_impact_single_neuron_state_impl(neuron); | ||
| } | ||
|
DavidIkov marked this conversation as resolved.
|
||
|
|
||
|
|
||
| /** | ||
| * @brief Train population. | ||
| * @param population Population. | ||
| * @param projections Connected projections. | ||
| * @param message Spiking neurons in population at current step. | ||
| * @param step Step. | ||
| */ | ||
| inline void train_population_dispatch( | ||
| knp::core::Population<knp::neuron_traits::LIFNeuron> &population, | ||
| std::vector<std::reference_wrapper<knp::core::Projection<knp::synapse_traits::DeltaSynapse>>> &projections, | ||
| const knp::core::messaging::SpikeMessage &message, knp::core::Step step) | ||
| { | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @brief Train population. | ||
| * @param population Population. | ||
| * @param projections Connected projections. | ||
| * @param message Spiking neurons in population at current step. | ||
| * @param step Step. | ||
| */ | ||
| inline void train_population_dispatch( | ||
| knp::core::Population<knp::neuron_traits::LIFNeuron> &population, | ||
| std::vector<std::reference_wrapper<knp::core::Projection<knp::synapse_traits::SynapticResourceSTDPDeltaSynapse>>> | ||
| &projections, | ||
| const knp::core::messaging::SpikeMessage &message, knp::core::Step step) | ||
| { | ||
| } | ||
|
|
||
| } //namespace knp::backends::cpu::populations::impl | ||
88 changes: 88 additions & 0 deletions
88
...backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/populations/lif/lif_impl.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * @file lif_impl.h | ||
| * @brief Implementation of lif neuron population. | ||
| * @kaspersky_support Postnikov D. | ||
| * @date 12.05.2026 | ||
| * @license Apache 2.0 | ||
| * @copyright © 2026 AO Kaspersky Lab | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <knp/core/population.h> | ||
|
|
||
| #include <spdlog/spdlog.h> | ||
|
|
||
| #include <limits> | ||
|
|
||
|
|
||
| namespace knp::backends::cpu::populations::impl::lif | ||
| { | ||
|
|
||
| inline void calculate_pre_impact_single_neuron_state_impl( | ||
| knp::neuron_traits::neuron_parameters<knp::neuron_traits::LIFNeuron> &neuron) | ||
| { | ||
| if (0 == neuron.refract_counter_) | ||
| { | ||
| neuron.potential_ *= neuron.leak_coefficient_; | ||
|
artiomn marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| inline void impact_neuron_impl( | ||
| knp::neuron_traits::neuron_parameters<knp::neuron_traits::LIFNeuron> &neuron, | ||
| const knp::core::messaging::SynapticImpact &impact, bool is_forcing) | ||
| { | ||
| switch (impact.synapse_type_) | ||
| { | ||
| case knp::synapse_traits::OutputType::EXCITATORY: | ||
|
artiomn marked this conversation as resolved.
|
||
| if (0 == neuron.refract_counter_) | ||
| { | ||
| neuron.potential_ += impact.impact_value_; | ||
| } | ||
| break; | ||
| case knp::synapse_traits::OutputType::INHIBITORY_CURRENT: | ||
| if (0 == neuron.refract_counter_) | ||
| { | ||
| neuron.potential_ -= impact.impact_value_; | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| SPDLOG_ERROR("Unhandled synapse type."); | ||
| throw std::runtime_error("Unhandled synapse type."); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| inline bool calculate_post_impact_single_neuron_state_impl( | ||
| knp::neuron_traits::neuron_parameters<knp::neuron_traits::LIFNeuron> &neuron) | ||
| { | ||
| if (0 == neuron.refract_counter_) | ||
| { | ||
| if (neuron.potential_ > neuron.activation_threshold_) | ||
| { | ||
| neuron.potential_ = neuron.potential_reset_value_; | ||
| neuron.refract_counter_ = neuron.refract_period_; | ||
| return true; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| --neuron.refract_counter_; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| } //namespace knp::backends::cpu::populations::impl::lif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.