-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some idealized models for convergence tests
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,66 @@ | ||
#include "../src/ANN.h" | ||
#include <iostream> | ||
#include <vector> | ||
#include <random> | ||
#include <chrono> | ||
|
||
int main() { | ||
Network network; | ||
network.loadFromFile("mbase.ffann"); // Ensure this path is correct | ||
|
||
std::cout << "Network Configuration:\n" << network.toString() << std::endl; | ||
|
||
// Constants for testing | ||
const size_t numInputs = 10000000; | ||
const size_t inputSize = network.layers.front().weights[0].size(); | ||
|
||
// Initialize random number generation | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_real_distribution<float> dis(0.0, 1.0); | ||
|
||
// Prepare inputs | ||
std::vector<std::vector<float>> inputs(numInputs, std::vector<float>(inputSize)); | ||
for (auto& inp : inputs) { | ||
std::generate(inp.begin(), inp.end(), [&]() { return dis(gen); }); | ||
} | ||
|
||
// Prepare to store results | ||
std::vector<float> results; | ||
results.reserve(numInputs); | ||
|
||
// Timing the feedforward process | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
|
||
// Process each input through the network | ||
for (const auto& input : inputs) { | ||
results.push_back(network.processInput(input)[0]); | ||
} | ||
|
||
auto end = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> elapsed = end - start; | ||
|
||
// Output timing results | ||
std::cout << "Time taken for processing " << numInputs << " inputs: " << elapsed.count() << " seconds\n"; | ||
|
||
// Specific inputs for verification | ||
std::vector<std::vector<float>> testInputs = { | ||
{1, 1, 1, 0, 0}, | ||
{1, 0, 0, 0, 0}, | ||
{0, 1, 0, 0, 0}, | ||
{0, 0, 1, 0, 0}, | ||
{0, 0, 0, 1, 0}, | ||
{0, 0, 0, 0, 1}, | ||
{1, 1, 0, 1, 1} | ||
}; | ||
|
||
// Process each test input through the network and print the results | ||
for (const auto& input : testInputs) { | ||
auto outputs = network.processInput(input); | ||
std::cout << "["; | ||
for (auto i : input) std::cout << i << " "; | ||
std::cout << "] result: " << outputs[0] << std::endl; | ||
} | ||
|
||
return 0; | ||
} |