コード例 #1
0
ファイル: Program.cs プロジェクト: firestrand/SwarmOps
        static void Main(string[] args)
        {
            // Initialize PRNG.
            Globals.Random = new RandomOps.MersenneTwister();

            // Output optimization settings.
            Console.WriteLine("Optimizer: {0}", Optimizer.Name);
            Console.WriteLine("Using following parameters:");
            Tools.PrintParameters(Optimizer, Parameters);
            Console.WriteLine("Number of optimization runs: {0}", NumRuns);
            Console.WriteLine("Problem: {0}", Problem.Name);
            Console.WriteLine("\tDimensionality: {0}", Dim);
            Console.WriteLine("\tNumIterations per run, max: {0}", NumIterations);
            Console.WriteLine();

            // Create a fitness trace for tracing the progress of optimization.
            int NumMeanIntervals = 3000;
            FitnessTrace fitnessTrace = new FitnessTraceMean(NumIterations, NumMeanIntervals);

            // Assign the runcondition to the problem.
            Problem.RunCondition = RunCondition;

            // Assign the fitness trace to the optimizer.
            Optimizer.FitnessTrace = fitnessTrace;

            // Start-time.
            DateTime t1 = DateTime.Now;

            // Perform optimizations.
            double fitness = Repeat.Fitness(Parameters);

            // End-time.
            DateTime t2 = DateTime.Now;

            // Compute result-statistics.
            Statistics.Compute();

            // Output best result, as well as result-statistics.
            Console.WriteLine("Best solution found:");
            Tools.PrintParameters(Problem, Statistics.BestParameters);
            Console.WriteLine();
            Console.WriteLine("Fitness Results:");
            Console.WriteLine("\tBest: \t\t{0}", Tools.FormatNumber(Statistics.FitnessMin));
            Console.WriteLine("\tWorst: \t\t{0}", Tools.FormatNumber(Statistics.FitnessMax));
            Console.WriteLine("\tMean: \t\t{0}", Tools.FormatNumber(Statistics.FitnessMean));
            Console.WriteLine("\tStd.Dev.: \t{0}", Tools.FormatNumber(Statistics.FitnessStdDev));
            Console.WriteLine();
            Console.WriteLine("Iterations used per run:");
            Console.WriteLine("\tMean: {0}", Tools.FormatNumber(Statistics.IterationsMean));

            // Output time-usage.
            Console.WriteLine();
            Console.WriteLine("Time usage: {0}", t2 - t1);

            // Output fitness trace.
            string traceFilename = "FitnessTrace-" + Problem.Name + ".txt";
            fitnessTrace.WriteToFile(traceFilename);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: firestrand/SwarmOps
        static void Main(string[] args)
        {
            // Initialize the PRNG.
            Globals.Random = new RandomOps.MersenneTwister();

            // Create a fitness trace for tracing the progress of optimization.
            int NumMeanIntervals = 3000;
            FitnessTrace fitnessTrace = new FitnessTraceMean(MetaNumIterations, NumMeanIntervals);

            // Assign the fitness trace to the meta-optimizer.
            MetaOptimizer.FitnessTrace = fitnessTrace;

            // Assign the RunCondition to the optimizer.
            Optimizer.RunCondition = RunCondition;

            // Output settings.
            Console.WriteLine("Meta-Optimization of benchmark problems.");
            Console.WriteLine();
            Console.WriteLine("Meta-method: {0}", MetaOptimizer.Name);
            Console.WriteLine("Using following parameters:");
            Tools.PrintParameters(MetaOptimizer, MetaOptimizer.DefaultParameters);
            Console.WriteLine("Number of meta-runs: {0}", MetaNumRuns);
            Console.WriteLine("Number of meta-iterations: {0}", MetaNumIterations);
            Console.WriteLine();
            Console.WriteLine("Method to be meta-optimized: {0}", Optimizer.Name);
            Console.WriteLine("Number of benchmark problems: {0}", Problems.Length);

            for (int i = 0; i < Problems.Length; i++)
            {
                Console.WriteLine("\t{0}", Problems[i].Name);
            }

            Console.WriteLine("Dimensionality for each benchmark problem: {0}", Dim);
            Console.WriteLine("Number of runs per benchmark problem: {0}", NumRuns);
            Console.WriteLine("Number of iterations per run: {0}", NumIterations);
            Console.WriteLine("Displace global optimum: {0}", (DisplaceOptimum) ? ("Yes") : ("No"));
            Console.WriteLine();

            Console.WriteLine("*** Indicates a meta-fitness evaluation is an improvement.");
            Console.WriteLine();

            // Start-time.
            DateTime t1 = DateTime.Now;

            // Perform the meta-optimization runs.
            double fitness = MetaRepeat.Fitness();

            // End-time.
            DateTime t2 = DateTime.Now;

            // Compute result-statistics.
            Statistics.Compute();

            // Retrieve best-found control parameters for the optimizer.
            double[] bestParameters = Statistics.BestResult.Parameters;

            // Output results and statistics.
            Console.WriteLine();
            Console.WriteLine("Best found parameters for {0} optimizer:", Optimizer.Name);
            Tools.PrintParameters(Optimizer, bestParameters);
            Console.WriteLine("Parameters written in array notation:");
            Console.WriteLine("\t{0}", Tools.ArrayToString(bestParameters, 4));
            Console.WriteLine("Best parameters have meta-fitness: {0}", Tools.FormatNumber(Statistics.FitnessMin));
            Console.WriteLine("Worst meta-fitness: {0}", Tools.FormatNumber(Statistics.FitnessMax));
            Console.WriteLine("Mean meta-fitness: {0}", Tools.FormatNumber(Statistics.FitnessMean));
            Console.WriteLine("StdDev for meta-fitness: {0}", Tools.FormatNumber(Statistics.FitnessStdDev));

            // Output best found parameters.
            Console.WriteLine();
            Console.WriteLine("Best {0} found parameters:", LogSolutions.Capacity);
            foreach (Solution candidateSolution in LogSolutions.Log)
            {
                Console.WriteLine("\t{0}\t{1}",
                    Tools.ArrayToStringRaw(candidateSolution.Parameters, 4),
                    Tools.FormatNumber(candidateSolution.Fitness));
            }

            // Output time-usage.
            Console.WriteLine();
            Console.WriteLine("Time usage: {0}", t2 - t1);

            // Output fitness trace.
            string traceFilename = "MetaFitnessTrace-" + MetaOptimizer.Name + "-" + Optimizer.Name + ".txt";
            fitnessTrace.WriteToFile(traceFilename);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: firestrand/SwarmOps
        /// <summary>
        /// Optimize the given problem and output result-statistics.
        /// </summary>
        static void Optimize(Problem problem)
        {
            // Create a fitness trace for tracing the progress of optimization, mean.
            int NumMeanIntervals = 3000;
            FitnessTrace fitnessTraceMean = new FitnessTraceMean(NumIterations, NumMeanIntervals);

            // Create a fitness trace for tracing the progress of optimization, quartiles.
            // Note that fitnessTraceMean is chained to this object by passing it to the
            // constructor, this causes both fitness traces to be used.
            int NumQuartileIntervals = 10;
            FitnessTrace fitnessTraceQuartiles = new FitnessTraceQuartiles(NumRuns, NumIterations, NumQuartileIntervals, fitnessTraceMean);

            // Assign the problem etc. to the optimizer.
            Optimizer.Problem = problem;
            Optimizer.RunCondition = RunCondition;
            Optimizer.FitnessTrace = fitnessTraceQuartiles;

            // Wrap the optimizer in a logger of result-statistics.
            Statistics Statistics = new Statistics(Optimizer);

            // Wrap it again in a repeater.
            Repeat Repeat = new RepeatSum(Statistics, NumRuns);

            // Perform the optimization runs.
            double fitness = Repeat.Fitness(Parameters);

            // Compute result-statistics.
            Statistics.Compute();

            // Output result-statistics.
            Console.WriteLine("{0} & {1} & {2} & {3} & {4} & {5} & {6} & {7} \\\\",
                problem.Name,
                Tools.FormatNumber(Statistics.FitnessMean),
                Tools.FormatNumber(Statistics.FitnessStdDev),
                Tools.FormatNumber(Statistics.FitnessQuartiles.Min),
                Tools.FormatNumber(Statistics.FitnessQuartiles.Q1),
                Tools.FormatNumber(Statistics.FitnessQuartiles.Median),
                Tools.FormatNumber(Statistics.FitnessQuartiles.Q3),
                Tools.FormatNumber(Statistics.FitnessQuartiles.Max));

            // Output fitness trace, mean.
            string traceFilenameMean = Optimizer.Name + "-FitnessTraceMean-" + problem.Name + ".txt";
            fitnessTraceMean.WriteToFile(traceFilenameMean);

            // Output fitness trace, quartiles.
            string traceFilenameQuartiles = Optimizer.Name + "-FitnessTraceQuartiles-" + problem.Name + ".txt";
            fitnessTraceQuartiles.WriteToFile(traceFilenameQuartiles);
        }