예제 #1
0
        private static void startTrainingCycle()
        {
            // erzeugt die RequestListener
            Build.Do();
            CRFBase.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);
        }