Example #1
0
        public HiddenLayer(int maxNetworks)
        {
            _nodeArray = new NodeData[maxNetworks][];

            _outputData = new NetworkData(maxNetworks);

            _resetEvent = new ManualResetEvent(false);
        }
        public NetworkData ProcessNetworksRange(NetworkData inputData, int startIndex, int endIndex)
        {
            lock (_networkLock) {
                var data = _hiddenLayer.ProcessDataRange(inputData, startIndex, endIndex);

                data = _outputLayer.ProcessDataRange(data, startIndex, endIndex);

                return(data);
            }
        }
Example #3
0
        private NetworkData InternalProcessDataMultiThread(NetworkData inputData, int startIndex, int endIndex)
        {
            if (_activeNetworks == 0)
            {
                return(_outputData);
            }

            _resetEvent.Reset();

            int incrementVal = (int)Mathf.Ceil(_activeNetworks / 8.0f);

            for (int i = startIndex; i < endIndex; i = i + incrementVal)
            {
                if (i >= _activeNetworks)
                {
                    break;
                }

                Interlocked.Increment(ref _numActiveThreads);

                var threadStartIndex = i;
                var threadEndIndex   = (threadStartIndex + incrementVal < _activeNetworks) ? threadStartIndex + incrementVal : _activeNetworks;

                ThreadPool.QueueUserWorkItem((arg) => {
                    InternalProcessDataRange(inputData, threadStartIndex, threadStartIndex + incrementVal);

                    if (Interlocked.Decrement(ref _numActiveThreads) == 0)
                    {
                        _resetEvent.Set();
                    }
                });
            }

            _resetEvent.WaitOne(50);

            return(_outputData);
        }
Example #4
0
        public static TestResults Test(Network network, List <LearningData> data, bool bitTest = true, int decimals = 100)
        {
            TestResults testResults = new TestResults();

            foreach (LearningData learningData in data)
            {
                NetworkData output  = network.Process(learningData.Input);
                bool        success = true;
                for (int i = 0; i < output.RawValues.Count; i++)
                {
                    if (bitTest && output.BitValues[i] != learningData.ExpectedOutput.BitValues[i])
                    {
                        success = false;
                        break;
                    }
                    else if (!bitTest)
                    {
                        int intOutValue      = (int)(output.RawValues[i] * decimals);
                        int intExpectedValue = (int)(learningData.ExpectedOutput.RawValues[i] * decimals);
                        if (intOutValue != intExpectedValue)
                        {
                            success = false;
                            break;
                        }
                    }
                }
                if (success)
                {
                    testResults.SuccessfulTests++;
                }
                else
                {
                    testResults.FailedTests++;
                }
            }
            return(testResults);
        }
Example #5
0
 public NetworkData ProcessDataRange(NetworkData inputData, int start, int end)
 {
     return(InternalProcessDataMultiThread(inputData, start, end));
 }
Example #6
0
 public NetworkData ProcessData(NetworkData inputData)
 {
     return(InternalProcessDataMultiThread(inputData, 0, _activeNetworks));
 }
Example #7
0
        private NetworkData InternalProcessDataSingleThread(NetworkData inputData)
        {
            InternalProcessDataRange(inputData, 0, _activeNetworks);

            return(_outputData);
        }
Example #8
0
 public NetworkData Process(NetworkData input)
 {
     return(Process(input.RawValues));
 }
 public void ProcessOutputs(NetworkData _outputData)
 {
     lock (_networkLock) {
         _outputManager.ProcessOutputs(_outputData);
     }
 }