-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneuralNetwork.cpp
More file actions
115 lines (80 loc) · 3.44 KB
/
Copy pathneuralNetwork.cpp
File metadata and controls
115 lines (80 loc) · 3.44 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Nueral Network Implementation
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <pthread.h>
#include <unistd.h>
#include "configReader.h"
using namespace std;
struct ThreadData {
vector<double> inputs;
vector<double> weights;
double output;
};
// class NeuralNetwork {
// public:
// vector<vector<double>> inputLayerWeights_;
// vector<vector<double>> hiddenLayerWeights_;
// vector<double> outputLayerWeights_;
// NeuralNetwork(const vector<vector<double>>& inputLayerWeights,
// const vector<vector<double>>& hiddenLayerWeights,
// const vector<vector<double>>& outputLayerWeights)
// : inputLayerWeights_(inputLayerWeights),
// hiddenLayerWeights_(hiddenLayerWeights),
// outputLayerWeights_(outputLayerWeights[0]) {}
// double feedForward(const vector<double>& inputs)
// {
// vector<vector<double>> prevLayerOutputs;
// vector<vector<double>> layerOutputs;
// // Feed-forward through the input layer
// prevLayerOutputs.push_back(inputs);
// layerOutputs = feedForwardLayer(prevLayerOutputs, inputLayerWeights_[0]);
// // Feed-forward through the hidden layers
// for (const auto& layerWeights : hiddenLayerWeights_) {
// prevLayerOutputs = layerOutputs;
// layerOutputs = feedForwardLayer(prevLayerOutputs, layerWeights);
// }
// // Feed-forward through the output layer
// prevLayerOutputs = layerOutputs;
// layerOutputs = feedForwardLayer(prevLayerOutputs, outputLayerWeights_);
// return layerOutputs[0][0]; // Assuming there is only one output neuron in the output layer
// }
// vector<vector<double>> feedForwardLayer(const vector<vector<double>>& inputs, const vector<double>& weights)
// {
// vector<vector<double>> outputs;
// vector<pthread_t> threads(weights.size());
// vector<ThreadData> threadData(weights.size());
// for (size_t i = 0; i < weights.size(); ++i) {
// threadData[i].inputs = inputs[0]; // Assuming all neurons in a layer have the same inputs
// threadData[i].weights = weights;
// int result = pthread_create(&threads[i], NULL, neuronThread, &threadData[i]);
// if (result != 0) {
// cerr << "Error creating thread. Exiting...\n";
// exit(1);
// }
// }
// for (size_t i = 0; i < threads.size(); ++i) {
// pthread_join(threads[i], NULL);
// outputs.push_back({threadData[i].output});
// }
// return outputs;
// }
// static void * neuronThread(void* threadData)
// {
// ThreadData* data = (ThreadData*)threadData;
// double sum = 0.0;
// for (size_t i = 0; i < data->inputs.size(); ++i)
// sum += data->inputs[i] * data->weights[i];
// data->output = 1.0 / (1.0 + exp(-sum));
// return NULL;
// }
// };
int main()
{
NeuralNetworkConfig config("config.txt");
// NeuralNetwork nn(config.inputLayerWeights, config.hiddenLayerWeights, config.outputLayerWeights);
config.print();
return 0;
}