00001 #include <iostream> 00002 #include "SigmoidalNeuron.h" 00003 #include "InputNeuron.h" 00004 #include "UniformRNG.h" 00005 #include <vector> 00006 #include <cmath> 00007 using namespace std; 00008 00009 int main(void) 00010 { 00011 const int iterations = 100; 00012 SigmoidalNeuron TestNeuron; 00013 double testinput1, weight1; 00014 double testinput2, weight2; 00015 double bias, result; 00016 00017 GeneralLinearCombiner::tinvector testiv; 00018 testiv.push_back(boost::shared_ptr<GeneralNeuron>(new InputNeuron(testinput1))); 00019 testiv.push_back(boost::shared_ptr<GeneralNeuron>(new InputNeuron(testinput2))); 00020 TestNeuron.SetType(SigmoidalNeuron::identity); 00021 TestNeuron.SetInput(testiv); 00022 00023 UniformRNG Random; 00024 for (int i = 0; i < iterations; ++i) 00025 { 00026 weight1 = Random.GetNumber(); 00027 weight2 = Random.GetNumber(); 00028 TestNeuron.SetWeights().at(0) = weight1; 00029 TestNeuron.SetWeights().at(1) = weight2; 00030 bias = Random.GetNumber(); 00031 TestNeuron.SetBias(bias); 00032 testinput1 = Random.GetNumber(); 00033 testinput2 = Random.GetNumber(); 00034 result = bias + weight1 * testinput1 + weight2 * testinput2; 00035 cout << "Output: " << TestNeuron.GetOutput() << " Correct: " << result << endl; 00036 } 00037 00038 TestNeuron.SetType(SigmoidalNeuron::bipolar); 00039 TestNeuron.SetInput(testiv); 00040 for (int i = 0; i < iterations; ++i) 00041 { 00042 weight1 = Random.GetNumber(); 00043 weight2 = Random.GetNumber(); 00044 TestNeuron.SetWeights().at(0) = weight1; 00045 TestNeuron.SetWeights().at(1) = weight2; 00046 bias = Random.GetNumber(); 00047 TestNeuron.SetBias(bias); 00048 testinput1 = Random.GetNumber(); 00049 testinput2 = Random.GetNumber(); 00050 result = tanh(0.5*(bias + weight1 * testinput1 + weight2 * testinput2)); 00051 cout << "Output: " << TestNeuron.GetOutput() << " Correct: " << result << endl; 00052 } 00053 00054 }
1.5.1