EnergySamplers
Documentation for EnergySamplers.
diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 91194f4..de2bf47 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-05T12:56:30","documenter_version":"1.7.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-05T14:40:55","documenter_version":"1.7.0"}} \ No newline at end of file diff --git a/dev/index.html b/dev/index.html index b635ecc..ed56a36 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,52 @@ -
Documentation for EnergySamplers.
Settings
This document was generated with Documenter.jl version 1.7.0 on Thursday 5 September 2024. Using Julia version 1.10.5.
Documentation for EnergySamplers.
EnergySamplers.AbstractSampler
EnergySamplers.AbstractSampler
EnergySamplers.AbstractSamplingRule
EnergySamplers.ConditionalSampler
EnergySamplers.ConditionalSampler
EnergySamplers.ImproperSGLD
EnergySamplers.JointSampler
EnergySamplers.JointSampler
EnergySamplers.SGLD
EnergySamplers.UnconditionalSampler
EnergySamplers.UnconditionalSampler
EnergySamplers.PMC
EnergySamplers._energy
EnergySamplers._energy
EnergySamplers.energy
EnergySamplers.energy
EnergySamplers.energy
EnergySamplers.mcmc_samples
EnergySamplers.mcmc_samples
EnergySamplers.mcmc_samples
EnergySamplers.AbstractSampler
— TypeBase type for samplers.
EnergySamplers.AbstractSampler
— Method(sampler::AbstractSampler)(
+ model,
+ rule::AbstractSamplingRule;
+ niter::Int = 100,
+ clip_grads::Union{Nothing,AbstractFloat} = 1e-2,
+ n_samples::Union{Nothing,Int} = nothing,
+ kwargs...,
+)
Sampling method for AbstractSampler
. This method generates samples from the model's learned distribution.
Arguments
sampler::AbstractSampler
: The sampler to use.model
: The model to sample from.rule::AbstractSamplingRule
: The sampling rule to use.niter::Int=100
: The number of iterations to perform.clip_grads::Union{Nothing,AbstractFloat}=nothing
: The value to clip the gradients. This is useful to prevent exploding gradients when training joint energy models. If nothing
, no clipping is performed.n_samples::Union{Nothing,Int}=nothing
: The number of samples to generate.kwargs...
: Additional keyword arguments.Returns
input_samples
: The samples generated by the sampler.EnergySamplers.AbstractSamplingRule
— TypeBase type for sampling rules.
EnergySamplers.ConditionalSampler
— TypeConditionalSampler <: AbstractSampler
Generates conditional samples: $x \sim p(x|y).$
EnergySamplers.ConditionalSampler
— MethodConditionalSampler(
+ 𝒟x::Distribution, 𝒟y::Distribution;
+ input_size::Dims, batch_size::Int,
+ max_len::Int=10000, prob_buffer::AbstractFloat=0.95
+)
Outer constructor for ConditionalSampler
.
EnergySamplers.ImproperSGLD
— TypeEnergySamplers.JointSampler
— TypeJointSampler <: AbstractSampler
Generates unconditional samples by drawing directly from joint distribution: $x \sim p(x, y).$
EnergySamplers.JointSampler
— MethodJointSampler(
+ 𝒟x::Distribution, 𝒟y::Distribution, input_size::Dims, batch_size::Int;
+ max_len::Int=10000, prob_buffer::AbstractFloat=0.95
+)
Outer constructor for JointSampler
.
EnergySamplers.SGLD
— TypeSGLD(a::Real=1.0, b::Real=1.0, γ::Real=0.5)
Stochastic Gradient Langevin Dynamics (SGLD) optimizer.
Examples
opt = SGLD()
+opt = SGLD(2.0, 100.0, 0.9)
EnergySamplers.UnconditionalSampler
— TypeUnonditionalSampler <: AbstractSampler
Generates unconditional samples: $x \sim p(x).$
EnergySamplers.UnconditionalSampler
— MethodUnconditionalSampler(
+ 𝒟x::Distribution,
+ 𝒟y::Union{Distribution,Nothing};
+ input_size::Dims,
+ batch_size::Int = 1,
+ max_len::Int = 10000,
+ prob_buffer::AbstractFloat = 0.95,
+)
Outer constructor for UnonditionalSampler
.
EnergySamplers.PMC
— MethodPMC(
+ sampler::AbstractSampler,
+ model,
+ rule::AbstractSamplingRule;
+ ntransitions::Int = 100,
+ niter::Int = 100,
+ kwargs...,
+)
Runs a Persistent Markov Chain (PMC) using the sampler and model. Persistent Markov Chains are used, for example, for Persistent Contrastive Convergence (Tieleman (2008)), a variant of the Contrastive Divergence (CD) algorithm. The main difference is that PCD uses a persistent chain to estimate the negative phase of the gradient. This is done by keeping the state of the Markov chain between iterations.
In our context, the sampler is the persistent chain and the model is a supervised model. The sampler generates samples from the model's learned distribution.
Note
This function does not perform any training. It only generates samples from the model. In other words, there is no Contrastive Divergence. For training Joint Energy Models, see JointEnergyModels.jl.
Arguments
sampler::AbstractSampler
: The sampler to use.model
: The model to sample from.rule::AbstractSamplingRule
: The sampling rule to use.ntransitions::Int=100
: The number of transitions to perform.niter::Int=100
: The number of iterations to perform.kwargs...
: Additional keyword arguments.Returns
sampler.buffer
: The buffer containing the samples generated by the sampler.EnergySamplers._energy
— Methodenergy(f, x, y::Int; agg=mean)
Computes the energy for conditional samples $x \sim p_{\theta}(x|y)$: $E(x)=- f_{\theta}(x)[y]$.
EnergySamplers._energy
— Methodenergy(f, x)
Computes the energy for unconditional samples $x \sim p_{\theta}(x)$: $E(x)=-\text{LogSumExp}_y f_{\theta}(x)[y]$.
EnergySamplers.energy
— Methodenergy(sampler::ConditionalSampler, model, x, y)
Energy function for ConditionalSampler
.
EnergySamplers.energy
— Methodenergy(sampler::JointSampler, model, x, y)
Energy function for JointSampler
.
EnergySamplers.energy
— Methodenergy(sampler::UnconditionalSampler, model, x, y)
Energy function for UnconditionalSampler
.
EnergySamplers.mcmc_samples
— Methodmcmc_samples(
+ sampler::ConditionalSampler,
+ model,
+ rule::Optimisers.AbstractRule,
+ input_samples::AbstractArray;
+ niter::Int,
+ y::Union{Nothing,Int} = nothing,
+)
Sampling method for ConditionalSampler
.
EnergySamplers.mcmc_samples
— Methodmcmc_samples(
+ sampler::JointSampler,
+ model,
+ rule::Optimisers.AbstractRule,
+ input_samples::AbstractArray;
+ niter::Int,
+ y::Union{Nothing,Int} = nothing,
+)
Sampling method for JointSampler
.
EnergySamplers.mcmc_samples
— Methodmcmc_samples(
+ sampler::UnconditionalSampler,
+ model,
+ rule::Optimisers.AbstractRule,
+ input_samples::AbstractArray;
+ niter::Int,
+ y::Union{Nothing,Int} = nothing,
+)
Sampling method for UnconditionalSampler
.
Settings
This document was generated with Documenter.jl version 1.7.0 on Thursday 5 September 2024. Using Julia version 1.10.5.