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 CreateLayer( IComputationalNetwork network, Func<Node> nodeFactoryMethod, int beginIndex, int count) { count = beginIndex + count; for (int neuronIndex = beginIndex; neuronIndex < count; neuronIndex++) { network.AddNode(neuronIndex, CreateNode(nodeFactoryMethod)); } }