File size: 2,497 Bytes
26d5b81 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <iostream>
#include <exception>
#include "../include/neuroflow/model.hpp"
#include "../include/neuroflow/memory.hpp"
#include "../include/neuroflow/networks.hpp"
using namespace neuroflow;
void test_ecn() {
std::cout << "Testing ECN alone..." << std::endl;
ExecutiveControlNetwork ecn(32, 32, 5, 1);
Tensor input({2, 32});
for (size_t i = 0; i < input.numel(); ++i) input.as_fp32()[i] = 0.1f * i;
auto output = ecn.forward(input);
std::cout << "ECN decision shape: [" << output.decision.shape_[0] << ", " << output.decision.shape_[1] << "]" << std::endl;
std::cout << "ECN passed!" << std::endl;
}
void test_dmn() {
std::cout << "Testing DMN alone..." << std::endl;
DefaultModeNetwork dmn(16, 16, 2);
Tensor input({2, 16});
for (size_t i = 0; i < input.numel(); ++i) input.as_fp32()[i] = 0.1f * i;
auto output = dmn.forward(input);
std::cout << "DMN vision shape size: " << output.vision.shape_.size() << std::endl;
for (size_t i = 0; i < output.vision.shape_.size(); ++i) std::cout << " dim " << i << ": " << output.vision.shape_[i] << std::endl;
std::cout << "DMN passed!" << std::endl;
}
void test_sn() {
std::cout << "Testing SN alone..." << std::endl;
SalienceNetwork sn(32, 16);
Tensor input({2, 32});
for (size_t i = 0; i < input.numel(); ++i) input.as_fp32()[i] = 0.1f * i;
auto output = sn.forward(input);
std::cout << "SN saliency shape: [" << output.saliency.shape_[0] << ", " << output.saliency.shape_[1] << "]" << std::endl;
std::cout << "SN gates shape: [" << output.gates.shape_[0] << ", " << output.gates.shape_[1] << "]" << std::endl;
std::cout << "SN passed!" << std::endl;
}
void test_memory() {
std::cout << "Testing Memory alone..." << std::endl;
MemoryConsolidationModule memory(32, 8, 16);
Tensor input({2, 32});
for (size_t i = 0; i < input.numel(); ++i) input.as_fp32()[i] = 0.1f * i;
auto output = memory.forward(input);
std::cout << "Memory retrieved shape: [" << output.retrieved.shape_[0] << ", " << output.retrieved.shape_[1] << "]" << std::endl;
std::cout << "Memory passed!" << std::endl;
}
int main() {
try {
test_ecn();
test_dmn();
test_sn();
test_memory();
std::cout << "\nAll component tests passed!" << std::endl;
} catch (const std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}
|