Skip to contents

Batches from morie_geron_dataloader_minibatch() with a per-epoch seed of seed + epoch, gradient from the shared MSE core.

Usage

morie_geron_minibatch_gradient_descent(X, y, theta, eta, b, n_iter, seed = 0)

Arguments

X, y, theta

Data and starting parameters.

eta

Positive learning rate.

b

Batch size in [1, m].

n_iter

Number of steps.

seed

Base LCG seed.

Value

List with theta, cost_history, theta_history, initial_cost, final_cost.

Examples

X <- matrix(c(1, 2, 1, 3, 1, 5, 1, 7), 4, byrow = TRUE)
y <- c(2, 3, 6, 9)
morie_geron_minibatch_gradient_descent(X, y, c(0, 0), 0.02, 2,
    5, seed = 3)
#> $theta
#> [1] 0.1321851 1.2569443
#> 
#> $cost_history
#> [1] 32.5000000 10.9993000  4.2661237  0.7877623  0.9527690  0.3528633
#> 
#> $theta_history
#> $theta_history[[1]]
#> [1] 0 0
#> 
#> $theta_history[[2]]
#> [1] 0.30 1.86
#> 
#> $theta_history[[3]]
#> [1] 0.2020 1.6064
#> 
#> $theta_history[[4]]
#> [1] 0.108384 1.040448
#> 
#> $theta_history[[5]]
#> [1] 0.1000038 1.0190931
#> 
#> $theta_history[[6]]
#> [1] 0.1321851 1.2569443
#> 
#> 
#> $initial_cost
#> [1] 32.5
#> 
#> $final_cost
#> [1] 0.3528633
#> 
#> $eta
#> [1] 0.02
#> 
#> $batch_size
#> [1] 2
#> 
#> $estimate
#> [1] 0.1321851 1.2569443
#> 
#> $n
#> [1] 4
#>