public static double ObjectiveFunction(DiseaseSimulation simulation, List <double> parameters)
        {
            foreach (var value in parameters)
            {
                if (value < 0)
                {
                    return(bigNumber);
                }
            }

            simulation.SetSimulationParameters(parameters);

            return(ObjectiveFunction(simulation));
        }
예제 #2
0
        static void ManualCalibration(ConnectionNetwork diseaseNetwork, DiseaseSimulation simulation)
        {
            var numSimulations = 1;

            var tPop = diseaseNetwork.numberOfPeople;

            string input = "R";

            while (input != "S")
            {
                if (input == "N")
                {
                    Console.WriteLine("Input new parametes separated by spaces: distContProb, K, infProb, hwProb, wwProb");
                    var newParams  = Console.ReadLine();
                    var tokens     = newParams.Split(' ');
                    var parameters = Array.ConvertAll(tokens, double.Parse).ToList();
                    simulation.SetSimulationParameters(parameters);
                }

                if (input == "C")
                {
                    Console.WriteLine("Input new number of simulations: ");
                    var n = Console.ReadLine();
                    numSimulations = Convert.ToInt32(n);
                }

                var results = new double[numSimulations];

                for (int i = 0; i < numSimulations; i++)
                {
                    Console.WriteLine("Running simulation: " + (i + 1));
                    results[i] = ParameterFitting.ObjectiveFunction(simulation);
                }

                Console.WriteLine("Objective values: " + results.Average());

                Console.WriteLine("Run another simulation (R), input new parameters (N), change number of simulations (C) or stop (S)");
                input = Console.ReadLine();
            }
        }