Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b332ddf
Added forgotten altai stdp functionality: #145
DavidIkov Feb 3, 2026
7ff5c7d
Started refactoring mnist example, added arguments parsing: #145
DavidIkov Feb 3, 2026
a8c18c1
Added core functionality for examples, now they can run and produce r…
DavidIkov Feb 4, 2026
55f7ee8
Added abillity to save detailed logs: #145
DavidIkov Feb 4, 2026
2952c93
Added model saving: #145
DavidIkov Feb 4, 2026
bb1fa0e
Moved inference results evaluation to separate function: #145
DavidIkov Feb 4, 2026
21779d6
Added trained network finalization: #145
DavidIkov Feb 4, 2026
f9088e1
Changed include type in models to fix pre-commit: #145
DavidIkov Feb 4, 2026
4dd1777
Separated model.cpp into multiple files: #145
DavidIkov Feb 4, 2026
756a1e5
Simplified network construction in examples: #145
DavidIkov Feb 5, 2026
4ec8373
Changed neurons naming to match naming convention: #145
DavidIkov Feb 5, 2026
78a7df9
Added some hyperparameters: #145
DavidIkov Feb 5, 2026
9280c40
Added custom spikes generators for each model type: #145
DavidIkov Feb 5, 2026
8be21ea
Changed switch case to template specializations: #145
DavidIkov Feb 5, 2026
378cee1
Added back debug trace logging: #145
DavidIkov Feb 5, 2026
1922c3b
Changed original authors: #145
DavidIkov Feb 5, 2026
1a0cc4f
Added readme back: #145
DavidIkov Feb 5, 2026
5765281
Removed some double empty lines in network construction: #145
DavidIkov Feb 5, 2026
2f95001
Unified several .h files into one, to make example more compact: #145
DavidIkov Feb 6, 2026
6ae6838
Removed shared folder: #145
DavidIkov Feb 6, 2026
3f3a928
Removed forgotten logging in qunatization of weights in mnist altai: …
DavidIkov Feb 6, 2026
7a89c0a
Changed some comments: #145
DavidIkov Feb 6, 2026
9785e33
Made some changes due to PR: #145
DavidIkov Feb 6, 2026
055bd25
Updated licence years: #145
DavidIkov Feb 6, 2026
54d24dc
Removed some spike generators: #145
DavidIkov Feb 6, 2026
00cf85c
Moved PopulationInfo and PopulationRole into global namespace: #145
DavidIkov Feb 6, 2026
5f02eb2
Moved save network source to header: #145
DavidIkov Feb 6, 2026
5256d78
Added const to UID: #145
DavidIkov Feb 6, 2026
c1cd738
Separated network construction into multiple functions: #145
DavidIkov Feb 6, 2026
205b3b2
Added comments to some of settings parameters: #145
DavidIkov Feb 6, 2026
a23bb8c
Removed includes at end of network_functions.h: #145
DavidIkov Feb 6, 2026
7d2a74b
Added comments for all functions, and some parts of code: #145
DavidIkov Feb 6, 2026
713c7dd
Added some more comments: #145
DavidIkov Feb 6, 2026
a7a6937
Fixed clang build: #145
DavidIkov Feb 9, 2026
899991e
Added mnist-learn to autodoc, and added proper comments: #145
DavidIkov Feb 9, 2026
84988f5
Changed types of values in blifat/settings.h: #145
DavidIkov Feb 9, 2026
772df5d
Fixed grammar in comments: #145
DavidIkov Feb 10, 2026
1e98a1b
Renamed settings.h files: #145
DavidIkov Feb 10, 2026
37ff4ae
Made changes according to PR comments: #145
DavidIkov Feb 10, 2026
7bd838f
Changed include type: #145
DavidIkov Feb 10, 2026
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
24 changes: 18 additions & 6 deletions examples/mnist-learn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ limitations under the License.
cmake_minimum_required(VERSION 3.22)
project(mnist_learn_example)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)

find_package(Boost COMPONENTS program_options REQUIRED )

# Need to check if the example build is inside the Kaspersky Neuromorphic Platform tree.
# Need to check if the example build inside KNP tree.
if (NOT TARGET KNP::BaseFramework::Core)
find_package(knp-base-framework REQUIRED)
endif()

add_executable(mnist_learn_example main.cpp construct_network.cpp train.cpp inference.cpp time_string.cpp)
target_link_libraries(mnist_learn_example PRIVATE KNP::BaseFramework::Core ${Boost_LIBRARIES})
find_package(Boost ${KNP_BOOST_MIN_VERSION} COMPONENTS program_options REQUIRED)

add_executable(${PROJECT_NAME}
main.cpp
model_desc.cpp
parse_arguments.cpp
dataset.cpp
evaluate_results.cpp
models/blifat/construct_network.cpp
models/blifat/finalize_network.cpp
models/blifat/spike_generators.cpp
models/altai/construct_network.cpp
models/altai/finalize_network.cpp
models/altai/spike_generators.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR})
Comment thread
artiomn marked this conversation as resolved.
target_link_libraries(${PROJECT_NAME} PRIVATE KNP::BaseFramework::Core Boost::program_options)
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @file construct_network.h
* @brief Functions for network construction.
* @kaspersky_support A. Vartenkov
* @date 03.12.2024
* @file annotated_network.h
* @brief Network with annotations.
* @kaspersky_support D. Postnikov
* @date 03.02.2026
* @license Apache 2.0
* @copyright © 2024-2025 AO Kaspersky Lab
* @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.
Expand All @@ -23,39 +23,55 @@

#include <knp/framework/network.h>

#include <filesystem>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>


/// A network with annotations.
struct AnnotatedNetwork
{
/// Network.
knp::framework::Network network_;

/// Annotation struct.
struct Annotation
{
/// Output uids.
// cppcheck-suppress unusedStructMember
std::vector<knp::core::UID> output_uids_;

/// Projections from rasterized channeled population.
// cppcheck-suppress unusedStructMember
std::vector<knp::core::UID> projections_from_raster_;

/// Projection from classes channeled populations. Aka label populations.
// cppcheck-suppress unusedStructMember
std::vector<knp::core::UID> projections_from_classes_;

/// Populations that should be kept in inference.
// cppcheck-suppress unusedStructMember
std::set<knp::core::UID> inference_population_uids_;

/// Projections that should be kept in inference.
// cppcheck-suppress unusedStructMember
std::set<knp::core::UID> inference_internal_projection_;

// For each compound network: a vector of senders and a vector of receivers.
/// For each compound network: a vector of senders and a vector of receivers.
// cppcheck-suppress unusedStructMember
std::vector<std::pair<std::vector<knp::core::UID>, std::vector<knp::core::UID>>> wta_data_;

/// WTA borders, for example 2,4,6.
// cppcheck-suppress unusedStructMember
std::vector<size_t> wta_borders_;

/// Map of population names.
// cppcheck-suppress unusedStructMember
std::map<knp::core::UID, std::string> population_names_;
}
/// Annotation to network.
// cppcheck-suppress unusedStructMember
data_;
};


AnnotatedNetwork create_example_network(int num_compound_networks);
212 changes: 0 additions & 212 deletions examples/mnist-learn/construct_network.cpp

This file was deleted.

50 changes: 50 additions & 0 deletions examples/mnist-learn/dataset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @file dataset.cpp
* @brief Process dataset.
* @kaspersky_support D. Postnikov
* @date 03.02.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.
*/

#include "dataset.h"

#include <fstream>

#include "global_config.h"


Dataset process_dataset(ModelDescription const& model_desc)
{
// Create streams for images and labels.
std::ifstream images_stream(model_desc.images_file_path_, std::ios::binary);
std::ifstream labels_stream(model_desc.labels_file_path_, std::ios::in);

Dataset dataset;
// Process them.
dataset.process_labels_and_images(
images_stream, labels_stream, model_desc.train_images_amount_ + model_desc.inference_images_amount_,
classes_amount, input_size, steps_per_image,
dataset.make_incrementing_image_to_spikes_converter(active_steps, state_increment_factor));
// Split dataset according to model description.
dataset.split(model_desc.train_images_amount_, model_desc.inference_images_amount_);

// Print out results.
std::cout << "Processed dataset, training will last " << dataset.get_steps_amount_for_training()
<< " steps, inference " << dataset.get_steps_amount_for_inference() << " steps\n"
<< std::endl;

Comment thread
artiomn marked this conversation as resolved.
return dataset;
}
Loading
Loading