コード例 #1
0
ファイル: UserTrainingX.cs プロジェクト: dtklinh/CRFTool
        public static IGWGraph <ITrainingInputNodeData, ITrainingInputEdgeData, ITrainingInputGraphData> ParseTrainingData(string file)
        {
            var graph = JSONX.LoadFromJSON <GWGraph <TrainingInputNodeData, TrainingInputEdgeData, TrainingInputGraphData> >(file);


            return(graph);
        }
コード例 #2
0
        protected override void OnRequest(LoadCRFGraph request)
        {
            var graph = default(IGWGraph <SGLNodeData, SGLEdgeData, SGLGraphData>);

            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "Graph Files|*.crf";
                openFileDialog1.Title  = "Select a CRF graph File";

                if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    graph = JSONX.LoadFromJSON <GWGraph <SGLNodeData, SGLEdgeData, SGLGraphData> >(openFileDialog1.FileName);
                }
            }
            if (graph != null)
            {
                int nodeCounter = 0;
                foreach (var node in graph.Nodes)
                {
                    node.Data.Ordinate = nodeCounter;
                    nodeCounter++;
                }
            }
            request.Graph = graph;
        }
コード例 #3
0
ファイル: InitModel.xaml.cs プロジェクト: dtklinh/CRFTool
        private void LoadParametersetB_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Parameter Files|*.par";
            openFileDialog1.Title  = "Select a Parameter File";

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                CRFToolData.IsingData = JSONX.LoadFromJSON <IsingData>(openFileDialog1.FileName);
            }
        }
コード例 #4
0
        public List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> > LoadCRFGraphs()
        {
            var            list            = new List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Graph Files|*.crfs";
            openFileDialog1.Title  = "Select a CRF graph list File";

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var graphsList = JSONX.LoadFromJSON <List <string> >(openFileDialog1.FileName);
                foreach (var item in graphsList)
                {
                    var graph = JSONX.LoadFromJSON <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(item);
                    list.Add(graph);
                }
            }
            return(list);
        }
コード例 #5
0
        private void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Space:
                if (EmbeddingControl == null)
                {
                    Embed();
                }
                else
                {
                    EmbeddingControl.Stop();
                    EmbeddingControl = null;
                }
                break;

            case Key.Tab:
                ViewModel.ViewType = ViewModel.ViewType.Next();
                break;

            case Key.S:
                viewModel.EvalResult.SaveAsJSON("testFile.txt");
                break;

            case Key.L:
                ViewModel.EvalResults.Add(JSONX.LoadFromJSON <OLMEvaluationResult>("testFile.txt"));
                break;

            case Key.N:
                ViewModel.EvalResPointer++;
                break;

            case Key.P:
                ViewModel.EvalResPointer--;
                break;

            default:
                break;
            }
        }
コード例 #6
0
        public GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> LoadCRFGraph()
        {
            var graph  = default(GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData>);
            var thread = new Thread(
                () =>
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter         = "Graph Files|*.crf";
                openFileDialog1.Title          = "Select a CRF graph File";

                if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    graph = JSONX.LoadFromJSON <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(openFileDialog1.FileName);
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            Data.SelectedGraph = graph;
            return(graph);
        }
コード例 #7
0
ファイル: WorkflowOne.cs プロジェクト: dtklinh/CRFTool
        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);
                }
            }
        }
コード例 #8
0
        private static double[] calculateTerminationConditionForSeeding()
        {
            double[] averageRatioItoS = new double[3];
            if (ComputeTerminationCondition)
            {
                List <double> ratios = new List <double>();

                // Getting the ratio of all surface nodes to the interface nodes
                // to get a reality near parameter when to stop the seeding
                foreach (var file in Directory.GetFiles(fileFolder))
                {
                    var pdbFile = PDBExt.Parse(file);
                    pdbFile.Name = file.Substring(fileFolder.Length + 1, 4);
                    var nameWithChain = file.Substring(fileFolder.Length + 1, 6);

                    // counting all the nodes
                    var rasaRequest = new RequestRasa(pdbFile);
                    rasaRequest.RequestInDefaultContext();

                    // counting all the surface nodes
                    int SurfaceCounter = 0;
                    foreach (var rasa in rasaRequest.Rasavalues)
                    {
                        SurfaceCounter += rasa.Value > 0.15 ? 1 : 0;
                        rasa.Key.IsCore = rasa.Value <= 0.15;
                    }

                    // counting the interface nodes for each file
                    int InterfaceCounter = 0;
                    using (var reader = new StreamReader(InterfaceDefLocation))
                    {
                        var line = "";
                        while ((line = reader.ReadLine()) != null)
                        {
                            var nuss = nameWithChain;
                            InterfaceCounter += line.StartsWith(nameWithChain) ? 1 : 0;
                        }
                    }

                    double ratio = 1.0 * InterfaceCounter / SurfaceCounter;
                    ratios.Add(ratio);
                }

                // calculation of the average ratio between surface and interface nodes
                double ratioSum = 0.0;
                for (int i = 0; i < ratios.Count; i++)
                {
                    ratioSum += ratios[i];
                }
                double max = ratios.Max();
                double min = ratios.Min();
                averageRatioItoS[0] = ratioSum / ratios.Count;
                averageRatioItoS[1] = min;
                averageRatioItoS[2] = max;

                averageRatioItoS.SaveAsJSON("terminationCondition.txt");
            }
            else
            {
                averageRatioItoS = JSONX.LoadFromJSON <double[]>("terminationCondition.txt");
            }

            return(averageRatioItoS);
        }