Coder Social home page Coder Social logo

rybern / mstan Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 3.0 3.12 MB

"Swappable Module" compiler for the Stan probabilistic programming language.

Home Page: https://statmodeling.stat.columbia.edu/2021/11/19/drawing-maps-of-model-space-with-modular-stan/

License: BSD 3-Clause "New" or "Revised" License

Haskell 88.13% Nix 2.90% R 1.11% Python 7.47% Shell 0.40%

mstan's People

Contributors

hyunjimoon avatar rybern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mstan's Issues

Trans-MCMC for joint space across different models

Problem: Parameters in model1 do not appear in model2. Exploration happens on joint space of every parameters within the model network.

Suggestion: use transformed parameters block to conditioned parameters as below
From

data {
  int N;
  vector[N] y;
}
parameters {
  real<lower=0> sigma;
}
...

To

data {
  int N;
  vector[N] y;
}
parameters {
  real<lower=0> sigma;
  real<lower=0> mu;
}
transformed parameters{
  real<lower=0> mu;
  mu = 0
}
model {
  sigma ~ lognormal(0, 1);
  y ~ normal(mu, sigma);
}

`model-neighbors` should be lazy

We shouldn't have to build the whole model network to find the neighbors of a model; sometimes the model network will be huge

categorized update and discrepancy metric

Can be applied to Regression (external feature), time series (external + internal feature), casual models it is regression example.

A. categorized update
We need to categorized the update types which can be seen from below can be largely divided into three: predictor set, distributional family of both outcome and predictor, model structure (i.e. hierarchical model - most related to DAG),
U1. predictor update

  1. y ~ sqrt_roach1 + treatment + senior (stan_glmp)
  2. y ~ treatment + senior
  3. y ~ sqrt_roach1 + senior
  4. y ~ sqrt_roach1 + treatment

U2. distributional family update
5. update(stan_glmp, family = neg_binomial_2)
6. y ~ sqrt_roach1 + treatment + senior + offset(log(exposure2)), zi ~ sqrt_roach1 + treatment + senior + offset(log(exposure2))), family=zero_inflated_negbinomial(),

U3. random effect (hierarchical model) update
7. y ~ sqrt_roach1 + treatment + senior + (1 | id)

B. Model discrepancy metric
can be computed with SBC::compute_results and calibration plot feature can be easily added as can be seen https://hyunjimoon.github.io/SBC/articles/implementing_backends.html


# feature
1. simple <- outcome ~ rx
2. complex <- outcome ~ rx + site + gender + age + risk

# prior
3. complex_narrow: intercept_prior_loc = 3, intercept_prior_width = 0.5, predictor_prior_loc = c(-2, 2), predictor_prior_width = 0.5)

backend_indo_simple <- SBC_backend_glm(formula = formula_indo_simple, family = "binomial") 
backend_indo_complex <- SBC_backend_glm(formula = formula_indo_complex, family = "binomial") 

datasets_simple <- generate_datasets(SBC_generator_function(
  generator_single_logistic, 
  formula = simple,
  dataset = medicaldata::indo_rct),
  n_datasets = 500) 

# Model discrepancy metric
discrepancy <- function(A,B) {(compute_results(datasets_A, backend_B)$dist + compute_results(datasets_B,backend_A)$dist)/2}

simple-complex <- discrepancy(indo_simple, indo_complex) 
simple-simple_narrow <- discrepancy(simple_narrow, simple)
complex-complex_narrow <- discrepancy(complex_narrow,complex)

## might need centering with self-discrepancy
complex-complex <- discrepancy(complex, complex)

simple model stan code order change

problem: the system provides simple model stan code as parameter -> data order as below which gives parse error.
fix: data block should come first.

parameters {
  real mu;
  real<lower=0> sigma;
}
data {
  int N;
  vector[N] x;
}
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.