public IOTEventTrustCategoryResult(int node, int app, IOTEventCategoryType category, DSClass ds) { this.node = node; this.ds = ds; this.category = category; this.categoryIdent = node + "-" + category; this.app = app; this.confirmedEventNums = new int[(int)IOTEventType.COUNT]; //TODO app }
public static int GetStartTypeByCategory(IOTEventCategoryType category) { switch (category) { case IOTEventCategoryType.DropPacket: return (int)IOTEventType.NotDropPacket; case IOTEventCategoryType.ModifyPacket: return (int)IOTEventType.NotModifyPacket; case IOTEventCategoryType.MakePacket: return (int)IOTEventType.NotMakePacket; case IOTEventCategoryType.DropCommand: return (int)IOTEventType.NotDropCommand; case IOTEventCategoryType.ModifyCommand: return (int)IOTEventType.NotModifyCommand; case IOTEventCategoryType.MakeCommand: return (int)IOTEventType.NotMakeCommand; //TODO others default: return -1; } }
public IOTEventTrustResult(int node, int reportNode, string pkgIdent, IOTEventCategoryType category, DSClass ds) { this.node = node; this.reportNode = reportNode; this.ds = ds; this.category = category; this.eventIdent = pkgIdent+"-"+category; //TODO app confirmBeliefThrehold = new Dictionary<IOTEventType, double>(); confirmBeliefThrehold[IOTEventType.DropPacketMaliciously] = 0.3; confirmBeliefThrehold[IOTEventType.DropCommandMaliciously] = 0.3; }
public static int GetOffsetByCategory(IOTEventCategoryType category, IOTEventType type) { switch (category) { case IOTEventCategoryType.DropPacket: return (int)type - (int)IOTDropPacketEventType.NotDropPacket; case IOTEventCategoryType.ModifyPacket: return (int)type - (int)IOTModifyPacketEventType.NotModifyPacket; case IOTEventCategoryType.MakePacket: return (int)type - (int)IOTMakePacketEventType.NotMakePacket; case IOTEventCategoryType.DropCommand: return (int)type - (int)IOTDropCommandEventType.NotDropCommand; case IOTEventCategoryType.ModifyCommand: return (int)type - (int)IOTModifyCommandEventType.NotModifyCommand; case IOTEventCategoryType.MakeCommand: return (int)type - (int)IOTMakeCommandEventType.NotMakeCommand; //TODO others default: return -1; } }
static IOTEventTrustCategoryResult CombineToCategory(int node, string ident, IOTEventCategoryType category, List<IOTEventTrustResult> events) { IOTEventTrustResult e0 = events[0]; int len = e0.ds.m.Length; int app = e0.app; DSClass ds = null; IOTEventTrustCategoryResult r = new IOTEventTrustCategoryResult(node, app, category, null); int categoryCount = IOTEventTrustResult.GetCountByCategory(category); foreach (IOTEventTrustResult e in events) { if (e.app != e0.app || e.node != e0.node || e.category != e0.category) throw new Exception(string.Format( "Error: app and node not match: {0}-{1}->{2}-{3}", e0.app, e0.node, e.app, e.node)); } //先计算归一化因子 int totalweight = 0; double[] weights = new double[events.Count]; foreach (IOTEventTrustResult e in events) { totalweight += e.nodeReportCount; } //调整权重 DSClass[] d = new DSClass[events.Count]; for (int i = 0; i < events.Count; i++) { weights[i] = (double)events[i].nodeReportCount / totalweight; d[i] = events[i].ds; } //进行正交运算 ds = DSClass.CombineWithWeight(d, weights); //计算每种类型在总的事件中确认的比例 ds.Normalize(); ds.Cal(); r.ds = ds; foreach (IOTEventTrustResult e in events) { for (int i = 0; i < categoryCount; i++) { IOTEventType type = (IOTEventType)i; /* if (!IOTEventTrustResult.confirmBeliefThrehold.ContainsKey(type)) continue; double rateThrehold = IOTEventTrustResult.confirmBeliefThrehold[type]; **/ IOTGlobal global = (IOTGlobal)IOTGlobal.getInstance(); double beliefThrehold = global.BeliefThrehold; double plausibilityThrehold = global.PlausibilityThrehold; int offset = IOTEventTrustResult.GetOffsetByCategory(e.category, type); ////计算某类型的事件发生的次数,前提是该事件正交结果可能是发生的 if (e.ds.b[DSClass.pow(offset)] > beliefThrehold && e.ds.p[DSClass.pow(offset)] > plausibilityThrehold //&& ds.b[DSClass.pow(offset)] > beliefThrehold //&& ds.p[DSClass.pow(offset)] > plausibilityThrehold ) r.confirmedEventNums[i]++; } if (e.totalEventCount > r.totalEventCount) r.totalEventCount = e.totalEventCount; } return r; }