diff --git a/Manifest.toml b/Manifest.toml index db9101d..dee3191 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -132,6 +132,12 @@ git-tree-sha1 = "ed720e2622820bf584d4ad90e6fcb93d95170b44" uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9" version = "0.1.3" +[[CSV]] +deps = ["Dates", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode"] +git-tree-sha1 = "b83aa3f513be680454437a0eee21001607e5d983" +uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" +version = "0.8.5" + [[ChainRules]] deps = ["ChainRulesCore", "Compat", "LinearAlgebra", "Random", "Statistics"] git-tree-sha1 = "0902fc7f416c8f1e3b1e014786bb65d0c2241a9b" @@ -269,6 +275,12 @@ git-tree-sha1 = "bec2532f8adb82005476c141ec23e921fc20971b" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" version = "1.8.0" +[[DataFrames]] +deps = ["Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] +git-tree-sha1 = "d785f42445b63fc86caa08bb9a9351008be9b765" +uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +version = "1.2.2" + [[DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02" @@ -835,6 +847,12 @@ git-tree-sha1 = "371a19bb801c1b420b29141750f3a34d6c6634b9" uuid = "1d0040c9-8b98-4ee7-8388-3f51789ca0ad" version = "0.1.0" +[[PooledArrays]] +deps = ["DataAPI", "Future"] +git-tree-sha1 = "a193d6ad9c45ada72c14b731a318bedd3c2f00cf" +uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" +version = "1.3.0" + [[Preferences]] deps = ["TOML"] git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a" @@ -959,6 +977,12 @@ git-tree-sha1 = "9c1a0dea3b442024c54ca6a318e8acf842eab06f" uuid = "30f210dd-8aff-4c5f-94ba-8e64358c1161" version = "2.2.0" +[[SentinelArrays]] +deps = ["Dates", "Random"] +git-tree-sha1 = "54f37736d8934a12a200edea2f9206b03bdf3159" +uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c" +version = "1.3.7" + [[Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" @@ -1119,7 +1143,7 @@ uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" version = "0.18.0" [[TuringDash]] -deps = ["Dash", "DashBootstrapComponents", "DashCoreComponents", "DashHtmlComponents", "PlotlyJS", "Turing"] +deps = ["CSV", "Dash", "DashBootstrapComponents", "DashCoreComponents", "DashHtmlComponents", "DataFrames", "PlotlyJS", "Random", "Turing"] path = "TuringDash" uuid = "ff11d773-741b-488a-a49d-ae0d842bee15" version = "0.1.0" diff --git a/Project.toml b/Project.toml index 2237272..b39b7b8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,3 +1,4 @@ [deps] +Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" TuringDash = "ff11d773-741b-488a-a49d-ae0d842bee15" diff --git a/TuringDash/src/TuringDash.jl b/TuringDash/src/TuringDash.jl index ff2d0cd..da60463 100644 --- a/TuringDash/src/TuringDash.jl +++ b/TuringDash/src/TuringDash.jl @@ -1,6 +1,5 @@ module TuringDash - include("render_funcs.jl") include("utils.jl") using Dash, DashBootstrapComponents @@ -31,7 +30,8 @@ function make_app() y_graph1 = [] itr = 0 df = nothing - + nperiteration = 1 + external_stylesheets = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" app = dash(external_stylesheets=[dbc_themes.BOOTSTRAP,external_stylesheets], suppress_callback_exceptions=true) @@ -70,30 +70,32 @@ function make_app() if (user_funcs == "") || (funcs_init == "") throw(PreventUpdate()) end - + x_graph = [] y_graph = [] y_graph1 = [] itr = 0 - + for colname in Symbol.(names(df)) @eval $colname = df.$colname - end - #evealuate model + end + # evealuate model eval(Meta.parse(user_funcs)) #evaluate eval_definition model = eval(Meta.parse(funcs_init)) - alg = MH() + alg = MH( + [0.25 0.05; + 0.05 0.50] + ) rng = Random.GLOBAL_RNG - nperiteration = 5 nsamples = 1000 @async begin r = sample(rng, model, alg, nperiteration; chain_type=MCMCChains.Chains, save_state=true, progress=false) put!(chn, Array(r)[end,1:2]) - for i in (nperiteration + 1):nperiteration:nsamples + for _ in (nperiteration + 1):nperiteration:nsamples r = Turing.Inference.resume(r, nperiteration, save_state=true, progress=false) put!(chn, Array(r)[end,1:2]) end @@ -114,7 +116,7 @@ function make_app() global x_graph, y_graph, y_graph1, chn, itr if isready(chn) val = take!(chn) - itr += 5 + itr += nperiteration append!(x_graph, itr) append!(y_graph, val[1]) append!(y_graph1, val[2]) diff --git a/TuringDash/src/render_funcs.jl b/TuringDash/src/render_funcs.jl index 597b72e..a2a79a7 100644 --- a/TuringDash/src/render_funcs.jl +++ b/TuringDash/src/render_funcs.jl @@ -6,7 +6,7 @@ function render_all() dbc_row([ render_func_init(), dbc_col([ - dbc_button("Sample !", color="success", id="dtu-btn-turing") + dbc_button("Sample", color="success", id="dtu-btn-turing") ], md =2), render_plots() ]) @@ -17,12 +17,12 @@ function render_info() dbc_jumbotron([ html_h1("Dash Turing App", className="dtu-display-3"), html_p( - "Web app for Bayesian inference using Dash.jl and Turing.jl ", + "Web app for Bayesian inference using Dash.jl and Turing.jl ", className="lead", ), html_hr(className="my-2"), html_p( - "User can define Turing model", + "User can define a Turing model. The dataset's column names are available as variable names.", ) ]) ]) @@ -39,7 +39,7 @@ end function render_function() return dbc_card([ dbc_cardbody([ - html_h4("Model specification", className="card-title"), + html_h4("Model specification:", className="card-title"), html_div([ dbc_textarea( id = "dtu-user-funcs", @@ -47,10 +47,10 @@ function render_function() className="mb-3", rows = 6, value=""" - @model turingmodel(x, y) = begin + @model regression_model(x, y) = begin a ~ Normal() b ~ Normal() - for i in 1:length(x) + for i in 1:10 y[i] ~ Normal(a + b * x[i], 1.0) end end @@ -63,13 +63,13 @@ end function render_init() return dbc_card([ dbc_cardbody([ - html_h4("Conditional Model", className="card-title"), + html_h4("Conditional model:", className="card-title"), html_div([ dbc_input( id = "dtu-user-func-init", bs_size="lg", className="mb-3", - value="turingmodel(x, y)", + value="regression_model(x, y)", ) ]), ]) @@ -83,7 +83,7 @@ function render_uploader() html_div( id="dtu-def-upload-data", [ - html_label("Select a default dataset:") + html_label("Select a dataset:") dcc_dropdown( id="dtu-def-data-drop", options =[ @@ -96,7 +96,7 @@ function render_uploader() ) ], ), - html_h3("OR"), + html_h3("or"), dcc_upload( id="dtu-upload-datan", children=html_div([ diff --git a/precompile_funcs.jl b/precompile_funcs.jl index 88f634d..8e84965 100644 --- a/precompile_funcs.jl +++ b/precompile_funcs.jl @@ -1,8 +1,9 @@ module PrecompileFuncs - using TuringDash - using TuringDash.Turing - using TuringDash.Random - using TuringDash.CSV, TuringDash.DataFrames + +using TuringDash +using TuringDash.Turing +using TuringDash.Random +using TuringDash.CSV, TuringDash.DataFrames function precompile_turing() chn = Base.Channel{Vector{Float64}}(Inf) @@ -10,15 +11,15 @@ function precompile_turing() global df1 df1 = CSV.read(download("https://raw.githubusercontent.com/efmanu/TuringDashApp.jl/master/TuringDash/datasets/data1.csv"), DataFrame) model_str1 = """ - @model turingmodel(x, y) = begin + @model regression_model(x, y) = begin a ~ Normal() b ~ Normal() - for i in 1:length(x) + for i in 1:10 y[i] ~ Normal(a + b * x[i], 1.0) end end """ - model_str2 = "turingmodel(x, y)" + model_str2 = "regression_model(x, y)" for colname in Symbol.(names(df1)) @eval $colname = df1.$colname end @@ -26,7 +27,10 @@ function precompile_turing() eval(Meta.parse(model_str1)) model = eval(Meta.parse(model_str2)) - alg = MH() + alg = MH( + [0.25 0.05; + 0.05 0.50] + ) rng = Random.GLOBAL_RNG nperiteration = 50 @@ -40,4 +44,5 @@ function precompile_turing() end return "success" end + end \ No newline at end of file