private void ParametersetSGB_Click(object sender, RoutedEventArgs e) { var request = new UserDecision(); request.Options = new string[] { "A", "B", "C" }; request.Request(); //CRFToolData.IsingData = new SoftwareGraphIsing(); //var window = new MainView(); //window.Show(); }
public void Execute() { // - Prerequisites: // - Graphstructure // - Training Data // - 2 Node Classifications TrainingData = new List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(); EvaluationData = new List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(); // decision wether user wants to train or load pre-trained data var requestTraining = new UserDecision("Use Training.", "Load Training Result."); requestTraining.Request(); if (requestTraining.Decision == 0) // use training { // -n characteristics for each node { var request = new UserInput(UserInputLookFor.Folder); request.DefaultPath = "..\\..\\CRFToolApp\\bin\\Graphs"; request.TextForUser = "******"; request.Request(); GraphDataFolder = request.UserText; foreach (var file in Directory.EnumerateFiles(GraphDataFolder)) { var graph = JSONX.LoadFromJSON <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(file); TrainingData.Add(graph); } } // - Step 1: // - discretize characteristics #region Use Training Pede { // create features CreateFeatures(Dataset, TrainingData); InitCRFScores(TrainingData); var request = new OLMRequest(OLMVariant.Ising, TrainingData); request.BasisMerkmale.AddRange(Dataset.NodeFeatures); request.BasisMerkmale.AddRange(Dataset.EdgeFeatures); request.LossFunctionValidation = OLM.LossRatio; request.Request(); // zugehörige Scores erzeugen für jeden Graphen (auch Evaluation) CreateCRFScores(TrainingData, Dataset.NodeFeatures, request.Result.ResultingWeights); // store trained Weights Dataset.NumberIntervals = NumberIntervals; Dataset.Characteristics = TrainingData.First().Data.Characteristics.ToArray(); Dataset.EdgeCharacteristic = "IsingEdgeCharacteristic"; Dataset.Weights = request.Result.ResultingWeights; Dataset.SaveAsJSON("results.json"); } #endregion } else { // load pre-trained data var request = new UserInput(); request.TextForUser = "******"; request.Request(); var file = request.UserText; var trainingResult = JSONX.LoadFromJSON <WorkflowOneDataset>(file); Dataset = trainingResult; } //- Step2: // User Choice here { var request = new UserInput(UserInputLookFor.Folder); request.TextForUser = "******"; request.Request(); GraphDataFolder = request.UserText; foreach (var file in Directory.EnumerateFiles(GraphDataFolder)) { var graph = JSONX.LoadFromJSON <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(file); EvaluationData.Add(graph); } } // remove double edges { var edgesToRemove = new LinkedList <GWEdge <CRFNodeData, CRFEdgeData, CRFGraphData> >(); foreach (var graph in EvaluationData) { foreach (var edge in graph.Edges.ToList()) { if (graph.Edges.Any(e => (e != edge) && ((e.Foot == edge.Head && e.Head == edge.Foot && e.GWId.CompareTo(edge.GWId) < 0) || (e.Foot == edge.Foot && e.Head == edge.Head && e.GWId.CompareTo(edge.GWId) < 0)))) { edgesToRemove.Add(edge); graph.Edges.Remove(edge); } } } foreach (var edge in edgesToRemove) { edge.Foot.Edges.Remove(edge); edge.Head.Edges.Remove(edge); } } //scores erzeugen CreateCRFScores(EvaluationData, Dataset.NodeFeatures, Dataset.Weights); // - Create ROC Curve { } // - Give Maximum with Viterbi { foreach (var graph in EvaluationData) { var request = new SolveInference(graph, null, 2); request.Request(); graph.Data.AssginedLabeling = request.Solution.Labeling; } //show results in 3D Viewer { //var request = new ShowGraphs(); //request.Graphs = EvaluationData; //request.Request(); } } // - Give Sample with MCMC { foreach (var graph in EvaluationData) { SoftwareGraphLearningParameters parameters = new SoftwareGraphLearningParameters(); parameters.NumberOfGraphs = 60; parameters.NumberNodes = 50; parameters.NumberLabels = 2; parameters.NumberCategories = 4; parameters.IntraConnectivityDegree = 0.15; parameters.InterConnectivityDegree = 0.01; //sample parameters var samplerParameters = new MHSamplerParameters(); var sglGraph = graph.Convert((nodeData) => new SGLNodeData() { }, (edgeData) => new SGLEdgeData(), (graphData) => new SGLGraphData()); samplerParameters.Graph = sglGraph; samplerParameters.NumberChains = 1; //sampler starten var gibbsSampler = new MHSampler(); gibbsSampler.Do(samplerParameters); } } }