/// <summary> /// Uses gradient descent to calculate the "theta" vector. /// On each iteration gets calculated as per /// /// theta = theta - (alpha/m)*(X*theta - Y)'*X /// /// </summary> private void GradientDescent(Input input) { var monitor = new CostFunctionMonitor(input); _theta = new DenseMatrix(1, input.FeaturesCount); var multiplier = (Settings.LearningRate / input.SamplesCount); for (int i = 0; i < Settings.MaxIterations; i++) { _theta -= multiplier * ((input.X * _theta.Transpose() - input.Y).Transpose() * input.X); if (monitor.IsConverged(_theta)) { break; } } }