Exemple #1
0
        public static GWGraph <TrainingInputNodeData, TrainingInputEdgeData, TrainingInputGraphData> ExampleData()
        {
            var rdm   = new Random();
            var graph = GWGraphpackageOne.GWString <TrainingInputNodeData, TrainingInputEdgeData, TrainingInputGraphData>(6);

            graph.Data = new TrainingInputGraphData();
            graph.Data.ObservationToCRFScoreProbability = new double[5, 5];
            for (int i = 0; i < 5; i++)
            {
                for (int k = 0; k < 5; k++)
                {
                    graph.Data.ObservationToCRFScoreProbability[i, k] = rdm.NextDouble();
                }
            }

            foreach (var node in graph.Nodes)
            {
                node.Data             = new TrainingInputNodeData();
                node.Data.Observation = rdm.Next(5);
            }
            foreach (var edge in graph.Edges)
            {
                edge.Data = new TrainingInputEdgeData();
            }

            return(graph);
        }
Exemple #2
0
        public GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> CreateTestGraphCRF()
        {
            var graph = GWGraphpackageOne.ThreeCoreElements <CRFNodeData, CRFEdgeData, CRFGraphData>(32);

            graph.Data = new CRFGraphData();
            foreach (var node in graph.Nodes)
            {
                node.Data = new CRFNodeData();
            }
            foreach (var edge in graph.Edges)
            {
                edge.Data = new CRFEdgeData();
            }

            var NumberOfSeedsForPatchCreation = 2;
            var MaximumTotalPatchSize         = 12;
            var seedingMethodPatchCreation    = new SeedingMethodPatchCreation(NumberOfSeedsForPatchCreation, MaximumTotalPatchSize);

            seedingMethodPatchCreation.CreatePatchAndSetAsReferenceLabel(graph);


            graph.SaveAsJSON("testgraph.crf");

            return(graph);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            CRFBase.Build.Do();

            // als Referenz folgende Klasse:
            //var oldWorkFlow = new WorkflowPede();

            //WorkflowPede.Start(null);

            { // example Gradient Descent
              //var request = new ExecuteGradientDescent();


                //request.Request();

                //Console.Write(request.Result);
            }

            { // example viterbi
                var graph = GWGraphpackageOne.GWString <CRFNodeData, CRFEdgeData, CRFGraphData>(12);
                foreach (var node in graph.Nodes)
                {
                    node.Data        = new CRFNodeData();
                    node.Data.Scores = new double[] { 1, 2 };
                }
                foreach (var edge in graph.Edges)
                {
                    edge.Data        = new CRFEdgeData();
                    edge.Data.Scores = new double[, ] {
                        { -11, 1 }, { 2, -22 }
                    };
                }
                var request = new SolveInference(graph, 2, 100);
                request.Request();

                foreach (var entry in request.Solution.Labeling)
                {
                    Console.Write(entry);
                    Console.ReadKey();
                }
            }
        }
        public static void Do(int graphSizes)
        {
            //new FileLogger("GraphAnalysis(" + graphSizes + ").txt");

            var graphs = GWGraphpackageOne.DefaultPackage <object, object, object>(graphSizes);

            foreach (var graph in graphs)
            {
                var request = new GraphAnalyse(graph);
                request.RequestInDefaultContext();

                using (var writer = new StreamWriter(graph.Name + "-data.txt"))
                {
                    writer.WriteLine("AnalysisResult: " + graph.Name);

                    writer.Write(writer.NewLine);
                    writer.WriteLine("Nodes: " + graph.Nodes.Count);
                    writer.WriteLine("Edges: " + graph.Edges.Count);
                    writer.WriteLine("Diameter: " + request.Result.ShortestPaths.Max(l => l.NotNullOrEmpty() ? l.Max() : 0.0));
                    writer.WriteLine("Average MaxShortestPath: " + request.Result.ShortestPaths.Average(l => l.NotNullOrEmpty() ? l.Max() : 0.0));
                    writer.WriteLine("Average ClusterCoefficient: " + request.Result.ClusterCoefficients.Average());

                    writer.Write(writer.NewLine);
                    writer.WriteLine("ConnectionProbability By Distance: ");
                    for (int i1 = 0; i1 < request.Result.ConProbByDistance.Length; i1++)
                    {
                        writer.Write("[" + i1 + "]" + ":");
                        for (int i2 = 0; i2 < request.Result.ConProbByDistance[i1].Length; i2++)
                        {
                            writer.Write(" " + Math.Round(request.Result.ConProbByDistance[i1][i2], 2) + ",");
                        }
                        writer.WriteLine();
                    }

                    writer.Write(writer.NewLine);
                    writer.WriteLine("CluserCoefficients: ");
                    for (int i1 = 0; i1 < request.Result.ClusterCoefficients.Length; i1++)
                    {
                        writer.WriteLine("[" + i1 + "]" + ": " + request.Result.ClusterCoefficients[i1]);
                    }

                    writer.Write(writer.NewLine);
                    writer.WriteLine("ShortestPaths (Max, Average): ");
                    for (int i1 = 0; i1 < request.Result.ShortestPaths.Length; i1++)
                    {
                        writer.WriteLine("[" + i1 + "]" + ": (" + request.Result.ShortestPaths[i1].Max() + ", " + request.Result.ShortestPaths[i1].Average() + ")");
                    }

                    //writer.WriteLine("ShortestPaths: ");
                    //for (int i1 = 0; i1 < request.Result.ShortestPaths.GetLength(0); i1++)
                    //{
                    //    for (int i2 = 0; i2 < request.Result.ShortestPaths.GetLength(1); i2++)
                    //    {
                    //        writer.WriteLine("[" + i1 + "," + i2 + "]" + ": " + request.Result.ShortestPaths[i1, i2]);
                    //    }
                    //}
                    //writer.Flush();
                    //writer.WriteLine("AveragePaths: ");
                    //for (int i1 = 0; i1 < request.Result.AveragePaths.GetLength(0); i1++)
                    //{
                    //    for (int i2 = 0; i2 < request.Result.AveragePaths.GetLength(1); i2++)
                    //    {
                    //        writer.WriteLine("[" + i1 + "," + i2 + "]" + ": " + request.Result.AveragePaths[i1, i2]);
                    //    }
                    //}
                }
            }
        }