-
Notifications
You must be signed in to change notification settings - Fork 21
Add non-learning AltAI-LIF neuron #65
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
54cce00
Add AltAI LIF mechanics: #0000038
a-vartenkov b80102c
Change headers: #0000038
a-vartenkov 4c2647e
Add tests for AltAI-LIF: #0000038
a-vartenkov 273cea2
Add some comments: #0000038
a-vartenkov e517ffd
Add include: #0000038
a-vartenkov f86f84f
Change types in additive_stdp: #0000038
a-vartenkov a0fa46c
Fix comment: #0000038
a-vartenkov fe8d54b
Update comment in altai_lif_population: #0000038
a-vartenkov 246588f
Remove some commented code: #0000038
a-vartenkov e272dd5
A few modifications to the test: #0000038
a-vartenkov a619cbe
Remove boolean arithmetics: #0000038
a-vartenkov 4061528
Remove empty functions: #0000038
a-vartenkov 1f27193
Add some logging: #0000038
a-vartenkov 08017b3
Rename blifat to blifat-like: #0000038
a-vartenkov 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
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
50 changes: 50 additions & 0 deletions
50
knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/altai_lif_population.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,50 @@ | ||
| /** | ||
| * @file altai_lif_population.h | ||
| * @kaspersky_support Vartenkov A. | ||
| * @date 01.04.2025 | ||
| * @license Apache 2.0 | ||
| * @copyright © 2024 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/backends/cpu-library/impl/altai_lif_population_impl.h> | ||
| #include <knp/backends/cpu-library/impl/lif_population_impl.h> | ||
| #include <knp/core/message_endpoint.h> | ||
| #include <knp/core/messaging/messaging.h> | ||
| #include <knp/core/population.h> | ||
|
|
||
| #include <optional> | ||
|
|
||
|
|
||
| /** | ||
| * @brief Namespace for CPU backends. | ||
| */ | ||
| namespace knp::backends::cpu | ||
| { | ||
|
|
||
| /** | ||
| * @brief Calculate LIF population step. | ||
| * @tparam LifNeuron LIF neuron type. | ||
| * @param population population to be calculated. | ||
| * @param endpoint endpoint for message exchange. | ||
| * @param step_n current step. | ||
| * @return message if a message was sent by function. | ||
| */ | ||
| template <class LifNeuron> | ||
| std::optional<knp::core::messaging::SpikeMessage> calculate_lif_population( | ||
| knp::core::Population<LifNeuron> &population, knp::core::MessageEndpoint &endpoint, size_t step_n) | ||
| { | ||
| return calculate_lif_population_impl(population, endpoint, step_n); | ||
| } | ||
| } // namespace knp::backends::cpu | ||
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
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
113 changes: 113 additions & 0 deletions
113
...ackends/cpu/cpu-library/include/knp/backends/cpu-library/impl/altai_lif_population_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,113 @@ | ||
| /** | ||
| * @file altai_lif_population_impl.h | ||
| * @kaspersky_support Vartenkov A. | ||
| * @date 07.04.2025 | ||
| * @license Apache 2.0 | ||
| * @copyright © 2024 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/messaging/messaging.h> | ||
| #include <knp/core/population.h> | ||
| #include <knp/neuron-traits/altai_lif.h> | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "lif_population_impl.h" | ||
|
|
||
|
|
||
| namespace knp::backends::cpu | ||
| { | ||
|
|
||
| // TODO: Maybe make this a .cpp and change library type from INTERFACE to STATIC later | ||
|
artiomn marked this conversation as resolved.
|
||
| template <> | ||
| void calculate_pre_input_state_lif<knp::neuron_traits::AltAILIF>( | ||
| knp::core::Population<knp::neuron_traits::AltAILIF> &population) | ||
| { | ||
| for (auto &neuron : population) | ||
| { | ||
| neuron.potential_ = std::round(neuron.potential_); | ||
|
|
||
| neuron.potential_ = neuron.do_not_save_ ? static_cast<float>(neuron.potential_reset_value_) : neuron.potential_; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| void leak_potential(knp::core::Population<knp::neuron_traits::AltAILIF> &population) | ||
| { | ||
| for (auto &neuron : population) | ||
| { | ||
| // -1 if leak_rev is true and potential < 0, 1 otherwise. | ||
| const int sign = (neuron.leak_rev_ && neuron.potential_ < 0) ? -1 : 1; | ||
| neuron.potential_ += neuron.potential_leak_ * sign; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| template <> | ||
| void process_inputs_lif<knp::neuron_traits::AltAILIF>( | ||
| knp::core::Population<knp::neuron_traits::AltAILIF> &population, | ||
| const std::vector<knp::core::messaging::SynapticImpactMessage> &messages) | ||
| { | ||
| for (const auto &msg : messages) | ||
| { | ||
| for (const auto &impact : msg.impacts_) | ||
| { | ||
| population[impact.postsynaptic_neuron_index_].potential_ += impact.impact_value_; | ||
| } | ||
| } | ||
| leak_potential(population); | ||
| } | ||
|
|
||
|
|
||
| template <> | ||
| knp::core::messaging::SpikeData calculate_spikes_lif<knp::neuron_traits::AltAILIF>( | ||
| knp::core::Population<knp::neuron_traits::AltAILIF> &population) | ||
| { | ||
| knp::core::messaging::SpikeData spikes; | ||
| for (knp::core::messaging::SpikeIndex i = 0; i < population.size(); ++i) | ||
| { | ||
| bool was_reset = false; | ||
| auto &neuron = population[i]; | ||
| if (neuron.potential_ >= neuron.activation_threshold_) | ||
| { | ||
| spikes.push_back(i); | ||
| if (neuron.is_diff_) neuron.potential_ -= neuron.activation_threshold_; | ||
| if (neuron.is_reset_) | ||
| { | ||
| neuron.potential_ = neuron.potential_reset_value_; | ||
| was_reset = true; | ||
| } | ||
| } | ||
| if (neuron.potential_ <= -static_cast<float>(neuron.negative_activation_threshold_) && !was_reset) | ||
| { | ||
| // Might probably want a negative spike, but we don't have any of the sort in KNP. Not a large problem, | ||
| // just requires some conversion. | ||
| if (neuron.saturate_) | ||
| { | ||
| neuron.potential_ = -static_cast<float>(neuron.negative_activation_threshold_); | ||
| continue; | ||
| } | ||
| if (neuron.is_reset_) | ||
| neuron.potential_ = -neuron.potential_reset_value_; | ||
| else if (neuron.is_diff_) | ||
| neuron.potential_ += neuron.negative_activation_threshold_; | ||
| } | ||
| } | ||
| return spikes; | ||
| } | ||
|
|
||
| } // namespace knp::backends::cpu | ||
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.