Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Layer1Neuron.h"
- int main()
- {
- bool answer = false;
- int get[2];
- int count[4] = { 0,0,0,0 };
- int result;
- char input;
- Layer1Neuron L1Neuron[4];
- do {
- std::cout << "Give me your first input:";
- std::cin >> get[0];
- std::cout << std::endl;
- std::cout << "Give me your second input:";
- std::cin >> get[1];
- std::cout << std::endl;
- if (get[0] == 0 && get[1] == 0)
- {
- std::cout << "The target result is:";
- std::cin >> result;
- std::cout << std::endl;
- std::cout << "The machine generated answer is:"<<L1Neuron[0].MachineResult(result)<<std::endl;
- if (count[0] < 5)
- {
- L1Neuron[0].TrainFunction(result);
- count[0]++;
- }
- }
- if (get[0] == 0 && get[1] == 1)
- {
- std::cout << "The target result is:";
- std::cin >> result;
- std::cout << std::endl;
- std::cout << "The machine generated answer is:" << L1Neuron[1].MachineResult(result) << std::endl;
- if (count[1] < 5)
- {
- L1Neuron[1].TrainFunction(result);
- count[1]++;
- }
- }
- if (get[0] == 1 && get[1] == 0)
- {
- std::cout << "The target result is:";
- std::cin >> result;
- std::cout << std::endl;
- std::cout << "The machine generated answer is:" << L1Neuron[2].MachineResult(result) << std::endl;
- if (count[2] < 5)
- {
- L1Neuron[2].TrainFunction(result);
- count[2]++;
- }
- }
- if (get[0] == 1 && get[1] == 1)
- {
- std::cout << "The target result is:";
- std::cin >> result;
- std::cout << std::endl;
- std::cout << "The machine generated answer is:" << L1Neuron[3].MachineResult(result) << std::endl;
- if (count[3] < 5)
- {
- L1Neuron[3].TrainFunction(result);
- count[3]++;
- }
- }
- std::cout << "Do you want to exit the program? Type y for yes or n for no:";
- std::cin >> input;
- std::cout << std::endl;
- if (input == 'y')
- {
- answer = true;
- }
- else if (input == 'n')
- {
- answer = false;
- }
- } while (answer == false);
- }
- #pragma once
- class Layer1Neuron
- {
- public:
- void TrainFunction(int result);
- int MachineResult(int result);
- private:
- double Layer1R[2] = { 0.5,0.5 };
- };
- #include "Layer1Neuron.h"
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- void Layer1Neuron::TrainFunction(int result)
- {
- if (result == 0)
- {
- Layer1R[0] = Layer1R[0] + 0.1;//0.1 is the learning rate.You can change it.
- Layer1R[1] = Layer1R[1] - 0.1;
- }
- else if(result ==1)
- {
- Layer1R[1] = Layer1R[1] + 0.1;
- Layer1R[0] = Layer1R[0] - 0.1;
- }
- }
- int Layer1Neuron::MachineResult(int result)
- {
- double val = (double)rand() / RAND_MAX;
- if (result == 0)
- {
- if (val < Layer1R[1])
- return 1;
- else if (val < Layer1R[result])
- return result;
- }
- else if(result ==1)
- {
- if (val < Layer1R[0])
- return 0;
- else if (val < Layer1R[result])
- return result;
- }
- }
Add Comment
Please, Sign In to add comment