Esempio n. 1
0
        public bool generateNegative(Clause pred)
        {
            int k = 0;
            int t = 0;
            int noOfClauseToCheck = 100;
            ResolutionManager rm  = new ResolutionManager();

            // int negTresh = (int)(noOfClauseToCheck * noOfClauseToCheck / negatives.Count);
            foreach (Literal c in negTrainSet)
            {
                if (rand.Next(negTrainSet.Count) < noOfClauseToCheck)
                {
                    t++;
                    Clause p = pred.clone();

                    if (rm.checkCoverage(p, c))
                    {      // return true;
                        k++;
                        c.covered = true;
                    }
                }
            }
            pred.negativeCoverage = (100.0 * k / t);
            if (pred.negativeCoverage > negativeThreshold)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        public void computeTestCoverage(Clause pred)
        {
            ResolutionManager rm = new ResolutionManager();
            int pcount           = 0;
            int total            = 0;

            foreach (Literal c in testSet)
            {
                if (!c.covered)
                {
                    Clause p = pred.clone();
                    total++;
                    if (rm.checkCoverage(p, c))
                    {
                        pcount++;
                        c.covered = true;
                    }
                }
            }
        }
Esempio n. 3
0
        public double computeCoverage(Clause pred, bool mark, bool fast) // the min coverage assumed to be five
        {
            ResolutionManager rm = new ResolutionManager();
            int pcount           = 0;
            int total            = 0;

            foreach (Literal c in trainSet)
            {
                Clause p = pred.clone();
                total++;
                if (rm.checkCoverage(p, c))
                {
                    pcount++;
                    c.covered = true;
                    if (mark)
                    {
                        c.visited = true;
                    }
                }
                if (pcount > 5)
                {
                    return(100.0 * pcount / total);
                }
                //TODO: change 104
                //  if (fast && total > 104)
                //    break;
            }
            double posCoverage = 0;

            if (total == 0)
            {
                posCoverage = 0;
            }
            else
            {
                posCoverage = 100.0 * pcount / total;
            }
            pred.positiveCoverage = posCoverage;
            return(posCoverage);
        }
Esempio n. 4
0
        public void computeDetectionRate(ArrayList list, ref double recall, ref double precision, ref double fmeasure, ref double accuracy)
        {
            resetTestCoverage();

            ResolutionManager rm = new ResolutionManager();

            int    P        = 0;
            double detected = 0;

            //TODO: PARALLEL
            Object[] cc = list.ToArray();

            if (PARALLEL)
            {
                Parallel.For(0, list.Count, i =>
                {
                    cnt++;
                    Clause p = (Clause)cc[i];
                    computeTestCoverage(p);
                });
            }
            else
            {
                foreach (Clause p in list)
                {
                    computeTestCoverage(p);
                }
            }
            foreach (Literal c in testSet)
            {
                P++;
                if (c.covered)
                {
                    detected++;
                }
            }
            //TODO: PARALLEL
            int negCov = 0;
            int N      = 0;

            foreach (Literal c in negTestSet)
            {
                N++;
                foreach (Clause p in list)
                {
                    Clause p2 = p.clone();
                    if (rm.checkCoverage(p2, c))
                    {
                        c.covered = true;
                        negCov++;
                        break;
                    }
                }
            }
            //TP: detected. FP: negCov   TN: N - FP,   FN: P - TP
            //prec = tp / (tp + fp)
            //recall = tp / p

            //   precision = 100 - ( 100.0 * negCov / negatives.Count);
            precision = 100.0 * detected / (detected + negCov);
            recall    = 100.0 * detected / P;
            if (precision + recall == 0)
            {
                fmeasure = 0;
            }
            else
            {
                fmeasure = 2 * recall * precision / (precision + recall);
            }
            accuracy = 100.0 * (detected + N - negCov) / (N + P);

            precision = Math.Round(precision, 2);
            recall    = Math.Round(recall, 2);
            fmeasure  = Math.Round(fmeasure, 2);
            accuracy  = Math.Round(accuracy, 2);
        }