Reference

This is the full API reference for RestrictedBoltzmannMachines.jl. Most functions and types have detailed docstrings. See also the Layer Types page for an overview of the available layer types, and the Examples for usage tutorials.

RestrictedBoltzmannMachines.GaussianType
Gaussian(θ, γ)

Gaussian layer, with location parameters θ and scale parameters γ. The energy of a layer with units $h_\mu$ is $E = \sum_\mu U(h_\mu)$, with the unit potential:

\[U(h) = \frac{|\gamma|}{2} h^2 - \theta h\]

where $\theta$, $\gamma$ are the entries of θ, γ for the corresponding unit, and $h$ takes values in $\mathbb{R}$.

source
RestrictedBoltzmannMachines.PottsType
Potts(θ)

Layer with Potts units, with external fields θ. Encodes categorical variables as one-hot vectors. The number of classes is the size of the first dimension.

Note

Sampling from Potts layers is not GPU-friendly. For GPU usage, use PottsGumbel instead, which uses the Gumbel-softmax trick.

source
RestrictedBoltzmannMachines.RBMMethod
RBM(centered_rbm::CenteredRBM)

Returns an (uncentered) RBM which neglects the offsets of centered_rbm. The resulting model is not equivalent to the original centered_rbm. To construct an equivalent model, use the function uncenter(centered_rbm) instead (see uncenter). Shares parameters with centered_rbm.

source
RestrictedBoltzmannMachines.ReLUType
ReLU(θ, γ)

Layer with ReLU units, with location parameters θ and scale parameters γ. The energy of a layer with units $h_\mu$ is $E = \sum_\mu U(h_\mu)$, with the unit potential:

\[U(h) = \frac{|\gamma|}{2} h^2 - \theta h \qquad (h \ge 0)\]

where $\theta$, $\gamma$ are the entries of θ, γ for the corresponding unit. Units are constrained to non-negative values ($U(h) = \infty$ for $h < 0$).

source
RestrictedBoltzmannMachines.SpinType
Spin(θ)

Layer with spin units, with external fields θ. The energy of a layer with units $s_i$ is given by:

\[E = -\sum_i \theta_i s_i\]

where each spin $s_i$ takes values $\pm 1$.

source
RestrictedBoltzmannMachines.StandardizedRBMType
StandardizedRBM{V,H,W,Ov,Oh,Sv,Sh}

RBM with standardized layer activations. Like CenteredRBM it subtracts the offsets offset_v, offset_h from the visible and hidden activations entering the interaction, and additionally divides them by the scales scale_v, scale_h. The energy is

\[E(v,h) = E_v(v) + E_h(h) - \sum_{i\mu} w_{i\mu} \frac{v_i - \lambda_i}{\sigma_i} \frac{h_\mu - \lambda_\mu}{\sigma_\mu}\]

where $\lambda$ are the offsets and $\sigma$ the scales. A CenteredRBM is the special case with unit scales. See http://jmlr.org/papers/v17/14-237.html.

source
RestrictedBoltzmannMachines.StandardizedRBMMethod
StandardizedRBM(rbm, offset_v, offset_h, scale_v, scale_h)

Creates a standardized RBM, with offsets offset_v, offset_h and scales scale_v, scale_h. The resulting model is not equivalent to the original rbm, unless the offsets are zero and the scales are one. To construct an equivalent model instead, use standardize.

source
RestrictedBoltzmannMachines.dReLUType
dReLU(; θp, θn, γp, γn)

Double ReLU layer, with separate parameters for positive and negative parts. The energy of a layer with units $h_\mu$ is $E = \sum_\mu U(h_\mu)$, with the unit potential:

\[U(h) = \begin{cases} \frac{|\gamma^+|}{2} h^2 - \theta^+ h & h \ge 0 \\[4pt] \frac{|\gamma^-|}{2} h^2 - \theta^- h & h < 0 \end{cases}\]

where $\theta^+, \theta^-, \gamma^+, \gamma^-$ are the entries of θp, θn, γp, γn for the corresponding unit, and $h$ takes values in $\mathbb{R}$.

source
RestrictedBoltzmannMachines.nsReLUType
nsReLU(; θ, Δ, ξ)

A variant of xReLU units without scale parameter γ (which is fixed at 1). This is done to remove the gauge invariance between the weights and the hidden units scale. The energy of a layer with units $h_\mu$ is $E = \sum_\mu U(h_\mu)$, with the unit potential:

\[U(h) = \begin{cases} \frac{1}{2(1+\eta)} h^2 - \left(\theta + \frac{\Delta}{1+\eta}\right) h & h \ge 0 \\[4pt] \frac{1}{2(1-\eta)} h^2 - \left(\theta - \frac{\Delta}{1-\eta}\right) h & h < 0 \end{cases} \qquad \eta = \frac{\xi}{1 + |\xi|}\]

where $\theta, \Delta, \xi$ are the entries of θ, Δ, ξ for the corresponding unit. This is the xReLU potential with $\gamma = 1$.

source
RestrictedBoltzmannMachines.pReLUType
pReLU(; θ, γ, Δ, η)

A different parameterization of the dReLU layer, with shared scale and asymmetry ratio. The energy of a layer with units $h_\mu$ is $E = \sum_\mu U(h_\mu)$, with the unit potential:

\[U(h) = \begin{cases} \frac{|\gamma|}{2(1+\eta)} h^2 - \left(\theta + \frac{\Delta}{1+\eta}\right) h & h \ge 0 \\[4pt] \frac{|\gamma|}{2(1-\eta)} h^2 - \left(\theta - \frac{\Delta}{1-\eta}\right) h & h < 0 \end{cases}\]

where $\theta, \gamma, \Delta, \eta$ are the entries of θ, γ, Δ, η for the corresponding unit. This is the dReLU potential with $\theta^\pm = \theta \pm \Delta / (1 \pm \eta)$ and $\gamma^\pm = \gamma / (1 \pm \eta)$.

Every value of η must be finite and lie strictly inside (-1, 1). For unconstrained learned asymmetry, use xReLU or the fixed-scale nsReLU instead.

source
RestrictedBoltzmannMachines.xReLUType
xReLU(; θ, γ, Δ, ξ)

Extended ReLU layer, like pReLU but with unbounded asymmetry parameter. The energy of a layer with units $h_\mu$ is $E = \sum_\mu U(h_\mu)$, with the unit potential:

\[U(h) = \begin{cases} \frac{|\gamma|}{2(1+\eta)} h^2 - \left(\theta + \frac{\Delta}{1+\eta}\right) h & h \ge 0 \\[4pt] \frac{|\gamma|}{2(1-\eta)} h^2 - \left(\theta - \frac{\Delta}{1-\eta}\right) h & h < 0 \end{cases} \qquad \eta = \frac{\xi}{1 + |\xi|}\]

where $\theta, \gamma, \Delta, \xi$ are the entries of θ, γ, Δ, ξ for the corresponding unit. This is the pReLU potential with the bounded asymmetry $\eta \in (-1, 1)$ reparameterized through the unbounded $\xi \in \mathbb{R}$.

source
RestrictedBoltzmannMachines.BinaryRBMMethod
BinaryRBM(a, b, w)
BinaryRBM(N, M)

Construct an RBM with binary visible and hidden units, which has an energy function:

\[E(v, h) = -a'v - b'h - v'wh\]

Equivalent to RBM(Binary(a), Binary(b), w).

source
RestrictedBoltzmannMachines.BinaryStandardizedRBMMethod
BinaryStandardizedRBM(a, b, w, offset_v, offset_h, scale_v, scale_h)
BinaryStandardizedRBM(a, b, w)

Construct a standardized RBM with Binary visible and hidden layers. With the short form the offsets are zero and the scales one (equivalent to the plain BinaryRBM).

source
RestrictedBoltzmannMachines.HopfieldRBMMethod
HopfieldRBM(g, θ, γ, w)
HopfieldRBM(g, w)

Construct an RBM with spin visible units and Gaussian hidden units. If not given, θ = 0 and γ = 1 by default.

\[E(v, h) = -g'v - θ'h + \sum_\mu \frac{γ_\mu}{2} h_\mu^2 - v'wh\]

source
RestrictedBoltzmannMachines.SpinStandardizedRBMMethod
SpinStandardizedRBM(a, b, w, offset_v, offset_h, scale_v, scale_h)
SpinStandardizedRBM(a, b, w)

Construct a standardized RBM with Spin visible and hidden layers. With the short form the offsets are zero and the scales one (equivalent to the plain SpinRBM).

source
RestrictedBoltzmannMachines.aisMethod
ais(rbm0, rbm1, v0, βs)

Provided v0 is an equilibrated sample from rbm0, returns F such that mean(exp.(F)) is an unbiased estimator of Z1/Z0, the ratio of partition functions of rbm1 and rbm0.

!!! tip Use logmeanexp logmeanexp(F), using the function logmeanexp from LogStatFunctions.jl, tends to give a better approximation of log(Z1) - log(Z0) than mean(F).

source
RestrictedBoltzmannMachines.aiseMethod
aise(rbm, [βs]; [nbetas], init=rbm.visible, nsamples=1)

AIS estimator of the log-partition function of rbm. It is recommended to fit init to the single-site statistics of rbm (or the data).

!!! tip Use large nbetas For more accurate estimates, use larger nbetas. It is usually better to have large nbetas and small nsamples, rather than large nsamples and small nbetas.

source
RestrictedBoltzmannMachines.annealMethod
anneal(rbm0, rbm1; β)

Returns an RBM that interpolates between rbm0 and rbm1. Denoting by E0(v, h) and E1(v, h) the energies assigned by rbm0 and rbm1, respectively, the returned RBM assigns energies given by:

E(v,h) = (1 - β) * E0(v) + β * E1(v, h)
source
RestrictedBoltzmannMachines.batchmean_momentsMethod
batchmean_moments(layer, moments; [wts])

Average a per-configuration moments array (as returned by moments_from_inputs with batched inputs) over its batch dimensions, weighted by wts (lazy uniform weights by default).

source
RestrictedBoltzmannMachines.categorical_sampleMethod
categorical_sample(P)

Given a probability array P of size (q, *), returns an array C of size (*), such that C[i] ∈ 1:q is a random sample from the categorical distribution P[:,i]. You must ensure that P defines a proper probability distribution.

source
RestrictedBoltzmannMachines.center!Method
center!(centered_rbm, offset_v = 0, offset_h = 0)

Transforms the offsets of centered_rbm. The transformed model is equivalent to the original one (energies differ by a constant).

source
RestrictedBoltzmannMachines.centerMethod
center(rbm::RBM, offset_v = 0, offset_h = 0)

Constructs a CenteredRBM equivalent to the given rbm. The energies assigned by the two models differ by a constant amount,

\[E(v,h) - E_c(v,h) = \sum_{i\mu}w_{i\mu}\lambda_i\lambda_\mu\]

where $E(v,h)$ is the energy assigned by the original rbm, and $E_c(v,h)$ is the energy assigned by the returned CenteredRBM.

This is the inverse operation of uncenter.

To construct a CenteredRBM that simply includes these offsets, call CenteredRBM(rbm, offset_v, offset_h) instead.

source
RestrictedBoltzmannMachines.collect_statesMethod
collect_states(layer)

Returns an array of all states of layer. Only defined for discrete layers.

Warning

Use only for small layers. For large layers, the exponential number of states will not fit in memory.

source
RestrictedBoltzmannMachines.initialize!Function
initialize!(rbm, [data]; ϵ = 1e-6)

Initializes the RBM and returns it. If provided, matches average visible unit activities from data.

initialize!(layer, [data]; ϵ = 1e-6)

Initializes a layer and returns it. If provided, matches average unit activities from data.

source
RestrictedBoltzmannMachines.log_likelihoodMethod
log_likelihood(rbm, v)

Log-likelihood of v under rbm, with the partition function compued by extensive enumeration. For discrete layers, this is exponentially slow for large machines.

source
RestrictedBoltzmannMachines.log_partitionMethod
log_partition(rbm)

Log-partition of rbm, computed by extensive enumeration of visible states (except for particular cases such as Gaussian-Gaussian RBM). This is exponentially slow for large machines.

For Gaussian-Gaussian RBMs, the exact Gaussian integral is used when the joint precision matrix (with Gaussian precisions abs.(γ)) is positive definite. Non-normalizable models with a singular or indefinite joint precision return Inf.

If your RBM has a smaller hidden layer, consider mirroring the layers of the rbm first (see mirror).

source
RestrictedBoltzmannMachines.log_pseudolikelihoodMethod
log_pseudolikelihood(rbm, v; exact = false)

Log-pseudolikelihood of v. If exact is true, the exact pseudolikelihood is returned. But this is slow if v consists of many samples. Therefore by default exact is false, in which case the result is a stochastic approximation, where a random site is selected for each sample, and its conditional probability is calculated. In average the results with exact = false coincide with the deterministic result, and the estimate is more precise as the number of samples increases.

source
RestrictedBoltzmannMachines.log_pseudolikelihood_exactFunction
log_pseudolikelihood_exact(rbm, v)

Log-pseudolikelihood of v. This function computes the exact pseudolikelihood, doing traces over all sites. Note that this can be slow for large number of samples. Implemented for Binary, Spin, Potts, and PottsGumbel visible layers.

source
RestrictedBoltzmannMachines.log_pseudolikelihood_sitesFunction
log_pseudolikelihood_sites(rbm, v, sites)

Log-pseudolikelihood of a site conditioned on the other sites, where sites is an array of site indices (CartesianIndex), one for each sample. Returns an array of log-pseudolikelihood values, for each sample. Implemented for Binary, Spin, Potts, and PottsGumbel visible layers.

source
RestrictedBoltzmannMachines.log_pseudolikelihood_stochMethod
log_pseudolikelihood_stoch(rbm, v)

Log-pseudolikelihood of v. This function computes an stochastic approximation, by doing a trace over random sites for each sample. For large number of samples, this is in average close to the exact value of the pseudolikelihood.

source
RestrictedBoltzmannMachines.metropolis!Method
metropolis!(v, rbm; β = 1)

Metropolis-Hastings sampling from rbm at inverse temperature β. Uses v[:,:,..,:,1] as initial configurations, and writes the Monte-Carlo chains in v[:,:,..,:,2:end].

source
RestrictedBoltzmannMachines.metropolisMethod
metropolis(rbm, v; β = 1, steps = 1)

Metropolis-Hastings sampling from rbm at inverse temperature β, starting from configuration v. Moves are proposed by normal Gibbs sampling.

source
RestrictedBoltzmannMachines.moments_from_inputsFunction
moments_from_inputs(layer, [inputs])

Moments of the unit activations under the conditional distribution given inputs, in the same layout as moments_from_samples: the first axis indexes the moment, the next axes are size(layer), and any trailing batch dimensions of inputs are preserved (the moments are per-configuration, not batch-averaged).

source
RestrictedBoltzmannMachines.moments_from_samplesFunction
moments_from_samples(layer, data; [wts])

Empirical moments of data, batch-averaged with weights wts. Each layer defines which moments it computes (see the docstrings of its specific methods); generally they are the sufficient statistics of the layer distribution, which do not depend on the layer parameters, so they can be computed once from a dataset and reused as the parameters change (see pcd!). The first axis indexes the moment and the remaining axes are size(layer) (batch dimensions of data are averaged over). The number of moments need not match the number of parameters (e.g. nsReLU uses the 4-slot dReLU layout while having 3 parameters).

moments_from_inputs returns conditional moments in this same layout, and ∂energy_from_moments consumes it.

source
RestrictedBoltzmannMachines.pcd!Method
pcd!(rbm, data; kwargs...)

Train an RBM with Persistent Contrastive Divergence (PCD).

pcd! repeatedly draws mini-batches from data, performs steps Gibbs updates of persistent fantasy particles, estimates the positive/negative phase gradients, applies optional regularization and gauge constraints, and updates model parameters with an Optimisers.jl rule.

data must have shape (size(rbm.visible)..., nsamples).

Keyword arguments

  • batchsize::Int=1: number of samples per update.
  • iters::Int=1: number of parameter updates.
  • wts::AbstractVector{<:Real}: finite, positive per-sample weights, lazy uniform weights by default. Zero or negative weights raise an ArgumentError — drop observations meant to be excluded (and their weights) beforehand. Callbacks receive the minibatch weights as wd.
  • steps::Int=1: Gibbs steps used to update persistent chains each iteration.
  • optim::AbstractRule=Adam(): optimizer rule from Optimisers.jl.
  • moments=moments_from_samples(rbm.visible, data; wts): data moments used by the positive phase.
  • l2_fields::Real=0: L2 regularization on visible fields.
  • l1_weights::Real=0: L1 regularization on interaction weights.
  • l2_weights::Real=0: L2 regularization on interaction weights.
  • l2l1_weights::Real=0: group-like L2/L1 weight regularization.
  • zerosum::Bool=true: enforce zero-sum gauge on Potts layers.
  • rescale::Bool=true: rescale weights (mainly useful for continuous hidden units).
  • callback=Returns(nothing): called after every update as callback(; rbm, optim, state, ps, iter, vd, wd, ∂, vm). Slurp unused keywords with a trailing _....
  • vm: initial fantasy particles. By default, min(batchsize, nsamples) chains sampled from the visible layer with zero inputs.
  • shuffle::Bool=true: whether to reshuffle samples between epochs.
  • ps: optimized parameter container. By default, this contains the visible, hidden, and interaction parameters.
  • state=setup(optim, ps): optimizer state.

Returns (state, ps).

source
RestrictedBoltzmannMachines.raiseMethod
raise(rbm::RBM, βs; v, init)

Reverse AIS estimator of the log-partition function of rbm. While aise tends to understimate the log of the partition function, raise tends to overstimate it. v must be an equilibrated sample from rbm.

!!! tip Use logmeanexp If F = raise(...), then -logmeanexp(-F), using the function logmeanexp from LogStatFunctions.jl, tends to give a better approximation of log(Z) than mean(F).

!!! tip Sandwiching the log-partition function If Rf = aise(...), Rr = raise(...) are the AIS and reverse AIS estimators, we have the stochastic bounds logmeanexp(Rf) ≤ log(Z) ≤ -logmeanexp(-Rr).

source
RestrictedBoltzmannMachines.rescale_activations!Method
rescale_activations!(layer, λ::AbstractArray)

For continuous layers with scale parameters, re-parameterizes such that unit activations are divided by λ, and returns true. For other layers, does nothing and returns false.

source
RestrictedBoltzmannMachines.rescale_hidden!Method
rescale_hidden!(rbm::CenteredRBM, λ::AbstractArray)

Scales parameters such that hidden unit activations are divided by λ, preserving the modeled distribution. This assumes the hidden units have a scale parameter, otherwise it does nothing and returns false. Since the interaction involves h - offset_h, the hidden offsets are divided by λ together with the activations.

source
RestrictedBoltzmannMachines.rescale_hidden!Method
rescale_hidden!(rbm, λ::AbstractArray)

For continuous hidden units with a scale parameter, scales parameters such that hidden unit activations are divided by λ, and returns true. For other hidden units does nothing and returns false. The modified RBM is equivalent to the original one.

source
RestrictedBoltzmannMachines.rescale_hidden!Method
rescale_hidden!(rbm::StandardizedRBM, λ::AbstractArray)

Rescale hidden unit activities by λ, which should be an array of the same size as the hidden units. This assumes the hidden units have a scale parameter, otherwise it does nothing and returns false.

source
RestrictedBoltzmannMachines.rescale_weights!Method
rescale_weights!(rbm)

For continuous hidden units with a scale parameter, scales parameters such that the weights attached to each hidden unit have norm 1. Hidden units whose incoming weights have zero norm are left unchanged. For a StandardizedRBM the unstandardized weights are normalized (see weight_norms): the standardized weights are invariant under rescaling of hidden unit activities, so they cannot be constrained to have unit norm.

source
RestrictedBoltzmannMachines.sample_h_from_hMethod
sample_h_from_h(rbm, h; steps=1)

Samples a hidden configuration conditional on another hidden configuration h. Ensures type stability by requiring that the returned array is of the same type as h.

source
RestrictedBoltzmannMachines.sample_v_from_vMethod
sample_v_from_v(rbm, v; steps=1)

Samples a visible configuration conditional on another visible configuration v. Ensures type stability by requiring that the returned array is of the same type as v.

source
RestrictedBoltzmannMachines.standardize!Method
standardize!(rbm::StandardizedRBM, offset_v, offset_h, scale_v, scale_h)

Transforms the offsets and scales of rbm in place. The transformed model is equivalent to the original one (energies differ by a constant). In-place analogue of standardize.

source
RestrictedBoltzmannMachines.standardizeMethod
standardize(rbm, offset_v = 0, offset_h = 0, scale_v = 1, scale_h = 1)

Constructs a StandardizedRBM equivalent to the given rbm (a plain RBM or another StandardizedRBM), with the given offsets and scales. The energies assigned by the two models differ by a constant amount, so the modeled distribution is unchanged.

This is the inverse operation of unstandardize. To construct a StandardizedRBM that simply adopts these offsets and scales without preserving the distribution, call StandardizedRBM(rbm, offset_v, offset_h, scale_v, scale_h) instead.

source
RestrictedBoltzmannMachines.standardize_hidden_from_v!Method
standardize_hidden_from_v!(rbm::StandardizedRBM, v; [wts], damping = 0, ϵ = 0)

Sets the hidden offsets and scales to the mean and standard deviation of hidden unit activations conditioned on v. The model is unchanged (energies differ by a constant).

source
RestrictedBoltzmannMachines.tnmeanvarMethod
tnmeanvar(a)

Mean and variance of the standard normal distribution truncated to the interval (a, +∞). Equivalent to tnmean(a), tnvar(a) but saves some common computations. WARNING: tnvar(a) can fail for very very large values ofa`.

source
RestrictedBoltzmannMachines.uncenterMethod
uncenter(centered_rbm::CenteredRBM)

Constructs an RBM equivalent to the given CenteredRBM. The energies assigned by the two models differ by a constant amount,

\[E(v,h) - E_c(v,h) = \sum_{i\mu}w_{i\mu}\lambda_i\lambda_\mu\]

where $E_c(v,h)$ is the energy assigned by centered_rbm and $E(v,h)$ is the energy assigned by the RBM constructed by this method.

This is the inverse operation of center.

To construct an RBM that simply neglects the offsets, call RBM(centered_rbm) instead.

source
RestrictedBoltzmannMachines.weight_normsMethod
weight_norms(std_rbm::StandardizedRBM)

Computes the norms of the unstandardized weights for each hidden unit. If you want the norms of the standardized weights, use weight_norms(RBM(std_rbm)).

source
RestrictedBoltzmannMachines.wmeanMethod
wmean(A; [wts])

Weighted mean of A along its trailing dimensions, weighted by wts (see wsum). By default, lazy uniform weights over all of A, which reduce like an ordinary mean without allocating a weights array or promoting eltypes.

\[\frac{\sum_i A_i w_i}{\sum_i w_i}\]

source
RestrictedBoltzmannMachines.wsumMethod
wsum(A, wts)

Weighted sum of A along its trailing dimensions, weighted by wts.

\[\sum_i A_i w_i\]

The reduced dimensions are inferred from the shape of wts, which must match the trailing dimensions of A (all of A for a full reduction, returning a scalar). Reduced dimensions are dropped from the result.

source
RestrictedBoltzmannMachines.zerosum!Method
zerosum!(∂, rbm::Union{CenteredRBM, StandardizedRBM})

Projects the gradient so that it doesn't modify the zerosum gauge of the equivalent plain RBM (see uncenter, unstandardize), with offsets and scales held fixed.

The gauge condition applies to the parameters of the equivalent plain RBM: for the weights it reads sum(w ./ scale_v; dims = 1) == 0 over Potts colors (and similarly for hidden Potts with scale_h), so the gradient component removed here is the corresponding gauge direction ξ .* scale_v. For a CenteredRBM the scales are one and these conditions coincide with the plain RBM ones.

source
RestrictedBoltzmannMachines.zerosumMethod
zerosum(rbm::CenteredRBM)

Returns an equivalent CenteredRBM, with the same offsets, whose equivalent uncentered RBM (see uncenter) is in the zerosum gauge. Only affects Potts layers. If the rbm doesn't have Potts layers, does nothing.

Note that the gauge condition applies to the uncentered parameters: since the interaction energy involves the centered v - offset_v, sums over Potts colors of the centered weights are compensated differently than in a plain RBM.

source
RestrictedBoltzmannMachines.zerosumMethod
zerosum(rbm::StandardizedRBM)

Returns an equivalent StandardizedRBM, with the same offsets and scales, whose equivalent unstandardized RBM (see unstandardize) is in the zerosum gauge. Only affects Potts layers. If the rbm doesn't have Potts layers, does nothing.

Note that the gauge condition applies to the unstandardized parameters: the standardized weights and fields need not sum to zero over Potts colors, because the interaction energy involves the standardized (v - offset_v) / scale_v, for which sums over colors are not constant when the offsets and scales vary across colors.

source
RestrictedBoltzmannMachines.∂cgfFunction
∂cgf(layer, [inputs]; [wts])

Unit activation moments, conjugate to layer parameters. These are obtained by differentiating cgfs with respect to the layer parameters. Averages over configurations (weigthed by wts).

source
RestrictedBoltzmannMachines.∂cgfsFunction
∂cgfs(layer, [inputs])

Gradient of cgfs with respect to the layer parameters, for each configuration of inputs (batch dimensions are preserved; the first axis indexes the parameter, as in layer.par). Since the cumulant generating function and the energy are conjugate, this is -∂energy_from_moments evaluated at the conditional moments given inputs.

source
RestrictedBoltzmannMachines.∂energy_from_momentsFunction
∂energy_from_moments(layer, moments)

Derivative of the layer's mean energy with respect to its parameters, evaluated at a moments array (see moments_from_samples for the layout). The first axis of the result indexes the parameter, as in layer.par, and trailing batch dimensions of moments are preserved. Since the energy is linear in the sufficient statistics, this is a linear map of moments, with coefficients that may depend on the current parameters.

source
RestrictedBoltzmannMachines.@declare_layerMacro
@declare_layer Layer (θ = zeros, γ = ones)

Declares a layer type Layer whose named parameters are the rows of a shared par array, in the given order, with the given default initializers. Generates the struct (with par size validation and a _validate_layer_parameters hook in the inner constructor), the Layer(par), keyword, Layer(T, sz), and Layer(sz) constructors, Base.propertynames, the Base.getproperty accessors returning views into par, and the _construct_like trait used by generic functions such as anneal.

source