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 @@ -Home · EnergySamplers.jl
+Home · EnergySamplers.jl

EnergySamplers

Documentation for EnergySamplers.

EnergySamplers.AbstractSamplerMethod
(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.
source
EnergySamplers.ConditionalSamplerMethod
ConditionalSampler(
+    𝒟x::Distribution, 𝒟y::Distribution;
+    input_size::Dims, batch_size::Int,
+    max_len::Int=10000, prob_buffer::AbstractFloat=0.95
+)

Outer constructor for ConditionalSampler.

source
EnergySamplers.JointSamplerType
JointSampler <: AbstractSampler

Generates unconditional samples by drawing directly from joint distribution: $x \sim p(x, y).$

source
EnergySamplers.JointSamplerMethod
JointSampler(
+    𝒟x::Distribution, 𝒟y::Distribution, input_size::Dims, batch_size::Int;
+    max_len::Int=10000, prob_buffer::AbstractFloat=0.95
+)

Outer constructor for JointSampler.

source
EnergySamplers.SGLDType
SGLD(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)
source
EnergySamplers.UnconditionalSamplerMethod
UnconditionalSampler(
+    𝒟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.

source
EnergySamplers.PMCMethod
PMC(
+    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.
source
EnergySamplers._energyMethod
energy(f, x, y::Int; agg=mean)

Computes the energy for conditional samples $x \sim p_{\theta}(x|y)$: $E(x)=- f_{\theta}(x)[y]$.

source
EnergySamplers._energyMethod
energy(f, x)

Computes the energy for unconditional samples $x \sim p_{\theta}(x)$: $E(x)=-\text{LogSumExp}_y f_{\theta}(x)[y]$.

source
EnergySamplers.mcmc_samplesMethod
mcmc_samples(
+    sampler::ConditionalSampler,
+    model,
+    rule::Optimisers.AbstractRule,
+    input_samples::AbstractArray;
+    niter::Int,
+    y::Union{Nothing,Int} = nothing,
+)

Sampling method for ConditionalSampler.

source
EnergySamplers.mcmc_samplesMethod
mcmc_samples(
+    sampler::JointSampler,
+    model,
+    rule::Optimisers.AbstractRule,
+    input_samples::AbstractArray;
+    niter::Int,
+    y::Union{Nothing,Int} = nothing,
+)

Sampling method for JointSampler.

source
EnergySamplers.mcmc_samplesMethod
mcmc_samples(
+    sampler::UnconditionalSampler,
+    model,
+    rule::Optimisers.AbstractRule,
+    input_samples::AbstractArray;
+    niter::Int,
+    y::Union{Nothing,Int} = nothing,
+)

Sampling method for UnconditionalSampler.

source
diff --git a/dev/objects.inv b/dev/objects.inv index aaf8d80..f774f03 100644 Binary files a/dev/objects.inv and b/dev/objects.inv differ diff --git a/dev/search_index.js b/dev/search_index.js index 0f82e1b..aad064a 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"","page":"Home","title":"Home","text":"CurrentModule = EnergySamplers","category":"page"},{"location":"#EnergySamplers","page":"Home","title":"EnergySamplers","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Documentation for EnergySamplers.","category":"page"},{"location":"","page":"Home","title":"Home","text":"","category":"page"},{"location":"","page":"Home","title":"Home","text":"Modules = [EnergySamplers]","category":"page"}] +[{"location":"","page":"Home","title":"Home","text":"CurrentModule = EnergySamplers","category":"page"},{"location":"#EnergySamplers","page":"Home","title":"EnergySamplers","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Documentation for EnergySamplers.","category":"page"},{"location":"","page":"Home","title":"Home","text":"","category":"page"},{"location":"","page":"Home","title":"Home","text":"Modules = [EnergySamplers]","category":"page"},{"location":"#EnergySamplers.AbstractSampler","page":"Home","title":"EnergySamplers.AbstractSampler","text":"Base type for samplers.\n\n\n\n\n\n","category":"type"},{"location":"#EnergySamplers.AbstractSampler-Tuple{Any, AbstractSamplingRule}","page":"Home","title":"EnergySamplers.AbstractSampler","text":"(sampler::AbstractSampler)(\n model,\n rule::AbstractSamplingRule;\n niter::Int = 100,\n clip_grads::Union{Nothing,AbstractFloat} = 1e-2,\n n_samples::Union{Nothing,Int} = nothing,\n kwargs...,\n)\n\nSampling method for AbstractSampler. This method generates samples from the model's learned distribution. \n\nArguments\n\nsampler::AbstractSampler: The sampler to use.\nmodel: The model to sample from.\nrule::AbstractSamplingRule: The sampling rule to use.\nniter::Int=100: The number of iterations to perform.\nclip_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.\nn_samples::Union{Nothing,Int}=nothing: The number of samples to generate.\nkwargs...: Additional keyword arguments.\n\nReturns\n\ninput_samples: The samples generated by the sampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.AbstractSamplingRule","page":"Home","title":"EnergySamplers.AbstractSamplingRule","text":"Base type for sampling rules.\n\n\n\n\n\n","category":"type"},{"location":"#EnergySamplers.ConditionalSampler","page":"Home","title":"EnergySamplers.ConditionalSampler","text":"ConditionalSampler <: AbstractSampler\n\nGenerates conditional samples: x sim p(xy)\n\n\n\n\n\n","category":"type"},{"location":"#EnergySamplers.ConditionalSampler-Tuple{Distributions.Distribution, Distributions.Distribution}","page":"Home","title":"EnergySamplers.ConditionalSampler","text":"ConditionalSampler(\n 𝒟x::Distribution, 𝒟y::Distribution;\n input_size::Dims, batch_size::Int,\n max_len::Int=10000, prob_buffer::AbstractFloat=0.95\n)\n\nOuter constructor for ConditionalSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.ImproperSGLD","page":"Home","title":"EnergySamplers.ImproperSGLD","text":"ImproperSGLD(α::Real=2.0, σ::Real=0.01)\n\nImproper SGLD optimizer.\n\nExamples\n\nopt = ImproperSGLD()\n\n\n\n\n\n","category":"type"},{"location":"#EnergySamplers.JointSampler","page":"Home","title":"EnergySamplers.JointSampler","text":"JointSampler <: AbstractSampler\n\nGenerates unconditional samples by drawing directly from joint distribution: x sim p(x y)\n\n\n\n\n\n","category":"type"},{"location":"#EnergySamplers.JointSampler-Tuple{Distributions.Distribution, Distributions.Distribution}","page":"Home","title":"EnergySamplers.JointSampler","text":"JointSampler(\n 𝒟x::Distribution, 𝒟y::Distribution, input_size::Dims, batch_size::Int;\n max_len::Int=10000, prob_buffer::AbstractFloat=0.95\n)\n\nOuter constructor for JointSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.SGLD","page":"Home","title":"EnergySamplers.SGLD","text":"SGLD(a::Real=1.0, b::Real=1.0, γ::Real=0.5)\n\nStochastic Gradient Langevin Dynamics (SGLD) optimizer.\n\nExamples\n\nopt = SGLD()\nopt = SGLD(2.0, 100.0, 0.9)\n\n\n\n\n\n","category":"type"},{"location":"#EnergySamplers.UnconditionalSampler","page":"Home","title":"EnergySamplers.UnconditionalSampler","text":"UnonditionalSampler <: AbstractSampler\n\nGenerates unconditional samples: x sim p(x)\n\n\n\n\n\n","category":"type"},{"location":"#EnergySamplers.UnconditionalSampler-Tuple{Distributions.Distribution, Union{Nothing, Distributions.Distribution}}","page":"Home","title":"EnergySamplers.UnconditionalSampler","text":"UnconditionalSampler(\n 𝒟x::Distribution,\n 𝒟y::Union{Distribution,Nothing};\n input_size::Dims,\n batch_size::Int = 1,\n max_len::Int = 10000,\n prob_buffer::AbstractFloat = 0.95,\n)\n\nOuter constructor for UnonditionalSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.PMC-Tuple{AbstractSampler, Any, AbstractSamplingRule}","page":"Home","title":"EnergySamplers.PMC","text":"PMC(\n sampler::AbstractSampler,\n model,\n rule::AbstractSamplingRule;\n ntransitions::Int = 100,\n niter::Int = 100,\n kwargs...,\n)\n\nRuns 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. \n\nIn 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. \n\nNote\n\nThis 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.\n\nArguments\n\nsampler::AbstractSampler: The sampler to use.\nmodel: The model to sample from.\nrule::AbstractSamplingRule: The sampling rule to use.\nntransitions::Int=100: The number of transitions to perform.\nniter::Int=100: The number of iterations to perform.\nkwargs...: Additional keyword arguments.\n\nReturns\n\nsampler.buffer: The buffer containing the samples generated by the sampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers._energy-Tuple{Any, Any, Int64}","page":"Home","title":"EnergySamplers._energy","text":"energy(f, x, y::Int; agg=mean)\n\nComputes the energy for conditional samples x sim p_theta(xy): E(x)=- f_theta(x)y.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers._energy-Tuple{Any, Any}","page":"Home","title":"EnergySamplers._energy","text":"energy(f, x)\n\nComputes the energy for unconditional samples x sim p_theta(x): E(x)=-textLogSumExp_y f_theta(x)y.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.energy-Tuple{ConditionalSampler, Any, Any, Any}","page":"Home","title":"EnergySamplers.energy","text":"energy(sampler::ConditionalSampler, model, x, y)\n\nEnergy function for ConditionalSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.energy-Tuple{JointSampler, Any, Any, Any}","page":"Home","title":"EnergySamplers.energy","text":"energy(sampler::JointSampler, model, x, y)\n\nEnergy function for JointSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.energy-Tuple{UnconditionalSampler, Any, Any, Any}","page":"Home","title":"EnergySamplers.energy","text":"energy(sampler::UnconditionalSampler, model, x, y)\n\nEnergy function for UnconditionalSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.mcmc_samples-Tuple{ConditionalSampler, Any, Optimisers.AbstractRule, AbstractArray}","page":"Home","title":"EnergySamplers.mcmc_samples","text":"mcmc_samples(\n sampler::ConditionalSampler,\n model,\n rule::Optimisers.AbstractRule,\n input_samples::AbstractArray;\n niter::Int,\n y::Union{Nothing,Int} = nothing,\n)\n\nSampling method for ConditionalSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.mcmc_samples-Tuple{JointSampler, Any, Optimisers.AbstractRule, AbstractArray}","page":"Home","title":"EnergySamplers.mcmc_samples","text":"mcmc_samples(\n sampler::JointSampler,\n model,\n rule::Optimisers.AbstractRule,\n input_samples::AbstractArray;\n niter::Int,\n y::Union{Nothing,Int} = nothing,\n)\n\nSampling method for JointSampler.\n\n\n\n\n\n","category":"method"},{"location":"#EnergySamplers.mcmc_samples-Tuple{UnconditionalSampler, Any, Optimisers.AbstractRule, AbstractArray}","page":"Home","title":"EnergySamplers.mcmc_samples","text":"mcmc_samples(\n sampler::UnconditionalSampler,\n model,\n rule::Optimisers.AbstractRule,\n input_samples::AbstractArray;\n niter::Int,\n y::Union{Nothing,Int} = nothing,\n)\n\nSampling method for UnconditionalSampler.\n\n\n\n\n\n","category":"method"}] }