<jupyter_start><jupyter_text>Model to be built ( with priors on $\alpha$, $\beta$, and $K$'s hyperpriors omitted:$$f\sim \mathcal{GP}([0, ..., 0], K(x, x'))$$    $$\mu \sim exp(\alpha + \beta x + f)$$        $$ y \sim Poisson(\mu)$$<jupyter_code>with pm.Model() as m_isl:
    η = pm.HalfCauchy('η', 1)
    ℓ = pm.HalfCauchy('ℓ', 1)
    
    cov = η * pm.gp.cov.ExpQuad(1, ls=ℓ)
    gp = pm.gp.Latent(cov_func=cov)
    f = gp.prior('f', X=isl_dist_sqr)
    
    α = pm.Normal('α', 0, 10)
    β = pm.Normal('β', 0, 1)
    μ = pm.math.exp(α + β*log_pop + f[index])
    tt_pred = pm.Poisson('tt_pred', μ, observed=tot_tools)
    trace_islands = pm.sample(1000, tune=1000)
                  
trace_η = trace_islands['η']
trace_ℓ = trace_islands['ℓ']
_, ax = pl.subplots(figsize=(8, 5))
xrange = np.linspace(0, d_isl_dist.values.max(), 100)
ax.plot(xrange, np.median(trace_η) * 
        np.exp(-np.median(trace_ℓ) * xrange ** 2), lw=3)
ax.plot(xrange, (trace_η[::20][:, None] * 
                 np.exp(-trace_ℓ[::20][:, None] * xrange**2)).T,
       'C0', alpha=.1)
ax.set_ylim(0, 1)
ax.set_xlabel('distance (1000s of km)')
ax.set_ylabel('covariance');
# compute posterior meidan covariance among societies
Σ = np.median(trace_η) * np.exp(-np.median(trace_ℓ) * isl_dist_sqr)
# convert to correlation matrix
Σ_post = np.diag(np.diag(Σ)**-0.5)
ρ = Σ_post @ Σ @ Σ_post
ρ = pd.DataFrame(ρ, index=d_isl_dist.columns, columns=d_isl_dist.columns)
ρ.round(2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19796610169491524, 'fraction_numerical': 0.02847457627118644, 'mean_word_length': 3.5, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '37301', 'license': 'CC0-1.0', 'n_tokens_mistral': 673, 'n_tokens_neox': 627, 'n_words': 120, 'path': 'Part-2-PyMC3-modeling/ipynb/GP/Learning_GP_3_Regression_with_autocorrelation.ipynb', 'repo_name': 'madHatter106/SouthernOcean', 'size': '1475'}