Example #1
0
        private static void StartSCProblem()
        {
            var bestClassifiers = new Individual[8];

            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
            ECActivator.AddSourceAssemblies(new[] { Assembly.GetAssembly(typeof(IEvolutionState)), Assembly.GetAssembly(typeof(MultiClassifierProblem)) });
            var             parameters    = Evolve.LoadParameterDatabase(new[] { "-file", @"Params\App\Iris\single.params" });
            IEvolutionState state         = Evolve.Initialize(parameters, 0);
            var             date          = DateTime.Now.Ticks.ToString();
            var             directoryName = "stats/" + date;
            var             directory     = System.IO.Directory.CreateDirectory(directoryName);
            var             writer        = new System.IO.StreamWriter(directoryName + "/multi_cl_stats.txt", false);

            //  IEvolutionState state = Evolve.Initialize(Evolve.LoadParameterDatabase(new[] { "-file", @"Params\App\Iris\single.params" }), 0);

            for (var i = 0; i < 8; i++)
            {
                // parameters = Evolve.LoadParameterDatabase(new[] { "-file", @"Params\App\Iris\single.params", "-stat.file", @"out1.stat" });
                if (i != 0)
                {
                    state = Evolve.Initialize(parameters, 0);
                }
                MultiClassificationClass.Current = MultiClassificationClass.Labels[i];
                // state.Output.FilePrefix = i.ToString();
                state.Run(EvolutionState.C_STARTED_FRESH);
                var best = ((SimpleStatistics)((SimpleEvolutionState)state).Statistics).BestOfRun[0];

                int humanGraph = state.Output.AddLog(directoryName + "/multi_cl_human_graph_" + MultiClassificationClass.Current + ".txt");
                int ecjGraph   = state.Output.AddLog(directoryName + "/multi_cl_ecj_graph_" + MultiClassificationClass.Current + ".txt");
                ((GPIndividual)best).Trees[0].PrintStyle = GPTree.PRINT_STYLE_DOT;
                ((GPIndividual)best).Trees[0].PrintTreeForHumans(state, humanGraph);
                ((GPIndividual)best).Trees[0].PrintTree(state, ecjGraph);

                state.Output.Close();
                // System.IO.File.Delete("out.stat");
                bestClassifiers[i] = best;

                var writer2 = new System.IO.StreamWriter(directoryName + "/classifier_code_" + MultiClassificationClass.Current + ".txt");
                var code    = TreeReader.PrintCodeFromTree(((GPIndividual)best).Trees[0]);
                writer2.Write(code);
                writer2.Close();

                var accuracy = (double)(1552 - ((KozaFitness)bestClassifiers[i].Fitness).StandardizedFitness) / 1552;
                writer.WriteLine("Klasyfikator dla gestu " + MultiClassificationClass.Labels[i]);
                writer.WriteLine("Ilość generacji: " + state.NumGenerations.ToString());
                writer.WriteLine("Rozmiar drzewa: " + ((GPIndividual)bestClassifiers[i]).Size.ToString());
                writer.WriteLine("Poprawność klasyfikacji: " + accuracy.ToString());
                writer.WriteLine();
                //    ((GPIndividual)bestClassifiers[0]).Trees[0].Child.Eval
                //((GPIndividual)bestClassifiers[0]).Trees[0].
                //  ((SingleClassifierProblem)state.Evaluator.p_problem)
            }

            writer.Close();

            CheckClassifierOnTestData(bestClassifiers, state, (int)ClassifierType.MULTI_CLASSIFIER, directoryName);
        }
Example #2
0
        private static void StartGP()
        {
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
            var test = new DataLoader(@"Datasets\gesty_pogrupowane.txt", 11, 1491, 1, 2, '\t');

            ECActivator.AddSourceAssemblies(new[] { Assembly.GetAssembly(typeof(IEvolutionState)), Assembly.GetAssembly(typeof(ClassificationProblem)) });
            IEvolutionState state = Evolve.Initialize(Evolve.LoadParameterDatabase(new[] { "-file", @"Params\App\Iris\koza.params" }), 2);

            state.Run(EvolutionState.C_STARTED_FRESH);
            var best          = ((SimpleStatistics)((SimpleEvolutionState)state).Statistics).BestOfRun[0];
            var date          = DateTime.Now.Ticks.ToString();
            var directoryName = "stats/" + date;
            var directory     = System.IO.Directory.CreateDirectory(directoryName);
            var stats         = new List <string>();

            stats.Add("Ilość pokoleń: " + state.NumGenerations);
            var accuracy = (double)(1552 - ((KozaFitness)best.Fitness).StandardizedFitness) / 1552;

            stats.Add("Rozmiar drzewa: " + ((GPIndividual)best).Size.ToString());
            stats.Add("Głębokość drzewa: " + ((GPIndividual)best).Trees[0].Child.Depth.ToString());
            stats.Add("Poprawność klasyfikacji dla danych uczących: " + accuracy.ToString());

            System.IO.File.WriteAllLines(directoryName + "/single_cl_stats.txt", stats.ToArray());

            var writer = new System.IO.StreamWriter(directoryName + "/classifier_code.txt");
            var code   = TreeReader.PrintCodeFromTree(((GPIndividual)best).Trees[0]);

            writer.Write(code);
            writer.Close();

            int humanGraph = state.Output.AddLog(directoryName + "/single_cl_human_graph.txt");
            int ecjGraph   = state.Output.AddLog(directoryName + "/single_cl_ecj_graph.txt");

            ((GPIndividual)best).Trees[0].PrintStyle = GPTree.PRINT_STYLE_DOT;
            ((GPIndividual)best).Trees[0].PrintTreeForHumans(state, humanGraph);
            ((GPIndividual)best).Trees[0].PrintTree(state, ecjGraph);

            CheckClassifierOnTestData(new[] { best }, state, (int)ClassifierType.SINGLE_CLASSIFIER, directoryName);
            //var data = new ClassificationData();

            /*
             * state.Output.AddLog(@"F:\Logs\test.gv");
             * ((GPIndividual)best[0]).Trees[0].PrintStyle = GPTree.PRINT_STYLE_DOT;
             * ((GPIndividual)best[0]).Trees[0].PrintTreeForHumans(state, state.Output.NumLogs - 1);
             * ((GPIndividual)best[0]).Trees[0].PrintTree(state, state.Output.NumLogs - 1);
             */
        }
Example #3
0
        private static void TestCode()
        {
            ECActivator.AddSourceAssemblies(new[] { Assembly.GetAssembly(typeof(IEvolutionState)), Assembly.GetAssembly(typeof(ClassificationProblem)) });
            var             parameters = Evolve.LoadParameterDatabase(new[] { "-file", @"Params\App\Iris\koza.params" });
            IEvolutionState state      = Evolve.Initialize(parameters, 0);

            state.Setup(state, new Parameter(new string[] { "a" }));
            //state.Run(EvolutionState.C_STARTED_FRESH);
            //   var individual = (GPIndividual)((SimpleStatistics)state.Statistics).BestOfRun[0];
            var tree   = new GPTree();
            var reader = new System.IO.StreamReader("single_cl_ecj_graph.txt");

            tree.ReadTree(state, reader);
            var writer = new System.IO.StreamWriter("testcode.txt");
            var code   = TreeReader.PrintCodeFromTree(tree);

            writer.Write(code);
            writer.Close();
        }