Exemplo n.º 1
0
 static void MergeToHashDS(HashDSClass ds, IOTEventTrustCategoryResult r)
 {
     int start = IOTEventTrustResult.GetStartTypeByCategory(r.category);
     for (int i = start; i < r.ds.length; i++)
         ds.SetM(i, r.ds.m[i]);
 }
Exemplo n.º 2
0
        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;
        }