/// <summary>
 /// Computes the total error of the solution with parameters theta.
 /// </summary>
 /// <param name="X">Training data</param>
 /// <param name="y">Target variable</param>
 /// <param name="theta">Model parameters</param>
 /// <param name="lambda">Regularization weight</param
 /// <returns>Solution error</returns>
 private double ComputeError(InsightMatrix X, InsightVector y, InsightVector theta, double lambda)
 {
     var first = y.Multiply(Sigmoid((X * theta.ToColumnMatrix()).Column(0)).Log());
     var second = (1 - y).Multiply(1 - Sigmoid((X * theta.ToColumnMatrix()).Column(0)).Log());
     var thetaSub = theta.SubVector(1, theta.Count - 1);
     var reg = (lambda / 2 * X.RowCount) * thetaSub.Power(2).Sum();
     return (first - second).Sum() / X.RowCount + reg;
 }