private void Button_Click_1(object sender, RoutedEventArgs e) { string collectionName = CollectionName.Text; int featureCount = int.Parse(FeatureCount.Text); //int featureToSelectCount = int.Parse(FeatureToSelectCount.Text); DatabaseService databaseService = new DatabaseService(); var dataSet = databaseService.ConvertMongoColectionToListOfLists(featureCount, collectionName); SpearmanCorrelation spearmanCorrelation = new SpearmanCorrelation(); var wynik = spearmanCorrelation.MakeCorelationTable(featureCount, collectionName, dataSet); ////before your loop var csv = new StringBuilder(); for (int i = 0; i < featureCount + 1; i++) { var newLine = string.Empty; for (int j = 0; j < featureCount + 1; j++) { newLine += wynik[i, j].ToString() + ";"; } csv.AppendLine(newLine); } File.WriteAllText($"E://cos//wynikiDobreDoMGR//Spearman_{collectionName}_corelationTable_{DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")}.txt", csv.ToString()); //FiltersHelper filtersHelper = new FiltersHelper(); //filtersHelper.SelectFeaturesAndWriteToFile(wynik, featureToSelectCount, "Spearman_" + collectionName, featureCount); FeatureSelection featureSelection = new FeatureSelection(); featureSelection.SelectFeaturesAndCheckClasification(wynik, featureCount + 1, dataSet, collectionName, "Spearman"); MessageBox.Show("Wykonano obliczenia."); }
public void RandomForestsCrossValidationTest_2() { this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_dnsHttpTls_cap); var applicationProtocolModelEvaluator = this.AppIdentService.CreateApplicationProtocolModels(this.L7Conversations, 10); var featureVectors = applicationProtocolModelEvaluator.TrainingFeatureVectors.ToList(); var appIdentAcordSource = new AppIdentAcordSource(); appIdentAcordSource.Init(featureVectors); Console.WriteLine($"Feature vectors: {featureVectors.Count}"); var featureSelection = new FeatureSelection(appIdentAcordSource.FeatureSelector); featureSelection.ProcessFeatureSelection(appIdentAcordSource, 0.5); foreach (var feature in featureSelection.FeatureSelector.SelectedFeatures) { Console.WriteLine($"{feature.Name}"); } var rfcModel = this.AccordAppIdent.GetBestRandomForestsWithGridSearch(appIdentAcordSource, out var bestParameters, out var minError); // get the cross validation results var cvResults = this.AccordAppIdent.GetCrossValidationResultsOfRandomForestModel(appIdentAcordSource, bestParameters); Console.WriteLine("### CV Results ###"); Console.WriteLine("\n### Training stats ###"); Console.WriteLine(">> model error mean: {0}\n>> model std: {1}", Math.Round(cvResults.Training.Mean, 6), Math.Round(cvResults.Training.StandardDeviation, 6)); Console.WriteLine("\n### Validation stats ###"); Console.WriteLine(">> model error mean: {0}\n>> model std: {1}", Math.Round(cvResults.Validation.Mean, 6), Math.Round(cvResults.Validation.StandardDeviation, 6)); var minErorr = cvResults.Validation.Values.Min(); var bestIndex = cvResults.Validation.Values.IndexOf(minErorr); var classifier = cvResults.Models[bestIndex]; var validationDataSource = classifier.Tag as AccordAppIdent.ValidationDataSource; var predictedValues = classifier.Model.Decide(validationDataSource.ValidationInputs); var i = 0; foreach (var label in appIdentAcordSource.Labels.Distinct()) { var conf = new ConfusionMatrix(validationDataSource.ValidationOutputs, predictedValues, i++); Console.WriteLine($"##########################"); Console.WriteLine($"Protocol: {label}"); Console.WriteLine($"TP: {conf.TruePositives}"); Console.WriteLine($"TN: {conf.TrueNegatives}"); Console.WriteLine($"FN: {conf.FalseNegatives}"); Console.WriteLine($"FP: {conf.FalsePositives}"); Console.WriteLine($"Accuracy: {conf.Accuracy}"); Console.WriteLine($"Precision: {conf.Precision}"); Console.WriteLine($"Specificity: {conf.Specificity}"); Console.WriteLine($"Sensitivity: {conf.Sensitivity}"); Console.WriteLine($"FScore: {conf.FScore}"); } }
public FeatureSelector EliminateCorelatedFeatures(AppIdentAcordSource appIdentAcordSource, double trashold, AppIdentTestContext appIdentTestContext) { var featureSelection = new FeatureSelection(); featureSelection.ProcessFeatureSelection(appIdentAcordSource, trashold); var featureSelector = appIdentAcordSource.FeatureSelector; appIdentTestContext.Save(featureSelector); return(featureSelector); }
// Left hand public override object VisitComposite_selector_simple([NotNull] GrammarParser.Composite_selector_simpleContext context) { // 1. Visit the children (Feature_selector_abs and Attribute_selector) FeatureSelection matchingFeatureSelection = (FeatureSelection)Visit(context.feature_selector_abs()); string attributeIdentifier = (string)Visit(context.attribute_selector()); // 2. Get the matching AttributeValue AttributeValue matchingAttributeValue = matchingFeatureSelection.AttributeValues.Find(attrval => attrval.AttributeIdentifier == attributeIdentifier); // 3. Return the AttributeValue together with its parent FeatureSelection return(new AttrValAndFeatureSelPair() { ParentFeatureSelection = matchingFeatureSelection, AttributeValue = matchingAttributeValue }); }
//[DotMemoryUnit(CollectAllocations = true)] //[AssertTraffic(AllocatedSizeInBytes = 1024*1024)] public void CorrelationMatrixTest_M2() { MainWindow window = null; this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_dnsHttpTls_cap); this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_learn1_cap); this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_refSkype_cap); this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_streamSkypeHttpTls_cap); this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_testM1_cap); this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_testM2_cap); List <L7Conversation> testSet; var applicationProtocolModelEvaluator = this.AppIdentService.CreateApplicationProtocolModels(this.L7Conversations, 0.9, out testSet); var featureVectors = applicationProtocolModelEvaluator.TrainingFeatureVectors.ToList(); var appIdentAcordSource = new AppIdentAcordSource(); appIdentAcordSource.Init(featureVectors); var featureSelection = new FeatureSelection(appIdentAcordSource.FeatureSelector); var selection = featureSelection.ProcessFeatureSelection(appIdentAcordSource, 0.3); var correlationMatrix = selection.Last(); // The dispatcher thread var t = new Thread(() => { window = new MainWindow { DataContext = new MainViewModel(appIdentAcordSource.FeatureNames, correlationMatrix) }; //window.DataContext = new MainViewModel(); // Initiates the dispatcher thread shutdown when the window closes window.Closed += (s, e) => window.Dispatcher.InvokeShutdown(); window.Show(); // Makes the thread support message pumping Dispatcher.Run(); }); // Configure the thread t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); }
// Common public override object VisitFeature_selector_abs([NotNull] GrammarParser.Feature_selector_absContext context) { // Variables string featureIdentifier = context.IDENTIFIER() != null?context.IDENTIFIER().ToString() : null; bool isRootFeatureSelector = context.ROOTFEATURE() != null ? true : false; FeatureSelection matchingFeatureSelection = null; // Find the matching FeatureSelection in the ConfigurationInstance if (featureIdentifier != null) { matchingFeatureSelection = configInstance.GetFeatureSelectionByFeatureIdentifier(featureIdentifier); } else if (isRootFeatureSelector) { matchingFeatureSelection = configInstance.RootFeatureSelection; } // return(matchingFeatureSelection); }
public override object VisitComposite_selector_advanced([NotNull] GrammarParser.Composite_selector_advancedContext context) { // 1. Visit the children (Feature_selector_abs, Feature_selector_rel and Attribute_selector) FeatureSelection absFeatureSelection = (FeatureSelection)Visit(context.feature_selector_abs()); // 2. Get the matching relative FeatureSelections var relativeSelectorType = (int)Visit(context.feature_selector_rel()); List <FeatureSelection> relativeMatchingFeatureSelections = null; if (relativeSelectorType == GrammarParser.DESCENDANTS_KEYWORD) { relativeMatchingFeatureSelections = configInstance .GetDescendantFeatureSelections(absFeatureSelection) .Where(featureSel => featureSel.SelectionState == Core.BLOs.FeatureSelectionStates.Selected) .ToList(); } else { throw new Exception("Only >descendants supported by the relative feature selector"); } // 3. Get the matching AttributeValues for all of the relative FeatureSelections string attributeIdentifier = (string)Visit(context.attribute_selector()); List <AttributeValue> matchingAttributeValues = new List <AttributeValue>(); relativeMatchingFeatureSelections.ForEach(featureSelection => { AttributeValue attrVal = featureSelection.AttributeValues.FirstOrDefault(attributeVal => attributeVal.AttributeIdentifier == attributeIdentifier); if (attrVal != null) { matchingAttributeValues.Add(attrVal); } }); return(matchingAttributeValues); }
private static void generateTree(DTreeNode currentNode) { FeatureSelection featureSelection = new FeatureSelection(); DTreeNode splitNode = featureSelection.GetSplitingFeature(currentNode); if (splitNode == null) { return; } currentNode.entropy = splitNode.entropy; if (currentNode.entropy == 0.0) { currentNode.className = splitNode.className; currentNode.isLeaf = true; return; } currentNode.spliteFeatureName = splitNode.spliteFeatureName; currentNode.informationGain = splitNode.informationGain; foreach (DTreeNode child in splitNode.childrenNodes) { DTreeNode childNode = new DTreeNode(); childNode.spliteFeatureValue = child.spliteFeatureValue; List <FeatureDataPair> featureValuePairs = currentNode.previousFeatureValues.ToList(); featureValuePairs.Add(new FeatureDataPair(currentNode.spliteFeatureName, childNode.spliteFeatureValue)); childNode.previousFeatureValues = featureValuePairs; childNode.depth = currentNode.depth + 1; currentNode.childrenNodes.Add(childNode); generateTree(childNode); } }