<commit_before>// Orange Trees 
// http://www.openbugs.info/Examples/Otrees.html

data {
  int(0,) K;
  int(0,) N;
  int x[N];
  double Y[K, N]; 
}

parameters{
  double(0,) sigmasq;
  double theta[K, 3];
  double theta_mu[3]; 
  double(0,) theta_sigmasq[3]; 
} 

derived parameters {
  double mu[K, N]; 
  double phi[K, 3]; 
  for (i in 1:K) { 
    phi[i, 1] <- exp(theta[i, 1]);
    phi[i, 2] <- exp(theta[i, 2]) - 1;
    phi[i, 3] <- -exp(theta[i, 3]);
  } 
} 

model {
  sigmasq ~ inv_gamma(.001, .001); 
  for (j in 1:3) {
    theta_mu[j] ~ normal(0, 100); 
    theta_sigmasq[j] ~ inv_gamma(.001, .001); 
  }
  for (i in 1:K) {
    for (j in 1:3) {
      theta[i, j] ~ normal(theta_mu[j], sqrt(theta_sigmasq[j]));
    }
    for (n in 1:N) {
      mu[i, n] <- phi[i, 1] / (1 + phi[i, 2] * exp(phi[i, 3] * x[n]));
      Y[i, n] ~ normal(mu[i, n], sqrt(sigmasq)); 
    }
  }
}
<commit_msg>refactored BUGS oranges model for speed and index consistency<commit_after>// Orange Trees 
// http://www.openbugs.info/Examples/Otrees.html

data {
  int(0,) K;
  int(0,) N;
  int x[N];
  double Y[K, N]; 
}

parameters{
  double(0,) sigmasq;
  double theta[K, 3];
  double theta_mu[3]; 
  double(0,) theta_sigmasq[3]; 
} 

derived parameters {
  double phi[K, 3]; 
  double theta_sigma[3];
  double sigma;
  for (k in 1:K) { 
    phi[k, 1] <- exp(theta[k, 1]);
    phi[k, 2] <- exp(theta[k, 2]) - 1;
    phi[k, 3] <- -exp(theta[k, 3]);
  } 
  for (j in 1:3)
    theta_sigma[j] <- sqrt(theta_sigmasq[j]);
  sigma <- sqrt(sigmasq);
} 

model {
  sigmasq ~ inv_gamma(.001, .001); 
  for (j in 1:3) {
    theta_mu[j] ~ normal(0, 100); 
    theta_sigmasq[j] ~ inv_gamma(.001, .001); 
  }
  for (k in 1:K) {
    for (j in 1:3)
      theta[k, j] ~ normal(theta_mu[j], theta_sigma[j]);
    for (n in 1:N)
      Y[k, n] ~ normal(phi[k,1] / (1 + phi[k,2] * exp(phi[k,3] * x[n])), sigma);
  }
}

{'fraction_non_alphanumeric': 0.21108742004264391, 'fraction_numerical': 0.04637526652452026, 'mean_word_length': 2.6731898238747553, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7052264', 'n_tokens_mistral': 992, 'n_tokens_neox': 860, 'n_words': 198}