public ICollection<Agent> TrainAll(IPID iPID, HistorySnapshot snapshot)
        {
            ICollection<Agent> readyAgents = new List<Agent>();
            foreach (LearningAgent learningAgent in m_LearningAgents)
            {
                if (learningAgent.IsNative(iPID))
                {
                    learningAgent.Train(snapshot, true);
                }
                else if (learningAgent.IsForeign(iPID))
                {
                    learningAgent.Train(snapshot, false);
                }
                else
                {
                    continue;
                }

                if (learningAgent.Ready)
                {
                    readyAgents.Add(learningAgent.TurnToAgent());
                }
            }
            return readyAgents;
        }
 public static IEnumerable<HistorySnapshot> Divide(int snapshotLength, HistorySnapshot sourceSnapshot)
 {
     int parts = sourceSnapshot.Events.Count / snapshotLength;
     for (int i = 0; i < parts; i++)
     {
         yield return sourceSnapshot.Sub(i * snapshotLength, (i + 1) * snapshotLength);
     }
 }
Exemple #3
0
 public LearningPair(HistorySnapshot snapshot, bool isExplorer)
 {
     input = new double[EventNameSpacePower];
     foreach (IProcessAction action in snapshot.Events)
     {
         EventName eventName = (EventName)Enum.Parse(typeof(EventName), action.EventName);
         input[(int)eventName]++;
     }
     output[isExplorer ? 0 : 1] = 1;
     output[isExplorer ? 1 : 0] = 0;
 }
Exemple #4
0
        public ICollection<Agent> Handle(IPID iPID, IList<IProcessAction> actions)
        {
            HistorySnapshot snapshot = new HistorySnapshot(iPID, actions);

            IRecognizedAgent recognized = m_WatchingAgents.Compute(snapshot);
            if (recognized.Apply(iPID.PID))
            {
                m_History.SetDynamicName(iPID, recognized.Name, recognized.MaxRes);
            }

            IEnumerable<AgentReaction> reactions = m_GuardianAgents.Compute(snapshot);
            foreach (AgentReaction reaction in reactions)
            {
                reaction.Apply();
            }

            return m_LearningAgents.TrainAll(iPID, snapshot);
        }
 public void Save(HistorySnapshot e, DateTime date)
 {
     if (e.PID.Name == null)
         return;
     FileStream fs = null;
     try
     {
         string fileName = String.Format(FileNameLayout, e.PID.ToString(), e.PID.Name, date);
         string filePath = Path.Combine(PathToSnapshotFolder, fileName);
         fs = File.Create(filePath);
         BinaryFormatter serializer = new BinaryFormatter();
         serializer.Serialize(fs, e);
     }
     catch
     {
         int i = 0;
     }
     finally
     {
         if (fs != null)
             fs.Close();
     }
 }
 public IEnumerable<AgentReaction> Compute(HistorySnapshot snapshot)
 {
     lock (syncRoot)
     {
         foreach (KeyValuePair<Agent, GuardianAgentSession> agentSession in m_Agents)
         {
             if (!agentSession.Value.Check(snapshot.PID.PID))
             {
                 continue;
             }
             double res = agentSession.Key.Compute(snapshot);
             if (res >= agentSession.Value.E1)
             {
                 continue;
             }
             else if (res >= agentSession.Value.E2)
             {
                 yield return new AgentReaction(res, snapshot.PID.PID, agentSession.Value.YellowStrategy);
             }
             else
             {
                 yield return new AgentReaction(res, snapshot.PID.PID, agentSession.Value.RedStrategy);
             }
         }
     }
 }
 public IRecognizedAgent Compute(HistorySnapshot snapshot)
 {
     double max = 0;
     IRecognizedAgent recognized = new NotRecognizedAgent();
     lock (syncRoot)
     {
         foreach (KeyValuePair<Agent, WatchingAgentSession> agentSession in m_Agents)
         {
             double res = agentSession.Key.Compute(snapshot);
             if (res > max - agentSession.Value.P1)
             {
                 max = res;
                 RecognizedAgent newRecognized = new RecognizedAgent(agentSession.Value.AgentName,
                     res,
                     agentSession.Value.RedStrategy,
                     agentSession.Value.YellowStrategy,
                     agentSession.Value.P1,
                     agentSession.Value.P2);
                 newRecognized.MaxRes = max;
                 recognized = newRecognized;
             }
         }
     }
     return recognized;
 }
Exemple #8
0
 public void Train(HistorySnapshot snapshot, bool isTargetProcess)
 {
     m_Analyzer.RunTrain(snapshot, isTargetProcess);
 }
Exemple #9
0
 public double Compute(HistorySnapshot snapshot)
 {
     IMultiNetworkComputationResult result = m_Analyzer.Compute(snapshot);
     return result.Result[0] - result.Result[1];
 }
Exemple #10
0
 public bool Duplicates(HistorySnapshot other)
 {
     IDictionary<String, int> thisCounter = this.Counter();
     IDictionary<String, int> otherCounter = other.Counter();
     return thisCounter.OrderBy(r => r.Key).SequenceEqual(otherCounter.OrderBy(r => r.Key));
 }
Exemple #11
0
 public HistorySnapshot Sub(int from, int to)
 {
     IList<IProcessAction> list = new List<IProcessAction>();
     for (int i = from; i < to; i++)
     {
         list.Add(Events[i]);
     }
     HistorySnapshot hs = new HistorySnapshot(PID, list);
     hs.ProcessName = this.ProcessName;
     return hs;
 }