From 6e904aa4ec9414673277d6eca052a077f23b39eb Mon Sep 17 00:00:00 2001 From: Stefan Lenz Date: Wed, 13 Oct 2021 11:38:31 +0200 Subject: [PATCH] assertinitoptimizers -> assert_initoptimizers. Documentation. --- src/dbmtraining.jl | 24 ++++++++++++++---------- src/rbmtraining.jl | 4 ++-- test/examples.jl | 1 - 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/dbmtraining.jl b/src/dbmtraining.jl index 38ca9e2..e714acf 100644 --- a/src/dbmtraining.jl +++ b/src/dbmtraining.jl @@ -26,19 +26,20 @@ trained using the general Boltzmann Machine learning procedure defaults to `epochs` * `learningrate`: learning rate for pretraining. Also used as initial value for the decaying fine tuning learning rate. -* `learningrates` (deprecated) / `learningratesfinetuning`: - The learning rate for fine tuning is by default decaying with the number of epochs, - starting with the value of the `learningrate`. - (For more details see `traindbm!`.) - The value of the learning rate for each epoch of fine tuning can be specified - via the argument `learningratesfinetuning` as a vector - with an entry for each of the epochs. * `learningratepretraining`: learning rate for pretraining, defaults to `learningrate` * `learningratefinetuning`: initial learning rate for fine tuning. The learning rate for fine tuning is decaying with the number of epochs, starting with the given value for the `learningratefinetuning` or the `learningrate`. (For more details see `traindbm!`.) +* `learningratesfinetuning`: + The learning rate for fine tuning is by default decaying with the number of epochs, + starting with the value of the `learningrate`. + (For more details see `traindbm!`.) + The value of the learning rate for each epoch of fine tuning can be specified + via the argument `learningratesfinetuning` as a vector + with an entry for each of the epochs. +* `learningrates`: deprecated, otherwise equivalent to `learningratesfinetuning` * `batchsize`: number of samples in mini-batches for pretraining and fine tuning. By default, a batchsize of 1 is used for pretraining. For fine tuning, no mini-batches are used by default, which means that @@ -218,11 +219,14 @@ updates. update the weights and biases. The learning rates should decrease with the epochs, e. g. with the factor `a / (b + epoch)`. If only one value is given as `learningrate`, `a` and `b` are 11.0 and 10.0, respectively. +* `batchsize`: number of samples in mini-batches. + No mini-batches are used by default, which means that + the complete data set is used for calculating the gradient in each epoch. * `nparticles`: number of particles used for sampling, default 100 * `monitoring`: A function that is executed after each training epoch. It has to accept the trained DBM and the current epoch as arguments. """ -function traindbm!(dbm::MultimodalDBM, x::Array{Float64,2}; +function traindbm!(dbm::MultimodalDBM, x::AbstractArray{Float64,2}; epochs::Int = 10, nparticles::Int = 100, learningrate::Float64 = 0.005, @@ -240,7 +244,7 @@ function traindbm!(dbm::MultimodalDBM, x::Array{Float64,2}; optimizer = converttodbmoptimizer(optimizer, dbm) map!(opt -> converttodbmoptimizer(opt, dbm), optimizers, optimizers) - optimizers = assertinitoptimizers(optimizer, optimizers, dbm, + optimizers = assert_initoptimizers(optimizer, optimizers, dbm, learningrates, sdlearningrates, epochs) particles = initparticles(dbm, nparticles) @@ -263,7 +267,7 @@ function traindbm!(dbm::MultimodalDBM, x::Array{Float64,2}; traindbm!(dbm, x, particles, optimizers[epoch]) end - # monitor the learning process at the end of epoch + # monitor the learning process at the end of each epoch monitoring(dbm, epoch) end diff --git a/src/rbmtraining.jl b/src/rbmtraining.jl index f57019b..47125b5 100644 --- a/src/rbmtraining.jl +++ b/src/rbmtraining.jl @@ -6,7 +6,7 @@ function assert_enoughvaluesforepochs(vname::String, v::Vector, epochs::Int) end -function assertinitoptimizers(optimizer::AbstractOptimizer, +function assert_initoptimizers(optimizer::AbstractOptimizer, optimizers::Vector{<:AbstractOptimizer}, bm::BM, learningrates::Vector{Float64}, sdlearningrates::Vector{Float64}, epochs::Int @@ -144,7 +144,7 @@ function fitrbm(x::Matrix{Float64}; rbm.sd .*= sdinitfactor end - optimizers = assertinitoptimizers(optimizer, optimizers, rbm, + optimizers = assert_initoptimizers(optimizer, optimizers, rbm, learningrates, sdlearningrates, epochs) if pcd diff --git a/test/examples.jl b/test/examples.jl index dea149b..324a1d5 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -120,7 +120,6 @@ loglikelihood(dbm, xtest) # ------------------------------------------------------------------------------ Random.seed!(0); -# Calculate a two dimensional dimension reduction on the data x, xlabels = blocksinnoise(500, 50, blocklen = 5, nblocks = 5) dbm = fitdbm(x, nhiddens = [50, 30, 15], batchsize = 5,