示例#1
0
        private static void StartTrainingCycle()
        {
            // erzeugt die RequestListener
            CRFToolApp.Build.Do();
            CRFBase.Build.Do();
            CRFGraphVis.Build.Do();

            // starting of TrainingCycle:
            var trainingCycle = new TrainingEvaluationCycleZellner();
            var parameters    = new TrainingEvaluationCycleInputParameters();

            // take OLM variants we want to test
            List <OLMVariant> variants = new List <OLMVariant>
            {
                //OLMVariant.Ising
                //OLMVariant.IsingII
                OLMVariant.IsingIII
                //OLMVariant.Default
            };

            Log.Post("Training variant: " + variants[0]);

            // setting of transition probabilities to create observation from reference labeling
            double[,] transition = SetTransitionProbabilities();

            #region modify graphs
            // do this for all graphs (currently saved in form of pdbfiles)
            List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> > crfGraphList = new List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >();
            var id = 0;

            foreach (String file in File.ReadLines(fileNames))
            {
                RandomlySelectedPDBFile     = fileFolder + "/" + file;
                RandomlySelectedPDBFileName = file.Substring(0, 4);

                var pdbFile = PDBExt.Parse(RandomlySelectedPDBFile);
                pdbFile.Name = RandomlySelectedPDBFileName;

                // set IsCore nodes, cuz we only need the interface nodes (the core nodes cannot interact)
                var proteinGraph = SetIsCore(pdbFile);

                // trim graph -> remove isCore nodes
                var trimmedGraph = TrimGraph(pdbFile, proteinGraph);

                // set real reference label of the graph
                var crfGraph = SetReferenceLabel(trimmedGraph);
                SetEdgeMaxDiffValues(crfGraph);
                crfGraph.Id = id++;
                crfGraphList.Add(crfGraph);
            }
            #endregion

            // set parameters for the training cycle
            parameters = new TrainingEvaluationCycleInputParameters(crfGraphList, crfGraphList.Count, variants, IsingConformityParameter,
                                                                    PottsConformityParameters, IsingCorrelationParameter, PottsCorrelationParameters, NumberOfIntervals,
                                                                    transition, NumberOfLabels, BufferSizeViterbi, amplifierControlParameter, Threshold);

            // running the cycle
            trainingCycle.RunCycle(parameters);
        }
示例#2
0
        private static void startTestCycle()
        {
            // erzeugt die RequestListener
            Build.Do();

            // einfache Graphen erzeugen (12 clone)
            //var graph = CreateGraphs.createGraph_Grid2D();
            var pdbFile      = PDBExt.Parse(RandomlySelectedPDBFile);
            var proteinGraph = CreateProteinGraph.Do(pdbFile, 6.0, ResidueNodeCenterDefinition.CAlpha).Values.First();
            IGWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> crfGraph = proteinGraph.Convert(nd => new CRFNodeData(nd.Data.Residue.Id), ed => new CRFEdgeData(), gd => new CRFGraphData());

            // seeding

            // 12 clone erzeugen
            var clone = new GWGraph <ICRFNodeData, ICRFEdgeData, ICRFGraphData> [clones];

            for (int i = 0; i < clones; i++)
            {
                var cloneGraph = crfGraph.Clone(ConvertData.convertNodeData, ConvertData.convertEdgeData, ConvertData.convertGraphData);

                // für jeden graphen (clone): Erzeugung eines Labelings (rdm) => als int[]
                Labeling.randomLabeling(cloneGraph);
                Labeling.assignedLabeling(cloneGraph);

                clone[i] = cloneGraph;
            }

            // calculation of tp, fp, tn, fn, sensitivity, specificity, mcc
            double[][] keysForAllClones = new double[clones][];
            for (int i = 0; i < clones; i++)
            {
                double[] keys = Compute.computeKeys(crfGraph, clone, i);
                keysForAllClones[i] = keys;
            }

            // test
            //outputKeys(keysForAllClones);
            outputLabelingsScores(clone);
        }
示例#3
0
        private static void startTrainingCycle()
        {
            // erzeugt die RequestListener
            Build.Do();

            // calculation of the termination condition for the seeding method
            double[] averageRatioItoS = calculateTerminationConditionForSeeding();

            // starting of TrainingCycle:
            var trainingCycle = new TrainingEvaluationCycle();
            var parameters    = new TrainingEvaluationCycleInputParameters();

            // take OLM variants we want to test, ISING and OLM_III (Default)
            List <OLMVariant> variants = new List <OLMVariant>();

            variants.Add(OLMVariant.Ising);
            variants.Add(OLMVariant.Default);

            // setting of transition probabilities
            //var a = 0.5 + 0.15 * rdm.NextDouble();
            var a = 0.85;
            var b = 0.85;

            double[,] transition = new double[2, 2] {
                { a, 1 - a }, { 1 - b, b }
            };

            #region modify graph
            var pdbFile = PDBExt.Parse(RandomlySelectedPDBFile);
            pdbFile.Name = RandomlySelectedPDBFileName;

            // setzen der IsCore
            var rasaRequest = new RequestRasa(pdbFile);
            rasaRequest.RequestInDefaultContext();

            foreach (var rasa in rasaRequest.Rasavalues)
            {
                rasa.Key.IsCore = rasa.Value <= 0.15;
            }
            var proteinGraph = CreateProteinGraph.Do(pdbFile, 7.0, ResidueNodeCenterDefinition.CAlpha).Values.First();

            // graph trimmen
            var trimmedGraph = trimGraph(pdbFile, proteinGraph);

            // set real reference label of the graph
            var nameWithChain  = RandomlySelectedPDBFile.Substring(fileFolder.Length + 1, 6);
            var interfacesList = new List <string>();
            using (var reader = new StreamReader(InterfaceDefLocation))
            {
                var line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    var nuss = nameWithChain;
                    if (line.StartsWith(nameWithChain))
                    {
                        interfacesList.Add(line.Substring(8));
                    }
                }
            }
            foreach (var interfaceEntry in interfacesList)
            {
                var node = trimmedGraph.Nodes.FirstOrDefault(n => n.Data.Residue.Id.Equals(interfaceEntry));
                if (node != null)
                {
                    node.Data.ReferenceLabel = 1;
                }
            }
            #endregion

            //test
            if (GraphVisualization)
            {
                var graph3D = trimmedGraph.Wrap3D(nd => new Node3DWrap <ResidueNodeData>(nd.Data)
                {
                    ReferenceLabel = nd.Data.ReferenceLabel, X = nd.Data.X, Y = nd.Data.Y, Z = nd.Data.Z
                });
                new ShowGraph3D(graph3D).Request(RequestRunType.Background);
                Thread.Sleep(120000);
            }

            var crfGraph = trimmedGraph.Convert <ResidueNodeData, CRFNodeData, SimpleEdgeData, CRFEdgeData,
                                                 ProteinGraphData, CRFGraphData>(nd => new CRFNodeData(nd.Data.Residue.Id)
            {
                X = nd.Data.X, Y = nd.Data.Y, Z = nd.Data.Z
            }, ed => new CRFEdgeData(),
                                                                                 gd => new CRFGraphData());
            crfGraph.SaveAsJSON("testGraph.txt");

            // setting the MaximumTotalPatchSize based on the ratio calculated with the hermann data
            int min = (int)(crfGraph.NodeCounter * averageRatioItoS[1]);
            int max = (int)(crfGraph.NodeCounter * averageRatioItoS[2]);
            int av  = (int)(crfGraph.NodeCounter * averageRatioItoS[0]);
            int MaximumTotalPatchSize = rdm.Next(min, max);

            // set parameters for the training cycle
            parameters = new TrainingEvaluationCycleInputParameters(crfGraph, NumberOfGraphInstances,
                                                                    NumberOfSeedsForPatchCreation, MaximumTotalPatchSize, variants,
                                                                    IsingConformityParameter, IsingCorrelationParameter, transition, NumberOfLabels, BufferSizeViterbi);
            // running the cycle
            trainingCycle.RunCycle(parameters);
        }
示例#4
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);
        }