Ejemplo n.º 1
0
        static Dictionary<float, float> TestGroupAll(Trained[,] trained, RefineGroupByPct refinedGroupByPct, List<TrainingData> testData)
        {
            Dictionary<float, float> result = new Dictionary<float, float>();
            foreach (var f in refinedGroupByPct.dict.Keys)
            {
                Console.WriteLine("Testing " + f);
                var n = TestGroup(trained, refinedGroupByPct.dict[f], testData);
                result[n.benefit] = n.cost;
            }

            using (TextWriter tw = new StreamWriter("results.csv"))
            {
                foreach (var n in result)
                {
                    tw.WriteLine($"{n.Key},{n.Value}");
                }
            }

            return result;
        }
Ejemplo n.º 2
0
        static RefineGroupByPct RefineGroupsAll(Trained[,] trained, List<TrainingData> refineData)
        {
            RefineGroupByPct results = new RefineGroupByPct();

            if (Program.debugState >= 2)
            {
                RefineGroup result = null;
                using (TextReader tr = new StreamReader("refined.csv"))
                {
                    string line;
                    while (null != (line = tr.ReadLine()))
                    {
                        string[] parts = line.Split(',');
                        if (parts.Length == 1 && float.TryParse(parts[0], out float f))
                        {
                            result = new RefineGroup();
                            for (int i = 0; i< TrainingData.Levels; i++)
                            {
                                result.group[i] = new float[TrainingData.Levels];
                            }
                            results.dict[f] = result;
                        }
                        else
                        {
                            int have = int.Parse(parts[0]);
                            for (int i = 1; i < parts.Length; i++)
                            {
                                float n = float.Parse(parts[i]);
                                result.group[have][i - 1] = n;
                            }
                        }
                    }
                }

                return results;
            }
            else
            {

                for (float f = .999F; f >= .99; f -= 1.001F)
                {
                    results.dict[f] = RefineGroup(trained, refineData, f);
                }

                for (float f = .99F; f >= .90; f -= 1.01F)
                {
                    results.dict[f] = RefineGroup(trained, refineData, f);
                }

                for (float f = .90F; f >= .0; f -= 1.1F)
                {
                    results.dict[f] = RefineGroup(trained, refineData, f);
                }

                using (TextWriter tw = new StreamWriter("refined.csv"))
                {
                    foreach (var f in results.dict.Keys)
                    {
                        tw.WriteLine($"{f}");
                        var result = results.dict[f];
                        for (int have = 0; have < TrainingData.Levels; have++)
                        {
                            tw.Write($"{have}");
                            var r = result.group[have];
                            foreach (var n in r)
                            {
                                tw.Write($",{n}");
                            }

                            tw.WriteLine();
                        }
                    }
                }

                return results;
            }
        }
Ejemplo n.º 3
0
 static void TrainAndEvaluate(List<TrainingData> trainData, List<TrainingData> refineData, List<TrainingData> testData)
 {
     Trained[,] trained = TrainGroups(trainData);
     RefineGroupByPct refinedGroupByPct = RefineGroupsAll(trained, refineData);
     TestGroupAll(trained, refinedGroupByPct, testData);
 }