Advertisement
riabcis

Untitled

Mar 23rd, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. // Ann.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. # include <cmath>
  6. #include <math.h>
  7. #include <vector>
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <fstream>
  11.  
  12. using namespace std;
  13.  
  14.  
  15. struct Sample
  16. {
  17. double input[2];
  18. double output[2];
  19. };
  20.  
  21. class Data
  22. {
  23. public:
  24. int getNumberOfInputs() { return inputs; }
  25. int getNumberOfOutputs() { return outputs; }
  26.  
  27. double *getInput(int index)
  28. {
  29. double *input = data[index].input;
  30. cout << "cia: " << input[0] << " " << input[1] << endl;
  31. return input;
  32. }
  33.  
  34. double *getOutput(int index)
  35. {
  36. double *output = data[index].output;
  37. return output;
  38. }
  39.  
  40. int getNumberOfSamples() { return samples; }
  41.  
  42. void addSample(Sample sample)
  43. {
  44. data.push_back(sample);
  45. samples++;
  46. }
  47.  
  48. void setSizes(int input_size, int output_size)
  49. {
  50. inputs = input_size;
  51. outputs = output_size;
  52. }
  53.  
  54. public:
  55. //vector<Sample*>* data;
  56. std::vector<Sample> data;
  57. int inputs;
  58. int outputs;
  59. int samples = 0;
  60. };
  61.  
  62. class pictures : public Data {
  63. void readData() {
  64.  
  65. }
  66. };
  67. class XOR : public Data
  68. {
  69. public:
  70. int randint() {
  71. double r = ((double)rand() / (RAND_MAX));
  72. int a = 0;
  73. if (r > 0.5) {
  74. a = 1;
  75. }
  76. else
  77. {
  78. a = 0;
  79. }
  80. return a;
  81. }
  82. void generate(int n)
  83. {
  84. for (int i = 0; i < n; i++)
  85. {
  86. double input1 = randint();
  87. double input2 = randint();
  88. double output1 = input1 == input2;
  89. double output2 = input1 != input2;
  90.  
  91. addSample({{ input1, input2 }, { output1, output2 }});
  92. }
  93. }
  94.  
  95. XOR()
  96. {
  97. inputs = 2;
  98. outputs = 2;
  99. samples = 0;
  100. }
  101.  
  102. void printInputs(int index)
  103. {
  104. cout << index << " index inputs: " << endl;
  105. for (int i = 0; i < inputs; i++)
  106. {
  107. cout << getInput(index)[i] << " ";
  108. }
  109. cout << endl;
  110. }
  111.  
  112. void printOutputs(int index)
  113. {
  114. cout << index << " index outputs: " << endl;
  115. for (int i = 0; i < outputs; i++)
  116. {
  117. cout << fixed << setprecision(2) << data[index].output[i] << " ";
  118. }
  119. cout << endl;
  120. }
  121. };
  122.  
  123. //Generating random number: either 0 or 1, uniform distribution, for XOR operation. Can remove later if using data from files.
  124. int randint();
  125.  
  126. int main()
  127. {
  128. XOR xo;
  129. xo.generate(10);
  130.  
  131. for (int i = 0; i < 10; i++) {
  132. xo.printInputs(i);
  133. xo.printOutputs(i);
  134. cout << endl;
  135. }
  136.  
  137.  
  138. int a;
  139. cin >> a;
  140.  
  141. return 0;
  142. }
  143.  
  144. //returns random int, either 0 or 1
  145. int randint() {
  146. double r = ((double)rand() / (RAND_MAX));
  147. int a = 0;
  148. if (r > 0.5) {
  149. a = 1;
  150. }
  151. else
  152. {
  153. a = 0;
  154. }
  155. return a;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement