You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I try to compile an app to predict bayesian model . I saved posterior chain, and model specification. My precomp_file is something like that.
precomp_file.jl
using Turing
using Distributions
using LinearAlgebra
using DataFrames
using CSV
using StatsBase
using Tracker
using MKL
using Bijectors
import Logging
Logging.disable_logging(Logging.Warn)
# El objetivo es precompilar las funciones para# que la app vaya rápido## Leer cadena y especificación modelo
chain_path ="/home/jose/Julia_projects/bayesian_app/resources/cadena_refactor.jls"# al hacer include dentro de la app mira por defecto en src
esp_modelo_path ="/home/jose/Julia_projects/bayesian_app/src/especificacion_modelo_refactor.jl"
df_path ="/home/jose/Julia_projects/bayesian_app/resources/Advertising.csv"
chain =read(chain_path, Chains)
df = CSV.read(df_path, DataFrame, ntasks=10)
include(esp_modelo_path)
## predecir
predicciones =predict(model_turing(df ), chain)
pred_df =DataFrame(predicciones)
pred_df = pred_df[!, Not([:iteration, :chain])]
medias =mean.(eachcol(pred_df))
mediana =quantile.(eachcol(pred_df), 0.5)
desv_ti =std.(eachcol(pred_df))
q01 =quantile.(eachcol(pred_df), 0.1)
q90 =quantile.(eachcol(pred_df), 0.9)
pred_interval =DataFrame(hcat(medias, mediana, desv_ti, q01, q90), :auto)
rename!(pred_interval,[:means,:median , :std, :q01, :q90])
CSV.write("data/predicciones.csv", pred_interval)
where especificacion_modelo_refactor.jl is a julia script only with model turing specification
@modelfunctionmodel_turing(df)
TV = df.TV
radio = df.radio
newspaper = df.newspaper
# Prior coeficientes
a ~Normal(0, 0.5)
tv_coef ~Normal(0, 0.5)
radio_coef ~Normal(0, 0.5)
newspaper_coef ~Normal(0, 0.5)
σ₁ ~Gamma(1, 1)
mu = a .+ tv_coef .* TV .+ radio_coef .* radio .+ newspaper_coef .* newspaper
sales ~MvNormal(mu, σ₁^2* I)
end
My app file is something like that.
module bayesian_app
using Turing
using Distributions
using LinearAlgebra
using DataFrames
using CSV
using StatsBase
using Tracker
using MKL
functionjulia_main()::Cinttryreal_main()
catch
Base.invokelatest(Base.display_error, Base.catch_stack())
return1endreturn0endfunctionreal_main()
iflength(ARGS) ==0error("pass arguments")
end# Read chain
chain =read(ARGS[1], Chains)
# Read model_espec in julia scriptinclude(ARGS[2])
# read data
df = CSV.read(ARGS[3], DataFrame, ntasks=10)
# Predict
predicciones =predict(model_turing(df), chain )
pred_df =DataFrame(predicciones)
pred_df = pred_df[!, Not([:iteration, :chain])]
medias =mean.(eachcol(pred_df))
mediana =quantile.(eachcol(pred_df), 0.5)
desv_ti =std.(eachcol(pred_df))
q01 =quantile.(eachcol(pred_df), 0.1)
q90 =quantile.(eachcol(pred_df), 0.9)
pred_interval =DataFrame(hcat(medias, mediana, desv_ti, q01, q90), :auto)
rename!(pred_interval,[:means,:median , :std, :q01, :q90])
CSV.write("pred_interval_80.csv", pred_interval)
CSV.write("pred_posterior.csv", pred_df)
endend# module
And get the compile, once I install some dpendencies like Tracker.jl an others.
I try to test my app passing a mcmc chain, a julia file where I wrote the model especification , but I get weird error message
../bayesian_bin_predict/bin/bayesian_app cadena_refactor.jls especificacion_modelo_refactor.jl Advertising.csv
┌ Warning: Package Bijectors does not have ChainRulesCore in its dependencies:
│ - If you have Bijectors checked out for development and have
│ added ChainRulesCore as a dependency but haven't updated your primary│ environment's manifest file, try `Pkg.resolve()`.│ - Otherwise you may need to report an issue with Bijectors└ Loading ChainRulesCore into Bijectors from project dependency, future warnings for Bijectors are suppressed.┌ Warning: Error requiring `Tracker` from `Bijectors`
But when I see Manifest and Project I view Tracker.jl and Bijectors.
Any idea?
Thanks
The text was updated successfully, but these errors were encountered:
Hi. I try to compile an app to predict bayesian model . I saved posterior chain, and model specification. My precomp_file is something like that.
precomp_file.jl
where especificacion_modelo_refactor.jl is a julia script only with model turing specification
My app file is something like that.
And I try to compile using
And get the compile, once I install some dpendencies like Tracker.jl an others.
I try to test my app passing a mcmc chain, a julia file where I wrote the model especification , but I get weird error message
But when I see Manifest and Project I view Tracker.jl and Bijectors.
Any idea?
Thanks
The text was updated successfully, but these errors were encountered: