code: def eight_schools():
      """Eight Schools model.
  
      Returns:
        model: `StanModel`.
      """
  
      code = """
    data {
      int<lower=0> num_schools;
      real treatment_effects[num_schools];
      real<lower=0> treatment_stddevs[num_schools];
    }
    parameters {
      real avg_effect;
      real log_stddev;
      vector[num_schools] std_school_effects;
    }
    transformed parameters {
      vector[num_schools] school_effects;
      school_effects <- std_school_effects * exp(log_stddev) + avg_effect;
    }
    model {
      avg_effect ~ normal(0, 10);
      log_stddev ~ normal(5, 1);
      std_school_effects ~ normal(0, 1);
      treatment_effects ~ normal(school_effects, treatment_stddevs);
    }
    """
  
      stan_data = {
          "num_schools": 8,
          "treatment_effects": np.array(
              [28, 8, -3, 7, -1, 1, 18, 12], dtype=np.float32
          ),
          "treatment_stddevs": np.array(
              [15, 10, 16, 11, 9, 11, 10, 18], dtype=np.float32
          ),
      }
  
      model = util.cached_stan_model(code)
  
      def _ext_identity(samples):
          """Extracts the values of all latent variables."""
          res = collections.OrderedDict()
          res["avg_effect"] = util.get_columns(
              samples, r"^avg_effect$"
          )[:, 0]
          res["log_stddev"] = util.get_columns(
              samples, r"^log_stddev$"
          )[:, 0]
          res["school_effects"] = util.get_columns(
              samples, r"^school_effects\[\d+\]$"
          )
          return res
  
      extract_fns = {"identity": _ext_identity}
  
      return stan_model.StanModel(
          extract_fns=extract_fns,
          sample_fn=util.make_sample_fn(model, data=stan_data),
      )
  
imports: import collections
  import numpy
  from inference_gym.tools.stan import stan_model
  from inference_gym.tools.stan import util
label_desc: Use image node_id 1 for calling a global function with example usage: eight_schools() and returns: stan_model, res