public FileActionMemory(IActionMemory actionMemory) : base(actionMemory.Action) { DifferenceCount = actionMemory.DifferenceCount; NoDifferenceCount = actionMemory.NoDifferenceCount; PositiveFeedbackCount = actionMemory.PositiveFeedbackCount; NegativeFeedbackCount = actionMemory.NegativeFeedbackCount; }
public void TryToLearn() { ActionFeedback = 0; // Zuerst mal die Lage erkunden RaiseExperienceWanted(); ISensationSnapshot sensationSnapshotBeforeAction = _lastSensationSnapshot; if (CheckForConflicts(sensationSnapshotBeforeAction)) { return; } // Nun wird entschieden welche Aktion ausgeführt werden soll IPuzzleAction action = GetDecisionByMemory(sensationSnapshotBeforeAction); if (action == null) { } // Nun eine Aktion ausführen und Reaktion erkennen RaiseActionWanted(action); int actionFeedback = ActionFeedback; // Wieder die Lage ermitteln und mit dem Zustand zuvor vergleichen RaiseExperienceWanted(); ISensationSnapshot sensationSnapshotAfterAction = _lastSensationSnapshot; var difference = SensationSnapshot.GetDifferencePatterns(sensationSnapshotBeforeAction, sensationSnapshotAfterAction); IActionMemory actionMemory = ActionMemoryDictonary[action]; bool isDifferent = difference.SensoryPatterns.Any(); actionMemory.RememberDifference(isDifferent, sensationSnapshotBeforeAction); if (isDifferent) { if (actionFeedback != 0) { if (actionFeedback < 0) { Console.WriteLine("Error occurred!"); } actionMemory.RememberFeedback(actionFeedback, sensationSnapshotBeforeAction); actionMemory.RefreshOverallNegativePscList(ActionMemoryDictonary.Values.ToList()); } _actionFeedbackHistory.Add(actionFeedback); while (_actionFeedbackHistory.Count > MAX_ACTION_FEEDBACK_HISTORY_COUNT) { _actionFeedbackHistory.RemoveAt(0); } } }
static public string Convert(IActionMemory actionMemory) { StringBuilder content = new StringBuilder(); content.AppendLine($"{IdentifierIPuzzleAction}\t{actionMemory.Action}"); content.AppendLine($"{IdentifierDifferenceCount}\t{actionMemory.DifferenceCount}"); content.AppendLine($"{IdentifierNoDifferenceCount}\t{actionMemory.NoDifferenceCount}"); content.AppendLine($"{IdentifierPositiveFeedbackCount}\t{actionMemory.PositiveFeedbackCount}"); content.AppendLine($"{IdentifierNegativeFeedbackCount}\t{actionMemory.NegativeFeedbackCount}"); content.AppendLine($"{IdentifierDifferentUnits}"); foreach (KeyValuePair <ISensoryUnit, int> entry in actionMemory.DifferentUnits) { content.AppendLine($"\t\t{entry.Key}\t{entry.Value}"); } content.AppendLine($"{IdentifierNoDifferentUnits}"); foreach (KeyValuePair <ISensoryUnit, int> entry in actionMemory.NoDifferentUnits) { content.AppendLine($"\t\t{entry.Key}\t{entry.Value}"); } foreach (FieldOfVisionTypes fieldOfVision in Enum.GetValues(typeof(FieldOfVisionTypes))) { content.AppendLine($"{IdentifierNGetNoDifferencePattern}\t{fieldOfVision}"); foreach (var entry in actionMemory.GetNoDifferencePattern(fieldOfVision)) { content.AppendLine($"\t\t{entry.Key}\t{entry.Value}"); } } content.AppendLine($"{IdentifierPositveDictPartialSnapshotCompressions}"); foreach (KeyValuePair <IPartialSnapshotCompression, IFeedbackCounter> entry in actionMemory.PositveDictPartialSnapshotCompressions.OrderByDescending(x => x.Value.PositiveCount)) { content.AppendLine($"\t\t{entry.Key}\t{entry.Value}"); } content.AppendLine($"{IdentifierNegativeDictPartialSnapshotCompressions}"); foreach (KeyValuePair <IPartialSnapshotCompression, IFeedbackCounter> entry in actionMemory.NegativeDictPartialSnapshotCompressions.OrderByDescending(x => x.Value.NegativeCount)) { content.AppendLine($"\t\t{entry.Key}\t{entry.Value}"); } return(content.ToString()); }