Exemplo n.º 1
0
        public void RefreshOverallNegativePscList(List <IActionMemory> actionMemories)
        {
            int minimumCount = MINIMUM_FEEDBACK_COUNT_FOR_UNIT;

            OverallNegativePartialSnapshotCompressions.Clear();
            foreach (IActionMemory actionMemoryEntry in actionMemories)
            {
                foreach (var dictPscEntry in actionMemoryEntry.NegativeDictPartialSnapshotCompressions.Where(e => e.Value.NegativeCount >= minimumCount))
                {
                    if (!OverallNegativePartialSnapshotCompressions.Contains(dictPscEntry.Key))
                    {
                        OverallNegativePartialSnapshotCompressions.Add(dictPscEntry.Key);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void RememberFeedback(int feedbackValue, ISensationSnapshot snapshot)
        {
            FieldOfVisionTypes fieldOfVision = GetFieldOfVisionsForFeedback().Last();
            List <IPartialSnapshotCompression> partialSnapshotCompressions = PartialSnapshotCompression.NewInstances(snapshot, fieldOfVision, Action.Direction, GetMaximumCompression());

            if (feedbackValue < 0)
            {
                NegativeFeedbackCount++;
                // ########### PartialSnapshotCompression #############
                foreach (IPartialSnapshotCompression pscEntry in partialSnapshotCompressions)
                {
                    if (PositveDictPartialSnapshotCompressions.ContainsKey(pscEntry))
                    {
                        PositveDictPartialSnapshotCompressions.Remove(pscEntry);
                    }

                    bool containingEntryExists = false;
                    foreach (IPartialSnapshotCompression negativePsc in NegativeDictPartialSnapshotCompressions.Keys)
                    {
                        if (GetNegativeFeedbackPercentage(negativePsc) >= 0.99 && pscEntry.Contains(negativePsc))
                        {
                            containingEntryExists = true;
                            break;
                        }
                    }
                    if (containingEntryExists)
                    {
                        continue;
                    }

                    if (!NegativeDictPartialSnapshotCompressions.ContainsKey(pscEntry))
                    {
                        NegativeDictPartialSnapshotCompressions.Add(pscEntry, new FeedbackCounter(PositiveFeedbackCount, NegativeFeedbackCount));
                    }
                    else if (GetNegativeFeedbackPercentage(pscEntry) >= 0.99)
                    {
                        var entriesToRemove = new List <IPartialSnapshotCompression>();
                        foreach (IPartialSnapshotCompression existingPsc in NegativeDictPartialSnapshotCompressions.Keys.Where(p => p.CompressionType != pscEntry.CompressionType))
                        {
                            if (existingPsc.Contains(pscEntry))
                            {
                                entriesToRemove.Add(existingPsc);
                            }
                        }
                        if (entriesToRemove.Any())
                        {
                            foreach (IPartialSnapshotCompression existingPsc in entriesToRemove)
                            {
                                NegativeDictPartialSnapshotCompressions.Remove(existingPsc);
                            }
                        }
                    }
                    else
                    {
                        NegativeDictPartialSnapshotCompressions[pscEntry].NegativeLifeCycleStamp = NegativeFeedbackCount;
                        NegativeDictPartialSnapshotCompressions[pscEntry].NegativeCount++;
                    }
                }
            }
            else if (feedbackValue > 0)
            {
                PositiveFeedbackCount++;
                // ###########  PartialSnapshotCompression #############
                foreach (IPartialSnapshotCompression pscEntry in partialSnapshotCompressions)
                {
                    if (NegativeDictPartialSnapshotCompressions.ContainsKey(pscEntry))
                    {
                        NegativeDictPartialSnapshotCompressions.Remove(pscEntry);
                    }

                    if (OverallNegativePartialSnapshotCompressions.Contains(pscEntry))
                    {
                        if (!PositveDictPartialSnapshotCompressions.ContainsKey(pscEntry))
                        {
                            PositveDictPartialSnapshotCompressions.Add(pscEntry, new FeedbackCounter(PositiveFeedbackCount, NegativeFeedbackCount));
                        }
                        else
                        {
                            PositveDictPartialSnapshotCompressions[pscEntry].PositiveLifeCycleStamp = PositiveFeedbackCount;
                            PositveDictPartialSnapshotCompressions[pscEntry].PositiveCount++;
                        }
                    }
                }
            }

            if (feedbackValue != 0)
            {
                List <IPartialSnapshotCompression> sortedKeys = NegativeDictPartialSnapshotCompressions.Keys.ToList();
                sortedKeys.Sort();
                var keysToRemove = new List <IPartialSnapshotCompression>();
                for (int i = 0; i < sortedKeys.Count - 1; i++)
                {
                    for (int j = i + 1; j < sortedKeys.Count; j++)
                    {
                        var a = sortedKeys[i];
                        var b = sortedKeys[j];
                        if (a.Contains(b) && NegativeDictPartialSnapshotCompressions[a].NegativeCount < NegativeDictPartialSnapshotCompressions[b].NegativeCount)
                        {
                            keysToRemove.Add(a);
                        }
                        else if (b.Contains(a) && NegativeDictPartialSnapshotCompressions[b].NegativeCount < NegativeDictPartialSnapshotCompressions[a].NegativeCount)
                        {
                            keysToRemove.Add(b);
                        }
                    }
                }
                foreach (var key in keysToRemove)
                {
                    NegativeDictPartialSnapshotCompressions.Remove(key);
                }
            }
        }