static void Main(string[] args) { var normalize = new ValueNormalizer(); var dataTransformer = new DataTransformer(); var dataSupplier = new DataSourceSupplier(); var data = dataSupplier.GetTrainingSet().ToList(); var trainingSet = GetNormalizedData(); var functions = new FunctionsCalculator(trainingSet); var newHouse = new double[] { 1, 1203, 3 }; double predictedPrice = 0.0; var actualPrice = 239500; var theta = new double[] { 89597.9027899082, 504777.895309395, -34952.0620218024 }; for (int i = 1; i <= 2; i++) { var featureVector = dataTransformer.GetNthFeatureVector(data, i).ToArray(); var min = featureVector.Min(); var max = featureVector.Max(); newHouse[i] = normalize.FeatureScaling(min, max, newHouse[i]); } predictedPrice = functions.Hypothesis(newHouse, theta); Console.WriteLine($"Actual price: {actualPrice}"); Console.WriteLine($"Predicted price: {predictedPrice}"); Console.Read(); }
private List <DataPoint> GetPlotData() { string projectPath = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())); string filePath = @"DataSets\theta.txt"; string fullPath = Path.Combine(projectPath, filePath); var trainingSet = this.GetNormalizedData(); var resultList = new List <DataPoint>(); var functionsCalculator = new FunctionsCalculator(trainingSet); var gradientDescentCalculator = new GradientDescentCalculator(trainingSet); double bound = 2043280050.60283; double alpha = 0.1; // todo: replace hardcoded number of values with dynamic initialization var theta = new double[] { 0, 0, 0 }; try { double costFunctionResult = functionsCalculator.CostFuction(theta); int iteration = 1; resultList.Add(new DataPoint(iteration, costFunctionResult)); do { theta = gradientDescentCalculator.Descent(theta, alpha, 3); costFunctionResult = functionsCalculator.CostFuction(theta); iteration++; resultList.Add(new DataPoint(iteration, costFunctionResult)); Console.WriteLine(costFunctionResult); } while (costFunctionResult > bound); File.WriteAllText(fullPath, string.Join(" ", theta)); } catch (Exception e) { Console.WriteLine(e.Message); } return(resultList); }