|
| 1 | +#include <cstdlib> |
| 2 | +#include <iostream> |
| 3 | +#include <vector> |
| 4 | + |
| 5 | +struct Connection { |
| 6 | + double weight; |
| 7 | + double deltaWeight; |
| 8 | +}; |
| 9 | +class Neuron; |
| 10 | + |
| 11 | +typedef std::vector<Neuron> Layer; |
| 12 | + |
| 13 | +// ********************** Class Neuron ************************** |
| 14 | + |
| 15 | +class Neuron { |
| 16 | +public: |
| 17 | + Neuron(unsigned numOutputs); |
| 18 | + |
| 19 | +private: |
| 20 | + static double randomWeight() { return rand() / double(RAND_MAX); } |
| 21 | + double m_outputVal; |
| 22 | + std::vector<Connection> m_outputWeights; |
| 23 | +}; |
| 24 | +Neuron::Neuron(unsigned numOutputs) { |
| 25 | + for (unsigned c = 0; c < numOutputs; c++) { |
| 26 | + m_outputWeights.push_back(Connection()); |
| 27 | + m_outputWeights.back().weight = randomWeight(); |
| 28 | + } |
| 29 | +}; |
| 30 | + |
| 31 | +// ********************** Class Net ************************** |
| 32 | +class Net { |
| 33 | +public: |
| 34 | + Net(const std::vector<unsigned> &topology); |
| 35 | + void feedforward(std::vector<double> &inputVals) {}; |
| 36 | + void backProp(const std::vector<double> &targetVals) {}; |
| 37 | + void getResults(const std::vector<double> resultVals) const {}; |
| 38 | + |
| 39 | +private: |
| 40 | + std::vector<Layer> m_layers; |
| 41 | +}; |
| 42 | + |
| 43 | +Net::Net(const std::vector<unsigned> &topology) { |
| 44 | + unsigned numLayers = topology.size(); |
| 45 | + for (unsigned layerNum = 0; layerNum < numLayers; layerNum++) { |
| 46 | + m_layers.push_back(Layer()); |
| 47 | + unsigned numOutputs = |
| 48 | + layerNum == numLayers - 1 ? 0 : topology[layerNum + 1]; |
| 49 | + |
| 50 | + for (unsigned neuronNumber = 0; neuronNumber <= topology[layerNum]; |
| 51 | + neuronNumber++) { |
| 52 | + m_layers.back().push_back(Neuron(numOutputs)); |
| 53 | + std::cout << "Made a new Neuron!" << std::endl; |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | +int main(int argc, char *argv[]) { |
| 58 | + std::vector<unsigned> topology; |
| 59 | + topology.push_back(3); |
| 60 | + topology.push_back(2); |
| 61 | + topology.push_back(1); |
| 62 | + Net myNet(topology); |
| 63 | + |
| 64 | + std::vector<double> inputVals; |
| 65 | + myNet.feedforward(inputVals); |
| 66 | + |
| 67 | + std::vector<double> targetVals; |
| 68 | + myNet.backProp(targetVals); |
| 69 | + |
| 70 | + std::vector<double> resultVals; |
| 71 | + myNet.getResults(resultVals); |
| 72 | + |
| 73 | + return 0; |
| 74 | +} |
0 commit comments