protected override void Iterate() { try { if (_inputBuffer.IsFull) { for (var i = 0; i < _subEntities.Count; i++) { // if buffer is empty, and "IsFull" then there is no buffer // and so we throw in non-buffered input _subEntities[i].Step(Input); } // get hash and add lookup if one doesn't exist yet var hash = State = GetState(); var hashIfTrue = hash.AndWith(true); var hashIfFalse = hash.AndWith(false); if (!_outLookup.ContainsKey(hashIfTrue)) { _outLookup[hashIfTrue] = new CacheList <Contentment>(_stateSize); } if (!_outLookup.ContainsKey(hashIfFalse)) { _outLookup[hashIfFalse] = new CacheList <Contentment>(_stateSize); } // add element to history if (_hashMemory.IsFull) { var list = _outLookup[_hashMemory.First()]; //FIFO list.Add(Input.Contentment); } var trueAverageContentment = _outLookup[hashIfTrue] .Select(x => x.Value) .Concat(_outLookup[hashIfFalse].Select(x => 1 - x.Value)) .AverageOrDefault(0.5); var falseAverageContentment = _outLookup[hashIfFalse] .Select(x => x.Value) .Concat(_outLookup[hashIfTrue].Select(x => 1 - x.Value)) .AverageOrDefault(0.5); Output = trueAverageContentment >= falseAverageContentment ? new IntelligenceOutput <bool> { Object = true } : new IntelligenceOutput <bool> { Object = false }; _hashMemory.Add(hash.AndWith(Output.Object)); } } finally { _inputBuffer.Add(Input); // If size 0, essentially a no-op } }
/// <summary> /// Determines if key/value pair position in LRU cache list is first. /// </summary> /// <param name="key"></param> /// <returns></returns> public bool IsKeyValuePairFirst(KeyType key) { return(CacheList.First().Key.Equals(key)); }