Last active
May 24, 2023 19:15
-
-
Save itsdfish/6ad91dbb3008056bf2656f22d16e30ed to your computer and use it in GitHub Desktop.
Discrete normalizing flow attemp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Distributions | |
function sample_prior() | |
return rand(Beta(1, 1)) | |
end | |
function generate_data() | |
θ = sample_prior() | |
y = rand(Binomial(10, θ)) | |
return [θ,y] | |
end | |
# train using samples from joint distribution x,y ~ p(x,y) where x=[μ, σ] -> y = N(μ, σ) | |
# rows: μ, σ, y | |
num_params = 1; num_obs = 1; n_train = 10000 | |
training_data = mapreduce(x -> generate_data(), hcat, 1:n_train); | |
############ train some data | |
X_train = reshape(training_data[1:num_params,:], (1,1,num_params,:)); | |
Y_train = reshape(training_data[(num_params+1):end,:], (1,1,num_obs,:)); | |
n_epochs = 2 | |
batch_size = 200 | |
n_batches = div(n_train, batch_size) | |
# make conditional normalizing flow | |
using InvertibleNetworks, LinearAlgebra, Flux | |
L = 3 # RealNVP multiscale layers | |
K = 4 # Coupling layers per scale | |
n_hidden = 32 # Hidden channels in coupling layers' neural network | |
G = NetworkConditionalGlow(num_params, num_obs, n_hidden, L, K;); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment