theta := theta - lr * (2/n) X' (X theta - y), intercept included.
Validates against stats::lm reference.
Usage
morie_gradient_descent_vanilla(x, y, lr = 0.01, n_iter = 1000, tol = 1e-08)
Arguments
- x
Numeric matrix / vector of predictors.
- y
Numeric response vector.
- lr
Learning rate.
- n_iter
Max iterations.
- tol
L2 step-norm tolerance for early stopping.
Value
Named list with estimate, reference_ols,
n_iter, loss, n, method.
Examples
morie_gradient_descent_vanilla(x = rnorm(50), y = rnorm(50))
#> $estimate
#> [1] 0.3025064 0.4220374
#>
#> $reference_ols
#> [1] 0.3025068 0.4220378
#>
#> $n_iter
#> [1] 752
#>
#> $loss
#> [1] 1.091902
#>
#> $n
#> [1] 50
#>
#> $method
#> [1] "Vanilla batch gradient descent (linear regression)"
#>