gradient.descent: Gradient descent method to find the coefficients of linear...

Description Usage Arguments Value Examples

View source: R/StatCompR.R

Description

Gradient descent method to find the coefficients of linear regression equation

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
gradient.descent(
  x,
  y,
  epsilon = 1e-14,
  maxit = 1000,
  stepsize = 0.001,
  alpha = 0.25,
  b = 0.8,
  stepmethod = "backtracking",
  verbose = TRUE,
  plotLoss = TRUE
)

Arguments

x

a m*n data matrix

y

observations size of m*1

epsilon

termination condition, difference between the coefs of two consecutive iters

maxit

the maximum number of iterations, default is 1000

stepsize

just stepsize, must smaller than 1e-3, default is 1e-3

alpha

parameter in the backtracking method, should in (0,0.5), default is 0.25

b

parameter in the backtracking method, should in (0,1), default is 0.8

stepmethod

optional "backtracking" or "fixed", default is "backtracking"

verbose

whether to print out iterations, default is "TRUE"

plotLoss

whether to plot loss, default is "TRUE"

Value

a list contains coefficients,RSE and number of iterations

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
n=100
x1<-rnorm(n)
x2<-rnorm(n)
y=1+0.5*x1+x2+rnorm(n,sd=0.1)
x<-cbind(x1,x2)
gradient.descent(x,y)

## End(Not run)

Lrrzz/StatComp21064 documentation built on Dec. 23, 2021, 10:21 p.m.