コード例 #1
0
        public HiddenLayer(int maxNetworks)
        {
            _nodeArray = new NodeData[maxNetworks][];

            _outputData = new NetworkData(maxNetworks);

            _resetEvent = new ManualResetEvent(false);
        }
コード例 #2
0
        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);
            }
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #5
0
 public NetworkData ProcessDataRange(NetworkData inputData, int start, int end)
 {
     return(InternalProcessDataMultiThread(inputData, start, end));
 }
コード例 #6
0
 public NetworkData ProcessData(NetworkData inputData)
 {
     return(InternalProcessDataMultiThread(inputData, 0, _activeNetworks));
 }
コード例 #7
0
        private NetworkData InternalProcessDataSingleThread(NetworkData inputData)
        {
            InternalProcessDataRange(inputData, 0, _activeNetworks);

            return(_outputData);
        }
コード例 #8
0
 public NetworkData Process(NetworkData input)
 {
     return(Process(input.RawValues));
 }
コード例 #9
0
 public void ProcessOutputs(NetworkData _outputData)
 {
     lock (_networkLock) {
         _outputManager.ProcessOutputs(_outputData);
     }
 }