From fe6ca0140228bc45da14857566af86f72140f38c Mon Sep 17 00:00:00 2001 From: Scott Lawrence Date: Sat, 22 Jun 2024 21:59:53 -0700 Subject: Progress toward MCMC --- src/Bayes.jl | 3 +++ src/MonteCarlo.jl | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/NeuralNetworks.jl | 41 +++++++++++++++++++++++++++++++++++++++++ src/Vatic.jl | 18 +++++++++++++++--- 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 src/Bayes.jl create mode 100644 src/NeuralNetworks.jl (limited to 'src') diff --git a/src/Bayes.jl b/src/Bayes.jl new file mode 100644 index 0000000..c40f1ab --- /dev/null +++ b/src/Bayes.jl @@ -0,0 +1,3 @@ +module Bayes + +end diff --git a/src/MonteCarlo.jl b/src/MonteCarlo.jl index 5d87834..6c7251f 100644 --- a/src/MonteCarlo.jl +++ b/src/MonteCarlo.jl @@ -1,6 +1,50 @@ module MonteCarlo +abstract type Proposer end + +struct GaussianProposer + σ::Float64 +end + +function (prop::GaussianProposer)(x::Vector{Float64}) + for i in length(x) + x += prop.σ * randn() + end +end + +abstract type Distribution end + struct MarkovChain + dist::Distribution + prop!::Proposer + x::Vector{Float64} + logp::Float64 + x′::Vector{Float64} +end + +function step!(mc::MarkovChain)::Bool + x′ .= x + mc.prop!(x′) + logp′ = mc.dist(x′) + # TODO distribution +end + +function calibrate!(mc::MarkovChain) + while true + for s in 1:100 + acc += step!(mc) + end + if acc < 30 + # TODO + elseif acc > 50 + # TODO + else + break + end + end +end + +struct HamiltonianMonteCarlo end end diff --git a/src/NeuralNetworks.jl b/src/NeuralNetworks.jl new file mode 100644 index 0000000..7bc9c5d --- /dev/null +++ b/src/NeuralNetworks.jl @@ -0,0 +1,41 @@ +module NeuralNetworks + +struct Linear + W::Matrix{Float64} + b::Vector{Float64} +end + +function (l::Linear)(x::Vector{Float64}) +end + +struct Activation +end + +struct MLP +end + +struct AffineCoupling +end + +function (f::AffineCoupling)(x::Vector{Float64})::Float64 + return 0. +end + +struct RealNVP + layers::Vector{AffineCoupling} + + function RealNVP() + layers = Vector{AffineCoupling}() + new(layers) + end +end + +function (f::RealNVP)(x::Vector{Float64})::Float64 + ldJ::Float64 = 0. + for l! in f.layers + ldJ += l!(x) + end + return ldJ +end + +end diff --git a/src/Vatic.jl b/src/Vatic.jl index 51abad3..3400a87 100644 --- a/src/Vatic.jl +++ b/src/Vatic.jl @@ -2,8 +2,11 @@ module Vatic include("Data.jl") +include("NeuralNetworks.jl") include("MonteCarlo.jl") +include("Bayes.jl") + include("platforms/Manifold.jl") include("platforms/Metaculus.jl") @@ -14,13 +17,22 @@ function main() args = let s = ArgParseSettings() @add_arg_table s begin + "--sources" + default = "sources.toml" + arg_type = String + "-i","--interactive" + action = :store_true end parse_args(s) end - term = REPL.Terminals.TTYTerminal("dumb", stdin, stdout, stderr) - repl = REPL.LineEditREPL(term, true) - REPL.run_repl(repl) + index = Data.Index(args["sources"]) + + if args["interactive"] + term = REPL.Terminals.TTYTerminal("dumb", stdin, stdout, stderr) + repl = REPL.LineEditREPL(term, true) + REPL.run_repl(repl) + end end end -- cgit v1.2.3-54-g00ecf