public IPartialSnapshotCompression GetMaxNegativePartialSnapshotCompression(ISensationSnapshot snapshot) { IPartialSnapshotCompression result = null; double maxPercentage = 0.0; foreach (KeyValuePair <IPartialSnapshotCompression, IFeedbackCounter> entry in NegativeDictPartialSnapshotCompressions.Where(p => p.Value.PositiveCount > 0)) { // ToDo: Check in given snapshot if partialSnapshotCompression included. } return(result); }
public double GetNegativeFeedbackPercentage(IPartialSnapshotCompression partialSnapshotCompression) { double negativeCount = NegativeDictPartialSnapshotCompressions.ContainsKey(partialSnapshotCompression) ? NegativeDictPartialSnapshotCompressions[partialSnapshotCompression].NegativeCount : 0; double positivCount = PositveDictPartialSnapshotCompressions.ContainsKey(partialSnapshotCompression) ? PositveDictPartialSnapshotCompressions[partialSnapshotCompression].PositiveCount : 0; double sum = Math.Max(MINIMUM_FEEDBACK_COUNT_FOR_UNIT, positivCount + negativeCount); if (sum > 0) { return(negativeCount / sum); } return(-1.0); }
public bool Contains(IPartialSnapshotCompression other) { if (other.CompressionType > CompressionType) { return(false); } switch (other.CompressionType) { case CompressionTypes.Unit: if (other.ChildNodes.FirstOrDefault() is PartialSnapshotCompressionNode otherUnitNode) { if (ChildNodes.FirstOrDefault() is PartialSnapshotCompressionNode thisUnitNode && thisUnitNode.Unit.Equals(otherUnitNode.Unit)) { return(true); } } break; case CompressionTypes.UnitSimpleTree: case CompressionTypes.UnitCountTree: case CompressionTypes.MultiUnitCountTree: if (other.ChildNodes.FirstOrDefault() is PartialSnapshotCompressionNode otherUnitCountTreeNode) { if (ChildNodes.FirstOrDefault() is PartialSnapshotCompressionNode thisUnitNode && thisUnitNode.Unit.Equals(otherUnitCountTreeNode.Unit)) { var unitCountDict = CountEntries(thisUnitNode.ChildNodes); var otherUnitCountDict = CountEntries(otherUnitCountTreeNode.ChildNodes); foreach (KeyValuePair <IPartialSnapshotCompressionNode, int> otherEntry in otherUnitCountDict) { if (!unitCountDict.ContainsKey(otherEntry.Key)) { return(false); } if (unitCountDict[otherEntry.Key] < otherUnitCountDict[otherEntry.Key]) { return(false); } } return(true); } } break; } return(false); }
static public bool Contains(Dictionary <Tuple <FieldOfVisionTypes, DirectionTypes>, ISensationSnapshot> dictDirectionToSnapshot, IPartialSnapshotCompression partialSnapshotCompression) { ISensoryUnit baseUnit = partialSnapshotCompression.ChildNodes.FirstOrDefault().Unit; var baseDirection = DirectionTypes.Center; FieldOfVisionTypes fieldOfVision = partialSnapshotCompression.FieldOfVision; ISensationSnapshot basePartialSnapshot = dictDirectionToSnapshot[new Tuple <FieldOfVisionTypes, DirectionTypes>(fieldOfVision, baseDirection)]; switch (partialSnapshotCompression.CompressionType) { case CompressionTypes.Unit: return(basePartialSnapshot.SensoryPatterns.Any(p => p.SensoryUnits.Contains(baseUnit))); case CompressionTypes.UnitSimpleTree: case CompressionTypes.UnitCountTree: case CompressionTypes.MultiUnitCountTree: IEnumerable <ISensoryPattern> patterns = basePartialSnapshot.SensoryPatterns.Where(p => p.SensoryUnits.Contains(baseUnit)); IEnumerable <ISensoryUnit> childUnits = partialSnapshotCompression.ChildNodes.FirstOrDefault().ChildNodes.Select(p => p.Unit); foreach (var direction in patterns.Select(p => p.DirectionType)) { var childPartialSnapshot = dictDirectionToSnapshot[new Tuple <FieldOfVisionTypes, DirectionTypes>(fieldOfVision, direction)]; bool areChildNodesIncluded = false; foreach (var childUnit in childUnits.Distinct()) { var minCount = childUnits.Count(u => u.Equals(childUnit)); if (baseUnit.Equals(childUnit)) { minCount++; } areChildNodesIncluded = childPartialSnapshot.SensoryPatterns.Count(p => p.SensoryUnits.Contains(childUnit)) >= minCount; if (!areChildNodesIncluded) { break; } } if (areChildNodesIncluded) { return(true); } } break; default: throw new NotImplementedException(); } return(false); }
static public IList <IActionMemory> Parse(IList <string> lines) { if (lines == null) { return(null); } IList <IActionMemory> result = new List <IActionMemory>(); IPuzzleAction action = null; FileActionMemory fileActionMemory = null; int parseType = 0; FieldOfVisionTypes fieldOfVision = FieldOfVisionTypes.Single; foreach (var line in lines) { if (line.StartsWith(IdentifierIPuzzleAction)) { action = PuzzleAction.Parse(line.Substring(IdentifierIPuzzleAction.Length)); fileActionMemory = _fileActionMemories.Where(e => e.Action.Equals(action))?.FirstOrDefault(); if (fileActionMemory == null) { fileActionMemory = new FileActionMemory(action); _fileActionMemories.Add(fileActionMemory); } result.Add(fileActionMemory); continue; } if (fileActionMemory == null) { continue; } if (line.StartsWith(IdentifierDifferenceCount)) { fileActionMemory.DifferenceCount += int.Parse(line.Substring(IdentifierDifferenceCount.Length)); } else if (line.StartsWith(IdentifierNoDifferenceCount)) { fileActionMemory.NoDifferenceCount += int.Parse(line.Substring(IdentifierNoDifferenceCount.Length)); } else if (line.StartsWith(IdentifierPositiveFeedbackCount)) { fileActionMemory.PositiveFeedbackCount += int.Parse(line.Substring(IdentifierPositiveFeedbackCount.Length)); } else if (line.StartsWith(IdentifierNegativeFeedbackCount)) { fileActionMemory.NegativeFeedbackCount += int.Parse(line.Substring(IdentifierNegativeFeedbackCount.Length)); } else if (line.StartsWith(IdentifierDifferentUnits)) { parseType = 1; } else if (line.StartsWith(IdentifierNoDifferentUnits)) { parseType = 2; } else if (line.StartsWith(IdentifierNGetNoDifferencePattern)) { fieldOfVision = (FieldOfVisionTypes)Enum.Parse(typeof(FieldOfVisionTypes), line.Substring(IdentifierNGetNoDifferencePattern.Length)); parseType = 3; } else if (line.StartsWith(IdentifierPositveDictPartialSnapshotCompressions)) { parseType = 4; } else if (line.StartsWith(IdentifierNegativeDictPartialSnapshotCompressions)) { parseType = 5; } else { var splitedLine = line.Split(new[] { '\t' }); if (splitedLine.Length < 4) { continue; } switch (parseType) { case 1: // DifferentUnits ISensoryUnit differentUnit = SensoryUnit.Parse(splitedLine[2]); int differentUnitCount = int.Parse(splitedLine[3]); if (!fileActionMemory.DifferentUnits.ContainsKey(differentUnit)) { fileActionMemory.DifferentUnits.Add(differentUnit, 0); } fileActionMemory.DifferentUnits[differentUnit] += differentUnitCount; break; case 2: // NoDifferentUnits ISensoryUnit noDifferentUnit = SensoryUnit.Parse(splitedLine[2]); int noDifferentUnitCount = int.Parse(splitedLine[3]); if (!fileActionMemory.NoDifferentUnits.ContainsKey(noDifferentUnit)) { fileActionMemory.NoDifferentUnits.Add(noDifferentUnit, 0); } fileActionMemory.NoDifferentUnits[noDifferentUnit] += noDifferentUnitCount; break; case 3: // DifferentUnits Dictionary <ISensoryPattern, int> dictionarySensoryPatternCount = fileActionMemory.GetNoDifferencePattern(fieldOfVision); ISensoryPattern noDifferentPattern = SensoryPattern.Parse(splitedLine[2]); int noDifferentPatternCount = int.Parse(splitedLine[3]); if (!dictionarySensoryPatternCount.ContainsKey(noDifferentPattern)) { dictionarySensoryPatternCount.Add(noDifferentPattern, 0); } dictionarySensoryPatternCount[noDifferentPattern] += noDifferentPatternCount; break; case 4: // PositveDictPartialSnapshotCompressions IPartialSnapshotCompression positveDictPartialSnapshotCompression = PartialSnapshotCompression.Parse(splitedLine[2]); FeedbackCounter positiveFeedback = FeedbackCounter.Parse(splitedLine[3]) as FeedbackCounter; if (!fileActionMemory.PositveDictPartialSnapshotCompressions.ContainsKey(positveDictPartialSnapshotCompression)) { fileActionMemory.PositveDictPartialSnapshotCompressions.Add(positveDictPartialSnapshotCompression, new FeedbackCounter(0, 0)); } positiveFeedback += fileActionMemory.PositveDictPartialSnapshotCompressions[positveDictPartialSnapshotCompression] as FeedbackCounter; fileActionMemory.PositveDictPartialSnapshotCompressions[positveDictPartialSnapshotCompression] = positiveFeedback; break; case 5: // NegativeDictPartialSnapshotCompressions IPartialSnapshotCompression negativeDictPartialSnapshotCompression = PartialSnapshotCompression.Parse(splitedLine[2]); FeedbackCounter negativeFeedback = FeedbackCounter.Parse(splitedLine[3]) as FeedbackCounter; if (!fileActionMemory.NegativeDictPartialSnapshotCompressions.ContainsKey(negativeDictPartialSnapshotCompression)) { fileActionMemory.NegativeDictPartialSnapshotCompressions.Add(negativeDictPartialSnapshotCompression, new FeedbackCounter(0, 0)); } negativeFeedback += fileActionMemory.NegativeDictPartialSnapshotCompressions[negativeDictPartialSnapshotCompression] as FeedbackCounter; fileActionMemory.NegativeDictPartialSnapshotCompressions[negativeDictPartialSnapshotCompression] = negativeFeedback; break; } } } return(result); }