public static void InitializeFullConnected( IComputationalNetwork network, int neuronCount, Func<Connection> connectionFactoryMethod, Func<Node> nodeFactoryMethod, bool feedForward = true) { Contract.Requires(network != null); Contract.Requires(connectionFactoryMethod != null); Contract.Requires(nodeFactoryMethod != null); Contract.Requires(neuronCount > 0); Contract.Requires(feedForward == true); // TODO: Non feed-forward lock (network.SyncRoot) { try { int inputInterfaceLength = network.InputInterface.Length; int outputInterfaceLength = network.OutputInterface.Length; int neuronBeginIndex = inputInterfaceLength; int neuronEndIndex = neuronBeginIndex + neuronCount - 1; int maxConnectionIndex = inputInterfaceLength + neuronCount + outputInterfaceLength - 1; for (int idx = neuronBeginIndex; idx <= neuronEndIndex; idx++) { network.AddNode(idx, CreateNode(nodeFactoryMethod)); } for (int iidx = 0; iidx < neuronBeginIndex; iidx++) { for (int nidx = neuronBeginIndex; nidx <= neuronEndIndex; nidx++) { network.AddConnection(new ConnectionIndex(iidx, nidx), CreateConnection(connectionFactoryMethod)); } } for (int nidx = neuronBeginIndex; nidx <= neuronEndIndex; nidx++) { for (int oidx = nidx + 1; oidx <= maxConnectionIndex; oidx++) { network.AddConnection(new ConnectionIndex(nidx, oidx), CreateConnection(connectionFactoryMethod)); } } for (int idx = neuronEndIndex + 1; idx <= maxConnectionIndex; idx++) { network.AddNode(idx, CreateNode(nodeFactoryMethod)); network.AddConnection(new ConnectionIndex(idx, idx + inputInterfaceLength), CreateConnection(connectionFactoryMethod)); } } catch (Exception ex) { throw GetErrorEx(ex); } } }
private static void ConnectLayer( IComputationalNetwork network, Func<Connection> connectionFactoryMethod, int prevLayerBeginIndex, int prevLayerNeuronCount, int beginIndex, int count) { for (int pIdx = prevLayerBeginIndex; pIdx < prevLayerBeginIndex + prevLayerNeuronCount; pIdx++) { for (int idx = beginIndex; idx < beginIndex + count; idx++) { network.AddConnection(new ConnectionIndex(pIdx, idx), CreateConnection(connectionFactoryMethod)); } } }