From be267d4e9dea25ce58f3241fc2ce89b7cb29dea5 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Thu, 11 Jul 2024 20:09:10 +0000 Subject: [PATCH] build based on 3ff7d1e --- dev/.documenter-siteinfo.json | 2 +- dev/ae/index.html | 2 +- dev/diffgeo/index.html | 2 +- dev/encoders/index.html | 2 +- dev/guidelines/index.html | 2 +- dev/hvae/index.html | 2 +- dev/index.html | 2 +- dev/infomaxvae/index.html | 2 +- dev/layers/index.html | 2 +- dev/mmdvae/index.html | 2 +- dev/quickstart/index.html | 2 +- dev/rhvae/index.html | 2 +- dev/utils/index.html | 2 +- dev/vae/index.html | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 18676c4..629be52 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-07-11T19:46:03","documenter_version":"1.5.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-07-11T20:09:06","documenter_version":"1.5.0"}} \ No newline at end of file diff --git a/dev/ae/index.html b/dev/ae/index.html index bef4df3..8a5646a 100644 --- a/dev/ae/index.html +++ b/dev/ae/index.html @@ -7,4 +7,4 @@ x_in::AbstractArray, x_out::AbstractArray; regularization::Union{Function, Nothing}=nothing, - reg_strength::Float32=1.0f0)

Calculate the mean squared error (MSE) loss for an autoencoder (AE) using separate input and target output vectors.

The AE loss is computed as: loss = MSE(xout, x̂) + regstrength × reg_term

Where:

Arguments

Optional Keyword Arguments

Returns

Note

Ensure that the input data x_in matches the expected input dimensionality for the encoder in the AE.

Training

AutoEncoderToolkit.AEs.train!Function
`train!(ae, x, opt; loss_function, loss_kwargs...)`

Customized training function to update parameters of an autoencoder given a specified loss function.

Arguments

  • ae::AE: A struct containing the elements of an autoencoder.
  • x::AbstractArray: Input data on which the autoencoder will be trained.
  • opt::NamedTuple: State of the optimizer for updating parameters. Typically initialized using Flux.Train.setup.

Optional Keyword Arguments

  • loss_function::Function: The loss function used for training. It should accept the autoencoder model and input data x, and return a loss value.
  • loss_kwargs::Union{NamedTuple,Dict} = Dict(): Additional arguments for the loss function.
  • verbose::Bool=false: If true, the loss value will be printed during training.
  • loss_return::Bool=false: If true, the loss value will be returned after training.

Description

Trains the autoencoder by:

  1. Computing the gradient of the loss with respect to the autoencoder parameters.
  2. Updating the autoencoder parameters using the optimizer.
train!(ae, x_in, x_out, opt; loss_function, loss_kwargs...)

Customized training function to update parameters of an autoencoder given a specified loss function.

Arguments

  • ae::AE: A struct containing the elements of an autoencoder.
  • x_in::AbstractArray: Input data on which the autoencoder will be trained.
  • x_out::AbstractArray: Target output data for the autoencoder.
  • opt::NamedTuple: State of the optimizer for updating parameters. Typically initialized using Flux.Train.setup.

Optional Keyword Arguments

  • loss_function::Function: The loss function used for training. It should accept the autoencoder model and input data x, and return a loss value.
  • loss_kwargs::Union{NamedTuple,Dict} = Dict(): Additional arguments for the loss function.
  • verbose::Bool=false: If true, the loss value will be printed during training.
  • loss_return::Bool=false: If true, the loss value will be returned after training.

Description

Trains the autoencoder by:

  1. Computing the gradient of the loss with respect to the autoencoder parameters.
  2. Updating the autoencoder parameters using the optimizer.
+ reg_strength::Float32=1.0f0)

Calculate the mean squared error (MSE) loss for an autoencoder (AE) using separate input and target output vectors.

The AE loss is computed as: loss = MSE(xout, x̂) + regstrength × reg_term

Where:

Arguments

Optional Keyword Arguments

Returns

Note

Ensure that the input data x_in matches the expected input dimensionality for the encoder in the AE.

Training

AutoEncoderToolkit.AEs.train!Function
`train!(ae, x, opt; loss_function, loss_kwargs...)`

Customized training function to update parameters of an autoencoder given a specified loss function.

Arguments

  • ae::AE: A struct containing the elements of an autoencoder.
  • x::AbstractArray: Input data on which the autoencoder will be trained.
  • opt::NamedTuple: State of the optimizer for updating parameters. Typically initialized using Flux.Train.setup.

Optional Keyword Arguments

  • loss_function::Function: The loss function used for training. It should accept the autoencoder model and input data x, and return a loss value.
  • loss_kwargs::Union{NamedTuple,Dict} = Dict(): Additional arguments for the loss function.
  • verbose::Bool=false: If true, the loss value will be printed during training.
  • loss_return::Bool=false: If true, the loss value will be returned after training.

Description

Trains the autoencoder by:

  1. Computing the gradient of the loss with respect to the autoencoder parameters.
  2. Updating the autoencoder parameters using the optimizer.
train!(ae, x_in, x_out, opt; loss_function, loss_kwargs...)

Customized training function to update parameters of an autoencoder given a specified loss function.

Arguments

  • ae::AE: A struct containing the elements of an autoencoder.
  • x_in::AbstractArray: Input data on which the autoencoder will be trained.
  • x_out::AbstractArray: Target output data for the autoencoder.
  • opt::NamedTuple: State of the optimizer for updating parameters. Typically initialized using Flux.Train.setup.

Optional Keyword Arguments

  • loss_function::Function: The loss function used for training. It should accept the autoencoder model and input data x, and return a loss value.
  • loss_kwargs::Union{NamedTuple,Dict} = Dict(): Additional arguments for the loss function.
  • verbose::Bool=false: If true, the loss value will be printed during training.
  • loss_return::Bool=false: If true, the loss value will be returned after training.

Description

Trains the autoencoder by:

  1. Computing the gradient of the loss with respect to the autoencoder parameters.
  2. Updating the autoencoder parameters using the optimizer.
diff --git a/dev/diffgeo/index.html b/dev/diffgeo/index.html index bbdf734..1efec44 100644 --- a/dev/diffgeo/index.html +++ b/dev/diffgeo/index.html @@ -51,4 +51,4 @@ riemannian_metric::AbstractArray, curve_velocity::AbstractArray, t::AbstractVector; -)

Function to compute the (discretized) integral defining the energy of a curve γ̲ on a Riemmanina manifold. The energy is defined as

    E(γ̲) = ∫ dt ⟨γ̲̇(t), G̲̲ γ̲̇(t)⟩,

where γ̲̇(t) defines the velocity of the parametric curve, and G̲̲ is the Riemmanian metric tensor. For this function, we approximate the integral as

    E(γ̲) ≈ ∑ᵢ Δt ⟨γ̲̇(tᵢ)ᵀ G̲̲ (γ̲(tᵢ+1) γ̲̇(tᵢ))⟩,

where Δt is the time step between points. Note that this Δt is assumed to be constant, thus, the time points t must be equally spaced.

Arguments

Returns

References

  1. Chen, N. et al. Metrics for Deep Generative Models. in Proceedings of the Twenty-First International Conference on Artificial Intelligence and Statistics 1540–1550 (PMLR, 2018).
  2. Chadebec, C. & Allassonnière, S. A Geometric Perspective on Variational Autoencoders. Preprint at http://arxiv.org/abs/2209.07370 (2022).
  3. Chadebec, C., Mantoux, C. & Allassonnière, S. Geometry-Aware Hamiltonian Variational Auto-Encoder. Preprint at http://arxiv.org/abs/2010.11518 (2020).
  4. Arvanitidis, G., Hauberg, S., Hennig, P. & Schober, M. Fast and Robust Shortest Paths on Manifolds Learned from Data. in Proceedings of the Twenty-Second International Conference on Artificial Intelligence and Statistics 1506–1515 (PMLR, 2019).
  5. Arvanitidis, G., Hauberg, S. & Schölkopf, B. Geometrically Enriched Latent Spaces. Preprint at https://doi.org/10.48550/arXiv.2008.00565 (2020).
  6. Arvanitidis, G., González-Duque, M., Pouplin, A., Kalatzis, D. & Hauberg, S. Pulling back information geometry. Preprint at http://arxiv.org/abs/2106.05367 (2022).
  7. Fröhlich, C., Gessner, A., Hennig, P., Schölkopf, B. & Arvanitidis, G. Bayesian Quadrature on Riemannian Data Manifolds.
  8. Kalatzis, D., Eklund, D., Arvanitidis, G. & Hauberg, S. Variational Autoencoders with Riemannian Brownian Motion Priors. Preprint at http://arxiv.org/abs/2002.05227 (2020).
  9. Arvanitidis, G., Hansen, L. K. & Hauberg, S. Latent Space Oddity: on the Curvature of Deep Generative Models. Preprint at http://arxiv.org/abs/1710.11379 (2021).
+)

Function to compute the (discretized) integral defining the energy of a curve γ̲ on a Riemmanina manifold. The energy is defined as

    E(γ̲) = ∫ dt ⟨γ̲̇(t), G̲̲ γ̲̇(t)⟩,

where γ̲̇(t) defines the velocity of the parametric curve, and G̲̲ is the Riemmanian metric tensor. For this function, we approximate the integral as

    E(γ̲) ≈ ∑ᵢ Δt ⟨γ̲̇(tᵢ)ᵀ G̲̲ (γ̲(tᵢ+1) γ̲̇(tᵢ))⟩,

where Δt is the time step between points. Note that this Δt is assumed to be constant, thus, the time points t must be equally spaced.

Arguments

Returns

References

  1. Chen, N. et al. Metrics for Deep Generative Models. in Proceedings of the Twenty-First International Conference on Artificial Intelligence and Statistics 1540–1550 (PMLR, 2018).
  2. Chadebec, C. & Allassonnière, S. A Geometric Perspective on Variational Autoencoders. Preprint at http://arxiv.org/abs/2209.07370 (2022).
  3. Chadebec, C., Mantoux, C. & Allassonnière, S. Geometry-Aware Hamiltonian Variational Auto-Encoder. Preprint at http://arxiv.org/abs/2010.11518 (2020).
  4. Arvanitidis, G., Hauberg, S., Hennig, P. & Schober, M. Fast and Robust Shortest Paths on Manifolds Learned from Data. in Proceedings of the Twenty-Second International Conference on Artificial Intelligence and Statistics 1506–1515 (PMLR, 2019).
  5. Arvanitidis, G., Hauberg, S. & Schölkopf, B. Geometrically Enriched Latent Spaces. Preprint at https://doi.org/10.48550/arXiv.2008.00565 (2020).
  6. Arvanitidis, G., González-Duque, M., Pouplin, A., Kalatzis, D. & Hauberg, S. Pulling back information geometry. Preprint at http://arxiv.org/abs/2106.05367 (2022).
  7. Fröhlich, C., Gessner, A., Hennig, P., Schölkopf, B. & Arvanitidis, G. Bayesian Quadrature on Riemannian Data Manifolds.
  8. Kalatzis, D., Eklund, D., Arvanitidis, G. & Hauberg, S. Variational Autoencoders with Riemannian Brownian Motion Priors. Preprint at http://arxiv.org/abs/2002.05227 (2020).
  9. Arvanitidis, G., Hansen, L. K. & Hauberg, S. Latent Space Oddity: on the Curvature of Deep Generative Models. Preprint at http://arxiv.org/abs/1710.11379 (2021).
diff --git a/dev/encoders/index.html b/dev/encoders/index.html index 32b81ad..4732727 100644 --- a/dev/encoders/index.html +++ b/dev/encoders/index.html @@ -136,4 +136,4 @@ loglikelihood = sum(x .* log.(λ) - λ - loggamma.(x .+ 1)) return loglikelihood -end # function

where we use the loggamma function from SpecialFunctions.jl to compute the log of the factorial of x_i.

Warning

We only defined the decoder_loglikelihood method for z::AbstractVector. One should also include a method for z::AbstractMatrix used when performing batch training.

With these two functions defined, our PoissonDecoder is ready to be used with any of the different VAE flavors included in AutoEncoderToolkit.jl!

+end # function

where we use the loggamma function from SpecialFunctions.jl to compute the log of the factorial of x_i.

Warning

We only defined the decoder_loglikelihood method for z::AbstractVector. One should also include a method for z::AbstractMatrix used when performing batch training.

With these two functions defined, our PoissonDecoder is ready to be used with any of the different VAE flavors included in AutoEncoderToolkit.jl!

diff --git a/dev/guidelines/index.html b/dev/guidelines/index.html index 782e82e..83069bd 100644 --- a/dev/guidelines/index.html +++ b/dev/guidelines/index.html @@ -1,2 +1,2 @@ -Community Guidelines · AutoEncoderToolkit

Community Guidelines

Contributing to the Software

For those interested in contributing to AutoEncoderToolkit.jl, please refer to the GitHub repository. The project welcomes contributions to

  • Expand the list of available models.
  • Improve the performance of existing models.
  • Add new features to the toolkit.
  • Improve the documentation.

Reporting Issues or Problems

If you encounter any issues or problems with the software, you can report them directly on the GitHub repository's issues page.

Seeking Support

For support and further inquiries, consider checking the documentation and existing issues on the GitHub repository. If you still do not find the answer, you can open a new issue on the GitHub repository's issues page.

+Community Guidelines · AutoEncoderToolkit

Community Guidelines

Contributing to the Software

For those interested in contributing to AutoEncoderToolkit.jl, please refer to the GitHub repository. The project welcomes contributions to

  • Expand the list of available models.
  • Improve the performance of existing models.
  • Add new features to the toolkit.
  • Improve the documentation.

Reporting Issues or Problems

If you encounter any issues or problems with the software, you can report them directly on the GitHub repository's issues page.

Seeking Support

For support and further inquiries, consider checking the documentation and existing issues on the GitHub repository. If you still do not find the answer, you can open a new issue on the GitHub repository's issues page.

diff --git a/dev/hvae/index.html b/dev/hvae/index.html index f6eb169..5a442b9 100644 --- a/dev/hvae/index.html +++ b/dev/hvae/index.html @@ -215,4 +215,4 @@ return_outputs::Bool=false, logp_prefactor::AbstractArray=ones(Float32, 3), logq_prefactor::AbstractArray=ones(Float32, 3), -)

Compute the Hamiltonian Monte Carlo (HMC) estimate of the evidence lower bound (ELBO) for a Hamiltonian Variational Autoencoder (HVAE).

This function takes as input an HVAE and a vector of input data x. It performs K HMC steps with a leapfrog integrator and a tempering schedule to estimate the ELBO. The ELBO is computed as the difference between the log p̄ and log q̄ as

elbo = mean(log p̄ - log q̄),

Arguments

Optional Keyword Arguments

Returns

+)

Compute the Hamiltonian Monte Carlo (HMC) estimate of the evidence lower bound (ELBO) for a Hamiltonian Variational Autoencoder (HVAE).

This function takes as input an HVAE and a vector of input data x. It performs K HMC steps with a leapfrog integrator and a tempering schedule to estimate the ELBO. The ELBO is computed as the difference between the log p̄ and log q̄ as

elbo = mean(log p̄ - log q̄),

Arguments

Optional Keyword Arguments

Returns

diff --git a/dev/index.html b/dev/index.html index cfaf822..34b6bae 100644 --- a/dev/index.html +++ b/dev/index.html @@ -49,4 +49,4 @@ decoder = AutoEncoderToolkit.SimpleGaussianDecoder(deconv_layers) # Re-defining the variational autoencoder -vae = encoder * decoder

Everything else in our training pipeline would remain the same thanks to multiple dispatch.

Furthermore, let's say that we would like to use a different flavor for our variational autoencoder. In particular the InfoVAE (also known as MMD-VAE) includes extra terms in the loss function to maximize mutual information between the latent space and the input data. We can easily take our vae model and convert it into a MMDVAE-type object from the MMDVAEs submodule as follows:

mmdvae = AutoEncoderToolkit.MMDVAEs.MMDVAE(vae)

This is the power of AutoEncoderToolkit.jl and Julia's multiple dispatch!

Implemented Autoencoders

modelmoduledescription
AutoencoderAEsVanilla deterministic autoencoder
Variational AutoencoderVAEsVanilla variational autoencoder
β-VAEVAEsbeta-VAE to weigh the reconstruction vs. KL divergence in ELBO
MMD-VAEsMMDsMaximum-Mean Discrepancy Variational Autoencoders
InfoMax-VAEsInfoMaxVAEsInformation Maximization Variational Autoencoders
Hamiltonian VAEHVAEsHamiltonian Variational Autoencoders
Riemannian Hamiltonian-VAERHVAEsRiemannian-Hamiltonian Variational Autoencoder
Looking for contributors!

If you are interested in contributing to the package to add a new model, please check the GitHub repository. We are always looking to expand the list of available models. And AutoEncoderToolkit.jl's structure should make it relatively easy.

GPU support

AutoEncoderToolkit.jl supports GPU training out of the box for CUDA.jl-compatible GPUs. The CUDA functionality is provided as an extension. Therefore, to train a model on the GPU, simply import CUDA into the current environment, then move the model and data to the GPU. The rest of the training pipeline remains the same.

+vae = encoder * decoder

Everything else in our training pipeline would remain the same thanks to multiple dispatch.

Furthermore, let's say that we would like to use a different flavor for our variational autoencoder. In particular the InfoVAE (also known as MMD-VAE) includes extra terms in the loss function to maximize mutual information between the latent space and the input data. We can easily take our vae model and convert it into a MMDVAE-type object from the MMDVAEs submodule as follows:

mmdvae = AutoEncoderToolkit.MMDVAEs.MMDVAE(vae)

This is the power of AutoEncoderToolkit.jl and Julia's multiple dispatch!

Implemented Autoencoders

modelmoduledescription
AutoencoderAEsVanilla deterministic autoencoder
Variational AutoencoderVAEsVanilla variational autoencoder
β-VAEVAEsbeta-VAE to weigh the reconstruction vs. KL divergence in ELBO
MMD-VAEsMMDsMaximum-Mean Discrepancy Variational Autoencoders
InfoMax-VAEsInfoMaxVAEsInformation Maximization Variational Autoencoders
Hamiltonian VAEHVAEsHamiltonian Variational Autoencoders
Riemannian Hamiltonian-VAERHVAEsRiemannian-Hamiltonian Variational Autoencoder
Looking for contributors!

If you are interested in contributing to the package to add a new model, please check the GitHub repository. We are always looking to expand the list of available models. And AutoEncoderToolkit.jl's structure should make it relatively easy.

GPU support

AutoEncoderToolkit.jl supports GPU training out of the box for CUDA.jl-compatible GPUs. The CUDA functionality is provided as an extension. Therefore, to train a model on the GPU, simply import CUDA into the current environment, then move the model and data to the GPU. The rest of the training pipeline remains the same.

diff --git a/dev/infomaxvae/index.html b/dev/infomaxvae/index.html index 48dcf1b..cbad745 100644 --- a/dev/infomaxvae/index.html +++ b/dev/infomaxvae/index.html @@ -64,4 +64,4 @@ mlp_activations::Vector{<:Function}, output_activation::Function; init::Function = Flux.glorot_uniform -)

Constructs a default MutualInfoChain.

Arguments

Optional Keyword Arguments

Returns

Notes

The function will throw an error if the number of provided activation functions does not match the number of layers specified in mlp_neurons.

+)

Constructs a default MutualInfoChain.

Arguments

Optional Keyword Arguments

Returns

Notes

The function will throw an error if the number of provided activation functions does not match the number of layers specified in mlp_neurons.

diff --git a/dev/layers/index.html b/dev/layers/index.html index 41f2100..f82f058 100644 --- a/dev/layers/index.html +++ b/dev/layers/index.html @@ -12,4 +12,4 @@ ...

Flatten

AutoEncoderToolkit.FlattenType
Flatten()

A custom layer for Flux that flattens its input into a 1D vector.

This layer is useful when you need to change the dimensions of your data within a Flux model. Unlike the built-in flatten operation in Julia, this custom layer can be saved and loaded by packages such as BSON and JLD2.

Examples

julia> f = Flatten()
 
 julia> f(rand(5, 2))
-10-element Vector{Float64}:

Note

When saving and loading the model, make sure to include Flatten in the list of layers to be processed by BSON or JLD2.

AutoEncoderToolkit.FlattenMethod
(f::Flatten)(x)

This function is called during the forward pass of the model. It flattens the input x into a 1D vector.

Arguments

  • f::Flatten: An instance of the Flatten struct.
  • x: The input to be flattened.

Returns

The flattened input.

ActivationOverDims

AutoEncoderToolkit.ActivationOverDimsType
ActivationOverDims(σ::Function, dims::Int)

A custom layer for Flux that applies an activation function over specified dimensions.

This layer is useful when you need to apply an activation function over specific dimensions of your data within a Flux model. Unlike the built-in activation functions in Julia, this custom layer can be saved and loaded using the BSON or JLD2 package.

Arguments

  • σ::Function: The activation function to be applied.
  • dims: The dimensions over which the activation function should be applied.

Note

When saving and loading the model, make sure to include ActivationOverDims in the list of layers to be processed by BSON or JLD2.

AutoEncoderToolkit.ActivationOverDimsMethod
(σ::ActivationOverDims)(x)

This function is called during the forward pass of the model. It applies the activation function σ.σ over the dimensions σ.dims of the input x.

Arguments

  • σ::ActivationOverDims: An instance of the ActivationOverDims struct.
  • x: The input to which the activation function should be applied.

Returns

  • The input x with the activation function applied over the specified dimensions.

Note

This custom layer can be saved and loaded using the BSON package. When saving and loading the model, make sure to include ActivationOverDims in the list of layers to be processed by BSON or JLD2.

+10-element Vector{Float64}:

Note

When saving and loading the model, make sure to include Flatten in the list of layers to be processed by BSON or JLD2.

AutoEncoderToolkit.FlattenMethod
(f::Flatten)(x)

This function is called during the forward pass of the model. It flattens the input x into a 1D vector.

Arguments

  • f::Flatten: An instance of the Flatten struct.
  • x: The input to be flattened.

Returns

The flattened input.

ActivationOverDims

AutoEncoderToolkit.ActivationOverDimsType
ActivationOverDims(σ::Function, dims::Int)

A custom layer for Flux that applies an activation function over specified dimensions.

This layer is useful when you need to apply an activation function over specific dimensions of your data within a Flux model. Unlike the built-in activation functions in Julia, this custom layer can be saved and loaded using the BSON or JLD2 package.

Arguments

  • σ::Function: The activation function to be applied.
  • dims: The dimensions over which the activation function should be applied.

Note

When saving and loading the model, make sure to include ActivationOverDims in the list of layers to be processed by BSON or JLD2.

AutoEncoderToolkit.ActivationOverDimsMethod
(σ::ActivationOverDims)(x)

This function is called during the forward pass of the model. It applies the activation function σ.σ over the dimensions σ.dims of the input x.

Arguments

  • σ::ActivationOverDims: An instance of the ActivationOverDims struct.
  • x: The input to which the activation function should be applied.

Returns

  • The input x with the activation function applied over the specified dimensions.

Note

This custom layer can be saved and loaded using the BSON package. When saving and loading the model, make sure to include ActivationOverDims in the list of layers to be processed by BSON or JLD2.

diff --git a/dev/mmdvae/index.html b/dev/mmdvae/index.html index 3cbb32f..ff82d4b 100644 --- a/dev/mmdvae/index.html +++ b/dev/mmdvae/index.html @@ -20,4 +20,4 @@ n_latent_samples::Int=100, kernel=gaussian_kernel, kernel_kwargs::Union{NamedTuple,Dict}=NamedTuple(), reconstruction_loglikelihood::Function=decoder_loglikelihood -)

Function to compute the absolute ratio between the log likelihood ⟨log p(x|z)⟩ and the MMD divergence MMD-D(qᵩ(z|x)||p(z)).

Arguments

Optional Keyword Arguments

Returns

abs(⟨log p(x|z)⟩ / MMD-D(qᵩ(z|x)||p(z)))

Description

This function calculates:

  1. The log likelihood ⟨log p(x|z)⟩ of x under the MMD-VAE decoder, averaged over

all samples. 2. The MMD divergence between the encoder distribution q(z|x) and prior p(z).

The absolute ratio of these two quantities is returned.

Note

This ratio is useful for setting the Lagrangian multiplier λ in training MMD-VAEs.

+)

Function to compute the absolute ratio between the log likelihood ⟨log p(x|z)⟩ and the MMD divergence MMD-D(qᵩ(z|x)||p(z)).

Arguments

Optional Keyword Arguments

Returns

abs(⟨log p(x|z)⟩ / MMD-D(qᵩ(z|x)||p(z)))

Description

This function calculates:

  1. The log likelihood ⟨log p(x|z)⟩ of x under the MMD-VAE decoder, averaged over

all samples. 2. The MMD divergence between the encoder distribution q(z|x) and prior p(z).

The absolute ratio of these two quantities is returned.

Note

This ratio is useful for setting the Lagrangian multiplier λ in training MMD-VAEs.

diff --git a/dev/quickstart/index.html b/dev/quickstart/index.html index 28b525b..4bdcccd 100644 --- a/dev/quickstart/index.html +++ b/dev/quickstart/index.html @@ -388,4 +388,4 @@ # Save model output nng_ex[:, :, (epoch÷n_save)+1] = nng(t_array) end # if -end # for

Now that we have trained the network, we can visualize the path between the initial and final points in the latent space. The color code in the following plot matches the epoch at which the path was computed.

+end # for

Now that we have trained the network, we can visualize the path between the initial and final points in the latent space. The color code in the following plot matches the epoch at which the path was computed.

diff --git a/dev/rhvae/index.html b/dev/rhvae/index.html index 65a4070..28b02b0 100644 --- a/dev/rhvae/index.html +++ b/dev/rhvae/index.html @@ -482,4 +482,4 @@ centroids_data::AbstractArray, T::Number, λ::Number -)

Construct a Riemannian Hamiltonian Variational Autoencoder (RHVAE) from a standard VAE and a metric chain.

Arguments

Returns

Description

The constructor initializes the latent centroids and the metric tensor M to their default values. The latent centroids are initialized to a zero matrix of the same size as centroids_data, and M is initialized to a 3D array of identity matrices, one for each centroid.

+)

Construct a Riemannian Hamiltonian Variational Autoencoder (RHVAE) from a standard VAE and a metric chain.

Arguments

Returns

Description

The constructor initializes the latent centroids and the metric tensor M to their default values. The latent centroids are initialized to a zero matrix of the same size as centroids_data, and M is initialized to a 3D array of identity matrices, one for each centroid.

diff --git a/dev/utils/index.html b/dev/utils/index.html index 1af1699..a6e5e2a 100644 --- a/dev/utils/index.html +++ b/dev/utils/index.html @@ -52,4 +52,4 @@ )

Compute the finite difference gradient of a function f at a point x.

Arguments

Optional Keyword Arguments

Returns

Description

This function computes the finite difference gradient of a function f at a point x. The gradient is a vector or a matrix where the i-th element is the partial derivative of f with respect to the i-th element of x.

The partial derivatives are computed using the forward or central difference formula, depending on the fdtype argument:

where ε is the step size and eᵢ is the i-th unit vector.

GPU Support

This function supports both CPU and GPU arrays.

AutoEncoderToolkit.utils.taylordiff_gradientFunction
    taylordiff_gradient(
             f::Function,
             x::AbstractVecOrMat
-    )

Compute the gradient of a function f at a point x using Taylor series differentiation.

Arguments

  • f::Function: The function for which the gradient is to be computed. This must be a scalar function.
  • x::AbstractVecOrMat: The point at which the gradient is to be computed. Can be a vector or a matrix. If a matrix, each column represents a point where the function f is to be evaluated and the derivative computed.

Returns

  • A vector or a matrix representing the gradient of f at x, depending on the input type of x.

Description

This function computes the gradient of a function f at a point x using Taylor series differentiation. The gradient is a vector or a matrix where the i-th element or column is the partial derivative of f with respect to the i-th element of x.

The partial derivatives are computed using the TaylorDiff.derivative function.

GPU Support

This function currently only supports CPU arrays.

+ )

Compute the gradient of a function f at a point x using Taylor series differentiation.

Arguments

Returns

Description

This function computes the gradient of a function f at a point x using Taylor series differentiation. The gradient is a vector or a matrix where the i-th element or column is the partial derivative of f with respect to the i-th element of x.

The partial derivatives are computed using the TaylorDiff.derivative function.

GPU Support

This function currently only supports CPU arrays.

diff --git a/dev/vae/index.html b/dev/vae/index.html index c0dc700..05c18b8 100644 --- a/dev/vae/index.html +++ b/dev/vae/index.html @@ -37,4 +37,4 @@ )`

Customized training function to update parameters of a variational autoencoder given a loss function.

Arguments

Optional Keyword Arguments

Description

Trains the VAE by:

  1. Computing the gradient of the loss w.r.t the VAE parameters.
  2. Updating the VAE parameters using the optimizer.

Examples

opt = Flux.setup(Optax.adam(1e-3), vae)
 for (x_in, x_out) in dataloader
         train!(vae, x_in, x_out, opt) 
-end
+end