Guest User

Untitled

a guest
May 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <QtGui/QApplication>
  2. #include <QFile>
  3. #include <QTextStream>
  4. #include <QChar>
  5. #include "mainwindow.h"
  6. #include "neuron.h"
  7. #include "outputstream.h"
  8.  
  9. QTextStream qout(stdout);
  10.  
  11. Neuron* createNeuron(QVector<int>& weights)
  12. {
  13. QFile file("neuron.cfg");
  14. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  15. return 0;
  16. Neuron* neuron = new Neuron();
  17. int i;
  18. QTextStream in(&file);
  19. if (!in.atEnd()) {
  20. in >> i;
  21. qout << i << endl;
  22. neuron->setThreshold(i);
  23. }
  24.  
  25. while (!in.atEnd()) {
  26. in >> i;
  27. qout << i << endl;
  28. weights.append(i);
  29. }
  30. return neuron;
  31. }
  32.  
  33. QVector<QBitArray>* readInputFile()
  34. {
  35. QVector<QBitArray>* input = new QVector<QBitArray>;
  36. QFile file("neuron.in");
  37. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  38. return input;
  39. QTextStream in(&file);
  40. while (!in.atEnd()) {
  41. QString line = in.readLine();
  42. QBitArray bits(line.size());
  43. for (int i = 0; i < line.size(); ++i) {
  44. qout << line.at(i);
  45. bits[i] = (line.at(i) == '0') ? false : true;
  46. }
  47. qout << endl;
  48. input->append(bits);
  49. }
  50. return input;
  51. }
  52.  
  53. int decideLongest(QVector<QBitArray>* input)
  54. {
  55. int longest = 0;
  56. foreach (QBitArray array, *input) {
  57. if (array.size() > longest)
  58. longest = array.size();
  59. }
  60. return longest;
  61. }
  62.  
  63. void readFiles()
  64. {
  65. QVector<int> weights;
  66. Neuron* neuron = createNeuron(weights);
  67. QVector<QBitArray>* input = readInputFile();
  68. OutputStream* os = new OutputStream;
  69. QObject::connect(neuron, SIGNAL(output(int)), os, SLOT(addData(int)));
  70. int longest = decideLongest(input);
  71. for (int i = 0; i < input->size(); ++i) {
  72. for (int j = 0; j < longest; ++j) {
  73. if (j < input->at(i).size())
  74. neuron->input((input->at(i)[j]) ? 1 : 0 * weights[i]);
  75. else
  76. neuron->input(0);
  77. }
  78. }
  79. qout << "wynik:" << os->getString();
  80. }
  81.  
  82. int main(int argc, char *argv[])
  83. {
  84. QCoreApplication a(argc, argv);
  85. readFiles();
  86. a.exit();
  87. return 0;
  88.  
  89. MainWindow w;
  90. #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
  91. w.showMaximized();
  92. #else
  93. w.show();
  94. #endif
  95. return a.exec();
  96. }
Add Comment
Please, Sign In to add comment