GEOSim.cpp
上传用户:lbr_007
上传日期:2019-05-31
资源大小:282k
文件大小:3k
源码类别:

传真(Fax)编程

开发平台:

Visual C++

  1. // GEOSim.cpp
  2. //
  3. #include "Stdafx.h"
  4. #include "GEOSim.h"
  5. GEOSim::GEOSim(void)
  6. {
  7. initSim();
  8. NNode n;
  9. NLayer nl[3];
  10. //
  11. // we have 2 inputs and 2 outputs, so first and last
  12. // layers have to have 2 nodes. middle layer can have
  13. // any number really. for this situation I chose 6 nodes
  14. // in the middle layer, the first three nodes represent
  15. // the polynomial terms: ax^2 + bx + c; and those nodes are
  16. // primarily connected to the first node of the input layer.
  17. // the next three (middle layer) nodes are the same polynomial
  18. // as the first three only this type primarily connected to
  19. // the second node of the first (zero-th) layer. there are also
  20. // cross connections between the first and second layers (i.e.
  21. // node (0, 0) is connected to node (1, 3) etc... the cross
  22. // connections allow the x-input to have some (maybe minor) effect
  23. // on the y-output.
  24. //
  25. n.CreateNode(1, 1.0, true);
  26. nl[0].AddElement(n);
  27. nl[0].AddElement(n);
  28. n.CreateNode(0, 1.0, true);
  29. nl[1].AddElement(n);
  30. n.CreateNode(1, 1.0, true);
  31. nl[1].AddElement(n);
  32. n.CreateNode(2, 1.0, true);
  33. nl[1].AddElement(n);
  34. nl[1].AddElement(n);
  35. n.CreateNode(1, 1.0, true);
  36. nl[1].AddElement(n);
  37. n.CreateNode(0, 1.0, true);
  38. nl[1].AddElement(n);
  39. n.CreateNode(1, 1.0, true);
  40. nl[2].AddElement(n);
  41. nl[2].AddElement(n);
  42. m_nn.AddLayer(nl[0]);
  43. m_nn.AddLayer(nl[1]);
  44. m_nn.AddLayer(nl[2]);
  45. //
  46. // setup the connectivity, first node (0,0) to second layer
  47. //
  48. m_nn.AddConnection(0, 0, 1, 0);
  49. m_nn.AddConnection(0, 0, 1, 1);
  50. m_nn.AddConnection(0, 0, 1, 2);
  51. m_nn.AddConnection(0, 0, 1, 3);
  52. //
  53. // now connecting node (0, 1) to the second layer
  54. //
  55. m_nn.AddConnection(0, 1, 1, 2);
  56. m_nn.AddConnection(0, 1, 1, 3);
  57. m_nn.AddConnection(0, 1, 1, 4);
  58. m_nn.AddConnection(0, 1, 1, 5);
  59. //
  60. // now connecting second layer nodes to third layer (output layer),
  61. // note that there are NO cross connects between layers 2 and 3.
  62. //
  63. m_nn.AddConnection(1, 0, 2, 0);
  64. m_nn.AddConnection(1, 1, 2, 0);
  65. m_nn.AddConnection(1, 2, 2, 0);
  66. m_nn.AddConnection(1, 3, 2, 1);
  67. m_nn.AddConnection(1, 4, 2, 1);
  68. m_nn.AddConnection(1, 5, 2, 1);
  69. m_nn.SetMaxDelta(0.250);
  70. }
  71. GEOSim::~GEOSim(void)
  72. {
  73. }
  74. void GEOSim::BeginSimulatorTraining(void)
  75. {
  76. UINT32 size = m_pts.GetSize();
  77. if (size > 0)
  78. {
  79. RegistrationPt * ptPtr = m_pts.GetData();
  80. ArrayContainer<double> inputs, outputs;
  81. for (UINT32 i = 0; i < size; i++){
  82. inputs.ResetArray();
  83. outputs.ResetArray();
  84. inputs.AddElement(ptPtr[i].m_xin);
  85. inputs.AddElement(ptPtr[i].m_yin);
  86. outputs.AddElement(ptPtr[i].m_xout);
  87. outputs.AddElement(ptPtr[i].m_yout);
  88. m_nn.AddInputsAndOutputs(inputs,outputs);
  89. }
  90. m_nn.Evolve();
  91. m_goodToGo = true;
  92. }
  93. }
  94. void GEOSim::Convert(double xin, double yin, double& xout, double& yout)
  95. {
  96. ArrayContainer<double> inputs;
  97. ArrayContainer<double> outputs;
  98. inputs.AddElement(xin);
  99. inputs.AddElement(yin);
  100. m_nn.GetResult(inputs,outputs);
  101. if (outputs.GetSize() == 2)
  102. {
  103. xout = outputs.GetData()[0];
  104. yout = outputs.GetData()[1];
  105. }
  106. }