
Trained patch convolutional autoencoder (Geron Ch 18, morie.fn hmcae)
Source:R/geron_ml2_native.R
morie_geron_conv_autoencoder_trained.RdSplits every image into non-overlapping p x p patches (row-major over patch rows then patch columns, each patch flattened row-major), normalises by the RMS pixel value, and trains a linear encoder/decoder pair by gradient descent on the reconstruction MSE. Weights come from one continuing LCG stream: W_enc (p^2 x F) then V_dec (F x p^2), both reshaped row-major.
Usage
morie_geron_conv_autoencoder_trained(
X,
filters = 2,
epochs = 100,
lr = 0.05,
seed = 0,
patch = 2
)Value
List with loss_history, final_loss, encoder, decoder,
codes (list of images, each a list of F patch-grid matrices),
code_shape, reconstruction (list of images),
compression_ratio, n_patches, patch, grcae_check,
estimate, n.
Details
A bottleneck narrower than the patch cannot reach zero loss; the
residual IS the compression cost, which the parity test checks by
comparing compression_ratio against final_loss.
grcae_check re-runs the single forward pass of
morie_geron_convolutional_autoencoder on the first image, exactly
as the Python module cross-checks itself against grcae.
Examples
Q <- matrix(c(0, 1, 2, -1), nrow = 2, byrow = TRUE)
morie_geron_q_learning(Q, 0, 1, 0.5, 1, 0.5, 0.9)
#> $Q
#> [,1] [,2]
#> [1,] 0 1.65
#> [2,] 2 -1.00
#>
#> $td_error
#> [1] 1.3
#>
#> $target
#> [1] 2.3
#>
#> $old_value
#> [1] 1
#>
#> $new_value
#> [1] 1.65
#>
#> $max_next
#> [1] 2
#>
#> $estimate
#> [1] 1.65
#>
#> $n
#> [1] 4
#>
#> $method
#> [1] "Tabular Q-learning update (off-policy TD control)"
#>
morie_geron_conv_autoencoder_trained(X = Q)
#> $loss_history
#> [1] 1.737157e+00 1.433048e+00 1.270556e+00 1.175097e+00 1.112104e+00
#> [6] 1.064618e+00 1.024153e+00 9.864557e-01 9.494235e-01 9.120507e-01
#> [11] 8.738998e-01 8.348342e-01 7.948841e-01 7.541788e-01 7.129103e-01
#> [16] 6.713129e-01 6.296495e-01 5.882001e-01 5.472517e-01 5.070886e-01
#> [21] 4.679828e-01 4.301853e-01 3.939188e-01 3.593712e-01 3.266918e-01
#> [26] 2.959891e-01 2.673305e-01 2.407444e-01 2.162232e-01 1.937278e-01
#> [31] 1.731928e-01 1.545318e-01 1.376428e-01 1.224133e-01 1.087248e-01
#> [36] 9.645642e-02 8.548835e-02 7.570397e-02 6.699184e-02 5.924684e-02
#> [41] 5.237095e-02 4.627366e-02 4.087203e-02 3.609056e-02 3.186090e-02
#> [46] 2.812145e-02 2.481693e-02 2.189787e-02 1.932010e-02 1.704431e-02
#> [51] 1.503554e-02 1.326276e-02 1.169847e-02 1.031829e-02 9.100677e-03
#> [56] 8.026556e-03 7.079072e-03 6.243336e-03 5.506197e-03 4.856042e-03
#> [61] 4.282622e-03 3.776890e-03 3.330863e-03 2.937497e-03 2.590578e-03
#> [66] 2.284625e-03 2.014802e-03 1.776843e-03 1.566987e-03 1.381914e-03
#> [71] 1.218700e-03 1.074761e-03 9.478227e-04 8.358765e-04 7.371520e-04
#> [76] 6.500876e-04 5.733063e-04 5.055935e-04 4.458782e-04 3.932158e-04
#> [81] 3.467734e-04 3.058162e-04 2.696965e-04 2.378428e-04 2.097514e-04
#> [86] 1.849778e-04 1.631303e-04 1.438631e-04 1.268715e-04 1.118869e-04
#> [91] 9.867200e-05 8.701795e-05 7.674034e-05 6.767661e-05 5.968340e-05
#> [96] 5.263425e-05 4.641768e-05 4.093533e-05 3.610050e-05 3.183671e-05
#>
#> $final_loss
#> [1] 2.807651e-05
#>
#> $encoder
#> [,1] [,2]
#> [1,] -0.4571437 -0.383533365
#> [2,] 0.8003489 0.183840975
#> [3,] 0.2930165 -0.002849286
#> [4,] -0.5175748 0.349461811
#>
#> $decoder
#> [,1] [,2] [,3] [,4]
#> [1,] 0.02498255 0.6035488 0.9412029 -0.5006082
#> [2,] 0.27326881 0.8565508 -1.2347027 0.2170948
#>
#> $codes
#> $codes[[1]]
#> $codes[[1]][[1]]
#> [,1]
#> [1,] 1.903957
#>
#> $codes[[1]][[2]]
#> [,1]
#> [1,] -0.1713194
#>
#>
#>
#> $code_shape
#> [1] 2 1 1
#>
#> $reconstruction
#> $reconstruction[[1]]
#> [,1] [,2]
#> [1,] 0.0007494558 1.002387
#> [2,] 2.0035382068 -0.990329
#>
#>
#> $compression_ratio
#> [1] 2
#>
#> $n_patches
#> [1] 1
#>
#> $patch
#> [1] 2
#>
#> $grcae_check
#> $grcae_check$loss
#> [1] 6
#>
#> $grcae_check$code_shape
#> [1] 1 1
#>
#>
#> $estimate
#> [1] 2.807651e-05
#>
#> $n
#> [1] 1
#>
#> $method
#> [1] "stride-p convolutional autoencoder trained by gradient descent on reconstruction MSE"
#>