Exemplo n.º 1
0
 public static string SaveToTextFile(CombiModel combiModel, string path)
 {
     using (var streamWriter = new StreamWriter(path))
     {
         var algRows = combiModel.AlgorithmRows;
         var i       = 0;
         foreach (var combiRowModel in algRows)
         {
             streamWriter.WriteLine($"Step #{++i}:");
             foreach (var model in combiRowModel.Models)
             {
                 streamWriter.WriteLine(model.ToString());
             }
             streamWriter.WriteLine($"{combiRowModel.BestModel.ToString()} Outer criteria: {combiRowModel.OuterCriteriaValueOfBestModel}");
         }
     }
     return(path);
 }
Exemplo n.º 2
0
        public CombiModel RunAlgorithm(int maxComplexity = 20)
        {
            var models = new List <CombiRowModel>();


            var setsOfModelsByComplexity = GetAllModelsOfIncreasingComplexity(maxComplexity);

            foreach (var modelsSet in setsOfModelsByComplexity)
            {
                var setDataModel = new CombiRowModel();
                var currentComplexityModelsParams = modelsSet.Select(model =>
                {
                    var modelObj = new EquationModel()
                    {
                        Coeficients = model
                    };
                    var paramsForModel           = internalCriteria(_trainingData, _trainingValues, model);
                    var mappedCoefsToModelParams = MapCoeficientsToModel(model, paramsForModel.Item1);
                    modelObj.CoeficientValues    = mappedCoefsToModelParams;
                    modelObj.InnerCriteriaValue  = paramsForModel.Item2;
                    return(modelObj);
                });
                setDataModel.Models = currentComplexityModelsParams.ToList();
                var bestModelForSet =
                    currentComplexityModelsParams.Aggregate(
                        (m1, m2) => m1.InnerCriteriaValue < m2.InnerCriteriaValue ? m1 : m2);
                setDataModel.BestModel = bestModelForSet;
                var externalCriteriaValue = externalCriteriaFunc(bestModelForSet, _checkingValues, _checkingData);
                setDataModel.OuterCriteriaValueOfBestModel = externalCriteriaValue;
                models.Add(setDataModel);
            }
            var bestModel  = GetBestModel(models);
            var combiModel = new CombiModel()
            {
                BestModel     = bestModel,
                AlgorithmRows = models
            };

            return(combiModel);
        }