public IMultiNetworkComputationResult Compute(HistorySnapshot snapshot) { IDictionary<Type, Input> learningDict = GetPairs(snapshot); IList<NetworkComputationResultEntry> results = new List<NetworkComputationResultEntry>(); foreach (KeyValuePair<Type, Input> typePairPair in learningDict) { NetworkComputationResultEntry resultEntry = new NetworkComputationResultEntry( NetworkMap[typePairPair.Key].Compute( Normalize( typePairPair.Value.Values ) ), typePairPair.Key.Name); results.Add(resultEntry); } return new MultiNetworkComputationResult(results, TrustVector); }
private IDictionary<Type, TypedLearningPair> GetRandomNegativePairs(HistorySnapshot snapshot) { IDictionary<Type, TypedLearningPair> learningDict = new Dictionary<Type, TypedLearningPair>(); int count = snapshot.Events.Count; int types = Enum.GetNames(typeof(EventName)).Length; Random rnd = new Random(); for (int i = 0; i < count; i++) { string name = ((EventName) rnd.Next(types)).ToString(); Type type = Significator.ToSignificantType(name); if (type == null) continue; TypedLearningPair pair; if (!learningDict.ContainsKey(type)) { pair = new TypedLearningPair(type, false); learningDict.Add(type, pair); } else { pair = learningDict[type]; } pair.Modify(Significator.ToSignificant(name)); } return learningDict; }
private IDictionary<Type, TypedLearningPair> GetPairs(HistorySnapshot snapshot, bool isTarget) { IDictionary<Type, TypedLearningPair> learningDict = new Dictionary<Type, TypedLearningPair>(); foreach (IProcessAction action in snapshot.Events) { Type type = Significator.ToSignificantType(action.EventName); if (type == null) continue; TypedLearningPair pair; if (!learningDict.ContainsKey(type)) { pair = new TypedLearningPair(type, isTarget); learningDict.Add(type, pair); } else { pair = learningDict[type]; } pair.Modify(Significator.ToSignificant(action.EventName)); } return learningDict; }
private IDictionary<Type, Input> GetPairs(HistorySnapshot snapshot) { IDictionary<Type, Input> learningDict = new Dictionary<Type, Input>(); foreach (IProcessAction action in snapshot.Events) { Type type = Significator.ToSignificantType(action.EventName); if (type == null) continue; Input input; if (!learningDict.ContainsKey(type)) { input = new Input(Enum.GetValues(type).Length); learningDict.Add(type, input); } else { input = learningDict[type]; } input.Modify(type, Significator.ToSignificant(action.EventName)); } return learningDict; }
public void RunTrain(HistorySnapshot snapshot, bool isTargetProcess) { Log.Info((isTargetProcess ? "Target: " : "Non-target: ") + snapshot.ToString()); IDictionary<Type, TypedLearningPair> learningDict; if (isTargetProcess) { learningDict = GetPairs(snapshot, true); LearnedAffectedKeys.UnionWith(snapshot.AffectedKeys); } else { //learningDict = new Dictionary<Type, TypedLearningPair>(); //learningDict = GetPairs(snapshot, false); learningDict = GetRandomNegativePairs(snapshot); } foreach (KeyValuePair<Type, TypedLearningPair> typePairPair in learningDict) { TrainerMap[typePairPair.Key].Run(Normalize(typePairPair.Value.Input), typePairPair.Value.Output); } }