GEOSim.cpp
上传用户:lbr_007
上传日期:2019-05-31
资源大小:282k
文件大小:3k
- // GEOSim.cpp
- //
- #include "Stdafx.h"
- #include "GEOSim.h"
- GEOSim::GEOSim(void)
- {
- initSim();
- NNode n;
- NLayer nl[3];
- //
- // we have 2 inputs and 2 outputs, so first and last
- // layers have to have 2 nodes. middle layer can have
- // any number really. for this situation I chose 6 nodes
- // in the middle layer, the first three nodes represent
- // the polynomial terms: ax^2 + bx + c; and those nodes are
- // primarily connected to the first node of the input layer.
- // the next three (middle layer) nodes are the same polynomial
- // as the first three only this type primarily connected to
- // the second node of the first (zero-th) layer. there are also
- // cross connections between the first and second layers (i.e.
- // node (0, 0) is connected to node (1, 3) etc... the cross
- // connections allow the x-input to have some (maybe minor) effect
- // on the y-output.
- //
- n.CreateNode(1, 1.0, true);
- nl[0].AddElement(n);
- nl[0].AddElement(n);
- n.CreateNode(0, 1.0, true);
- nl[1].AddElement(n);
- n.CreateNode(1, 1.0, true);
- nl[1].AddElement(n);
- n.CreateNode(2, 1.0, true);
- nl[1].AddElement(n);
- nl[1].AddElement(n);
- n.CreateNode(1, 1.0, true);
- nl[1].AddElement(n);
- n.CreateNode(0, 1.0, true);
- nl[1].AddElement(n);
- n.CreateNode(1, 1.0, true);
- nl[2].AddElement(n);
- nl[2].AddElement(n);
- m_nn.AddLayer(nl[0]);
- m_nn.AddLayer(nl[1]);
- m_nn.AddLayer(nl[2]);
- //
- // setup the connectivity, first node (0,0) to second layer
- //
- m_nn.AddConnection(0, 0, 1, 0);
- m_nn.AddConnection(0, 0, 1, 1);
- m_nn.AddConnection(0, 0, 1, 2);
- m_nn.AddConnection(0, 0, 1, 3);
- //
- // now connecting node (0, 1) to the second layer
- //
- m_nn.AddConnection(0, 1, 1, 2);
- m_nn.AddConnection(0, 1, 1, 3);
- m_nn.AddConnection(0, 1, 1, 4);
- m_nn.AddConnection(0, 1, 1, 5);
- //
- // now connecting second layer nodes to third layer (output layer),
- // note that there are NO cross connects between layers 2 and 3.
- //
- m_nn.AddConnection(1, 0, 2, 0);
- m_nn.AddConnection(1, 1, 2, 0);
- m_nn.AddConnection(1, 2, 2, 0);
- m_nn.AddConnection(1, 3, 2, 1);
- m_nn.AddConnection(1, 4, 2, 1);
- m_nn.AddConnection(1, 5, 2, 1);
- m_nn.SetMaxDelta(0.250);
- }
- GEOSim::~GEOSim(void)
- {
- }
- void GEOSim::BeginSimulatorTraining(void)
- {
- UINT32 size = m_pts.GetSize();
- if (size > 0)
- {
- RegistrationPt * ptPtr = m_pts.GetData();
- ArrayContainer<double> inputs, outputs;
- for (UINT32 i = 0; i < size; i++){
- inputs.ResetArray();
- outputs.ResetArray();
- inputs.AddElement(ptPtr[i].m_xin);
- inputs.AddElement(ptPtr[i].m_yin);
- outputs.AddElement(ptPtr[i].m_xout);
- outputs.AddElement(ptPtr[i].m_yout);
- m_nn.AddInputsAndOutputs(inputs,outputs);
- }
- m_nn.Evolve();
- m_goodToGo = true;
- }
- }
- void GEOSim::Convert(double xin, double yin, double& xout, double& yout)
- {
- ArrayContainer<double> inputs;
- ArrayContainer<double> outputs;
- inputs.AddElement(xin);
- inputs.AddElement(yin);
- m_nn.GetResult(inputs,outputs);
- if (outputs.GetSize() == 2)
- {
- xout = outputs.GetData()[0];
- yout = outputs.GetData()[1];
- }
- }