Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Ann.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- # include <cmath>
- #include <math.h>
- #include <vector>
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- struct Sample
- {
- double input[2];
- double output[2];
- };
- class Data
- {
- public:
- int getNumberOfInputs() { return inputs; }
- int getNumberOfOutputs() { return outputs; }
- double *getInput(int index)
- {
- double *input = data[index].input;
- cout << "cia: " << input[0] << " " << input[1] << endl;
- return input;
- }
- double *getOutput(int index)
- {
- double *output = data[index].output;
- return output;
- }
- int getNumberOfSamples() { return samples; }
- void addSample(Sample sample)
- {
- data.push_back(sample);
- samples++;
- }
- void setSizes(int input_size, int output_size)
- {
- inputs = input_size;
- outputs = output_size;
- }
- public:
- //vector<Sample*>* data;
- std::vector<Sample> data;
- int inputs;
- int outputs;
- int samples = 0;
- };
- class pictures : public Data {
- void readData() {
- }
- };
- class XOR : public Data
- {
- public:
- int randint() {
- double r = ((double)rand() / (RAND_MAX));
- int a = 0;
- if (r > 0.5) {
- a = 1;
- }
- else
- {
- a = 0;
- }
- return a;
- }
- void generate(int n)
- {
- for (int i = 0; i < n; i++)
- {
- double input1 = randint();
- double input2 = randint();
- double output1 = input1 == input2;
- double output2 = input1 != input2;
- addSample({{ input1, input2 }, { output1, output2 }});
- }
- }
- XOR()
- {
- inputs = 2;
- outputs = 2;
- samples = 0;
- }
- void printInputs(int index)
- {
- cout << index << " index inputs: " << endl;
- for (int i = 0; i < inputs; i++)
- {
- cout << getInput(index)[i] << " ";
- }
- cout << endl;
- }
- void printOutputs(int index)
- {
- cout << index << " index outputs: " << endl;
- for (int i = 0; i < outputs; i++)
- {
- cout << fixed << setprecision(2) << data[index].output[i] << " ";
- }
- cout << endl;
- }
- };
- //Generating random number: either 0 or 1, uniform distribution, for XOR operation. Can remove later if using data from files.
- int randint();
- int main()
- {
- XOR xo;
- xo.generate(10);
- for (int i = 0; i < 10; i++) {
- xo.printInputs(i);
- xo.printOutputs(i);
- cout << endl;
- }
- int a;
- cin >> a;
- return 0;
- }
- //returns random int, either 0 or 1
- int randint() {
- double r = ((double)rand() / (RAND_MAX));
- int a = 0;
- if (r > 0.5) {
- a = 1;
- }
- else
- {
- a = 0;
- }
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement