Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment thread
DavidIkov marked this conversation as resolved.
*
* 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);
}
Comment thread
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
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_;
Comment thread
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:
Comment thread
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "altai/altai_dispatcher.h"
#include "blifat/blifat_dispatcher.h"
#include "lif/lif_dispatcher.h"


namespace knp::backends::cpu::populations::impl
Expand Down
Loading
Loading