示例#1
0
        public void Connect(int fromIndex, int toIndex, bool required, Range inputRange = null, Range prevOutRange = null, List <List <double> > weigths = null)
        {
            int  insertionIndex = 0; // insert it sorted in network toIndex from less to more compared by fromIndex
            bool found          = false;
            int  connectedWidth = fromIndex == -1 ? inputLenght : networks[fromIndex].Network.OutputLength;
            var  connection     = new ConnectedNet.Connection(fromIndex, toIndex, prevOutRange, inputRange, required, weigths, networks[toIndex].Network.InputLength, connectedWidth);

            if (networks[toIndex].Connections.Count > 0)
            {
                //isBegining?
                if (fromIndex < networks[toIndex].Connections[0].fromNetworkIndex)
                {
                    found = true;
                }
                else
                {
                    for (int connectionIndex = 1; connectionIndex < networks[toIndex].Connections.Count - 1 && !found; connectionIndex++)
                    {
                        Range range = new Range(networks[toIndex].Connections[connectionIndex - 1].fromNetworkIndex, networks[toIndex].Connections[connectionIndex].fromNetworkIndex);
                        if (range.IsInside(fromIndex))
                        {
                            insertionIndex = connectionIndex;
                        }
                    }

                    //isEnd?
                    if (fromIndex > networks[toIndex].Connections[networks[toIndex].Connections.Count - 1].fromNetworkIndex && !found)
                    {
                        insertionIndex = networks[toIndex].Connections.Count - 1;
                    }
                }
            }

            networks[toIndex].Connections.Insert(insertionIndex, connection);
        }
示例#2
0
        ///<summary>pass an output to its associated connections without counting weigths</summary>
        private void PassOutput(double[] output, int networkIndex)
        {
            List <int> connectedNets = GetNetworksConnectedTo(networkIndex, out List <int> connectionIndexes);

            for (int i = 0; i < connectedNets.Count; i++)
            {
                ConnectedNet.Connection connectionCopy = networks[connectedNets[i]].Connections[connectionIndexes[i]];
                double[] inputValues = new double[connectionCopy.fromRange.Lenght];

                int index = 0;
                for (int valueIndex = connectionCopy.fromRange.start; valueIndex < connectionCopy.fromRange.start + connectionCopy.fromRange.Lenght; valueIndex++)
                {
                    inputValues[index] = output[valueIndex];
                    index++;
                }
                networks[connectedNets[i]].Connections[connectionIndexes[i]].valuesToPass = inputValues;
            }
        }