示例#1
0
        static void BatchGradientDescent()
        {
            string dataDirectory = "C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\HW4-q1\\";

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

            using (System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\output\\BGD.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 gd.Iterate())
                {
                    file.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(2), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));
                    Console.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(2), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));
                }
            }
        }
示例#2
0
        static void BatchGradientDescent()
        {
            string dataDirectory = "C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\HW4-q1\\";

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

            using (System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Dropbox\\Private\\Stanford\\CS246\\Homeworks\\HW4\\Q1\\output\\BGD.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 gd.Iterate())
                {
                    file.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(2), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));
                    Console.WriteLine("{0}\t{1}\t{2}", result.Item1.ToString().PadLeft(2), result.Item2.ToString().PadRight(16), FormatSeconds(result.Item3.TotalSeconds));
                }
            }
        }