public ClassificationResult Classify( int count, Classifier classifier, GroupCache groupCache, EncodingResult encodingResult, RevealedVectorSet trainingSet = null) { trainingSet = trainingSet ?? new RevealedVectorSet(); var correctlyAccepted = 0; var correctlyRejected = 0; var wronglyAccepted = 0; var wronglyRejected = 0; var correctlyRejectedInRejecting = 0; var wronglyRejectedInRejecting = 0; var rejectAccept = new List <List <SuspiciousNode> >(); var rejectReject = new List <List <SuspiciousNode> >(); var acceptAccept = new List <List <SuspiciousNode> >(); var acceptReject = new List <List <SuspiciousNode> >(); for (int i = 0; i < classifier.GroupCount; i++) { rejectAccept.Add(new List <SuspiciousNode>()); rejectReject.Add(new List <SuspiciousNode>()); acceptAccept.Add(new List <SuspiciousNode>()); acceptReject.Add(new List <SuspiciousNode>()); } var wrongNodeCount = 0; var wronglyRejectedFeatures = new List <BigInteger>(); var wronglyAcceptedFeatures = new List <BigInteger>(); foreach (var vectorAndGroupPath in encodingResult.IdealVectorSet.Accepted) { var vector = vectorAndGroupPath.Key; var groupPath = vectorAndGroupPath.Value; var groupIndex = groupCache.GetGroupIndex(vector); var rejected = classifier.IsRejected(vector, groupIndex); var accepted = classifier.IsAccepted(vector, groupIndex); if (!trainingSet.Accepted.ContainsKey(vector) && !trainingSet.Rejected.ContainsKey(vector)) { var target = new SuspiciousNode { Vector = vector, GroupKey = groupPath, Used = false, }; if (accepted) { if (!rejected) { acceptAccept[groupIndex].Add(target); } else { acceptReject[groupIndex].Add(target); } } else { if (!rejected) { rejectAccept[groupIndex].Add(target); } else { rejectReject[groupIndex].Add(target); } } } if (!accepted) { wronglyRejected++; wrongNodeCount += encodingResult.Vector2Count[vector]; wronglyRejectedFeatures.Add(vector); } else if (!rejected) { correctlyAccepted++; } else { wronglyRejectedInRejecting++; wrongNodeCount += encodingResult.Vector2Count[vector]; wronglyRejectedFeatures.Add(vector); } } foreach (var vectorAndGroupPath in encodingResult.IdealVectorSet.Rejected) { var vector = vectorAndGroupPath.Key; var groupPath = vectorAndGroupPath.Value; var groupIndex = groupCache.GetGroupIndex(vector); var rejected = classifier.IsRejected(vector, groupIndex); var accepted = classifier.IsAccepted(vector, groupIndex); if (!trainingSet.Accepted.ContainsKey(vector) && !trainingSet.Rejected.ContainsKey(vector)) { var target = new SuspiciousNode { Vector = vector, GroupKey = groupPath, Used = false, }; if (accepted) { if (!rejected) { acceptAccept[groupIndex].Add(target); } else { acceptReject[groupIndex].Add(target); } } else { if (!rejected) { rejectAccept[groupIndex].Add(target); } else { rejectReject[groupIndex].Add(target); } } } if (!accepted) { correctlyRejected++; } else if (!rejected) { wronglyAccepted++; wrongNodeCount += encodingResult.Vector2Count[vector]; wronglyAcceptedFeatures.Add(vector); } else { correctlyRejectedInRejecting++; } } Console.WriteLine("done"); Console.WriteLine( "WA: " + wronglyAccepted + ", WR: " + wronglyRejected + "/" + wronglyRejectedInRejecting + ", CA: " + correctlyAccepted + ", CR: " + correctlyRejected + "/" + correctlyRejectedInRejecting); Console.WriteLine( "TR: " + trainingSet.Count + ", AF: " + String.Join(", ", classifier.CountAcceptingFeatures()) + ", RF: " + String.Join(", ", classifier.CountRejectingFeatures())); var wrongFeatureCount = wronglyAccepted + wronglyRejected + wronglyRejectedInRejecting; var selector = new SuspiciousNodeSelector(classifier.AcceptingFeatureBitMask, classifier.RejectingFeatureBitMask); var suspiciousNodes = selector.SelectSuspiciousNodes(count, classifier, acceptAccept, acceptReject, rejectAccept, rejectReject); return(new ClassificationResult(suspiciousNodes, wronglyAcceptedFeatures, wronglyRejectedFeatures, wrongFeatureCount, wrongNodeCount, encodingResult)); }
private static int DetermineStrongCount(int groupIndex, Classifier classifier) { return classifier.CountAcceptingFeatures().ElementAt(groupIndex) > ThresholdvectorCount ? StronglyTargetCount : StronglyTargetCount / 2; }
private static int DetermineCount(Classifier classifier, int groupIndex) { return classifier.CountAcceptingFeatures().ElementAt(groupIndex) > ThresholdvectorCount ? TargetCount : TargetCount / 2; }
private static int DetermineStrongCount(int groupIndex, Classifier classifier) { return(classifier.CountAcceptingFeatures().ElementAt(groupIndex) > ThresholdvectorCount ? StronglyTargetCount : StronglyTargetCount / 2); }
private static int DetermineCount(Classifier classifier, int groupIndex) { return(classifier.CountAcceptingFeatures().ElementAt(groupIndex) > ThresholdvectorCount ? TargetCount : TargetCount / 2); }
public ClassificationResult Classify( int count, Classifier classifier, GroupCache groupCache, EncodingResult encodingResult, RevealedVectorSet trainingSet = null) { trainingSet = trainingSet ?? new RevealedVectorSet(); var correctlyAccepted = 0; var correctlyRejected = 0; var wronglyAccepted = 0; var wronglyRejected = 0; var correctlyRejectedInRejecting = 0; var wronglyRejectedInRejecting = 0; var rejectAccept = new List<List<SuspiciousNode>>(); var rejectReject = new List<List<SuspiciousNode>>(); var acceptAccept = new List<List<SuspiciousNode>>(); var acceptReject = new List<List<SuspiciousNode>>(); for (int i = 0; i < classifier.GroupCount; i++) { rejectAccept.Add(new List<SuspiciousNode>()); rejectReject.Add(new List<SuspiciousNode>()); acceptAccept.Add(new List<SuspiciousNode>()); acceptReject.Add(new List<SuspiciousNode>()); } var wrongNodeCount = 0; var wronglyRejectedFeatures = new List<BigInteger>(); var wronglyAcceptedFeatures = new List<BigInteger>(); foreach (var vectorAndGroupPath in encodingResult.IdealVectorSet.Accepted) { var vector = vectorAndGroupPath.Key; var groupPath = vectorAndGroupPath.Value; var groupIndex = groupCache.GetGroupIndex(vector); var rejected = classifier.IsRejected(vector, groupIndex); var accepted = classifier.IsAccepted(vector, groupIndex); if (!trainingSet.Accepted.ContainsKey(vector) && !trainingSet.Rejected.ContainsKey(vector)) { var target = new SuspiciousNode { Vector = vector, GroupKey = groupPath, Used = false, }; if (accepted) { if (!rejected) { acceptAccept[groupIndex].Add(target); } else { acceptReject[groupIndex].Add(target); } } else { if (!rejected) { rejectAccept[groupIndex].Add(target); } else { rejectReject[groupIndex].Add(target); } } } if (!accepted) { wronglyRejected++; wrongNodeCount += encodingResult.Vector2Count[vector]; wronglyRejectedFeatures.Add(vector); } else if (!rejected) { correctlyAccepted++; } else { wronglyRejectedInRejecting++; wrongNodeCount += encodingResult.Vector2Count[vector]; wronglyRejectedFeatures.Add(vector); } } foreach (var vectorAndGroupPath in encodingResult.IdealVectorSet.Rejected) { var vector = vectorAndGroupPath.Key; var groupPath = vectorAndGroupPath.Value; var groupIndex = groupCache.GetGroupIndex(vector); var rejected = classifier.IsRejected(vector, groupIndex); var accepted = classifier.IsAccepted(vector, groupIndex); if (!trainingSet.Accepted.ContainsKey(vector) && !trainingSet.Rejected.ContainsKey(vector)) { var target = new SuspiciousNode { Vector = vector, GroupKey = groupPath, Used = false, }; if (accepted) { if (!rejected) { acceptAccept[groupIndex].Add(target); } else { acceptReject[groupIndex].Add(target); } } else { if (!rejected) { rejectAccept[groupIndex].Add(target); } else { rejectReject[groupIndex].Add(target); } } } if (!accepted) { correctlyRejected++; } else if (!rejected) { wronglyAccepted++; wrongNodeCount += encodingResult.Vector2Count[vector]; wronglyAcceptedFeatures.Add(vector); } else { correctlyRejectedInRejecting++; } } Console.WriteLine("done"); Console.WriteLine( "WA: " + wronglyAccepted + ", WR: " + wronglyRejected + "/" + wronglyRejectedInRejecting + ", CA: " + correctlyAccepted + ", CR: " + correctlyRejected + "/" + correctlyRejectedInRejecting); Console.WriteLine( "TR: " + trainingSet.Count + ", AF: " + String.Join(", ", classifier.CountAcceptingFeatures()) + ", RF: " + String.Join(", ", classifier.CountRejectingFeatures())); var wrongFeatureCount = wronglyAccepted + wronglyRejected + wronglyRejectedInRejecting; var selector = new SuspiciousNodeSelector(classifier.AcceptingFeatureBitMask, classifier.RejectingFeatureBitMask); var suspiciousNodes = selector.SelectSuspiciousNodes(count, classifier, acceptAccept, acceptReject, rejectAccept, rejectReject); return new ClassificationResult(suspiciousNodes, wronglyAcceptedFeatures, wronglyRejectedFeatures, wrongFeatureCount, wrongNodeCount, encodingResult); }