Exemplo n.º 1
0
        //this function can be called by train(), cv(), & richEdge.train()
        public static double basicTrain(dataSet XTest, toolbox tb)
        {
            Global.reinitGlobal();
            double score = 0;

            if (Global.modelOptimizer.EndsWith("bfgs"))
            {
                Global.tb = tb;
                Global.XX = XTest;

                tb.train();
                score = Global.scoreListList[Global.scoreListList.Count - 1][0];
            }
            else
            {
                for (int i = 0; i < Global.ttlIter; i++)
                {
                    Global.glbIter++;
                    Stopwatch timer = new Stopwatch();
                    timer.Start();

                    double err = tb.train();

                    timer.Stop();
                    double time = timer.ElapsedMilliseconds / 1000.0;

                    Global.timeList.Add(time);
                    Global.errList.Add(err);
                    Global.diffList.Add(Global.diff);

                    List <double> scoreList = tb.test(XTest, i);
                    score = scoreList[0];
                    Global.scoreListList.Add(scoreList);

                    Global.swLog.WriteLine("iter{0}  diff={1}  train-time(sec)={2}  {3}={4}%", Global.glbIter, Global.diff.ToString("e2"), time.ToString("f2"), Global.metric, score.ToString("f2"));
                    Global.swLog.WriteLine("------------------------------------------------");
                    Global.swLog.Flush();
                    Console.WriteLine("iter{0}  diff={1}  train-time(sec)={2}  {3}={4}%", Global.glbIter, Global.diff.ToString("e2"), time.ToString("f2"), Global.metric, score.ToString("f2"));

                    //if (Global.diff < Global.convergeTol)
                    //break;
                }
            }
            return(score);
        }