Пример #1
0
        static void MiniBatchGradientDescent()
        {
            string dataDirectory = "C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\HW4-q1\\";

            GradientDescent gd = new MiniBatchGradientDescent(dataDirectory + "features.txt", dataDirectory + "target.txt");

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            var results = gd.Iterate();
            stopwatch.Stop();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\output\\MBGD.txt"))
            {
                file.WriteLine(" k \t      Cost\t\t   Time\n---\t----------------\t----------");
                Console.WriteLine(" k \t      Cost\t\t   Time\n---\t----------------\t----------");

                foreach (var result in results)
                {
                    file.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(3), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));

                    if (result.Item1 % 10 == results.Count % 10)
                    {
                        Console.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(3), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));
                    }
                }
            }

            Console.WriteLine("\nMini Batch Gradient Descent Complete.\n# of Iterations = " + results.Count + "\nTotal Time = " + stopwatch.Elapsed + "\n");
        }
Пример #2
0
        static void MiniBatchGradientDescent()
        {
            string dataDirectory = "C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\HW4-q1\\";

            GradientDescent gd = new MiniBatchGradientDescent(dataDirectory + "features.txt", dataDirectory + "target.txt");

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var results = gd.Iterate();

            stopwatch.Stop();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\output\\MBGD.txt"))
            {
                file.WriteLine(" k \t      Cost\t\t   Time\n---\t----------------\t----------");
                Console.WriteLine(" k \t      Cost\t\t   Time\n---\t----------------\t----------");

                foreach (var result in results)
                {
                    file.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(3), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));

                    if (result.Item1 % 10 == results.Count % 10)
                    {
                        Console.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(3), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));
                    }
                }
            }

            Console.WriteLine("\nMini Batch Gradient Descent Complete.\n# of Iterations = " + results.Count + "\nTotal Time = " + stopwatch.Elapsed + "\n");
        }