<jupyter_start><jupyter_text>Connectivity<jupyter_code>m = cl.GraphEnsemble(1000)
m.fit([const.Connectivity(343)], opt_kwargs={'nit':30,'fatol':1e-2,'disp':True})
plt.figure(figsize=[15,5])
plt.subplot(1,3,1)
plot_adj(ba_adj)
plt.subplot(1,3,2)
plot_adj(m.adj_matrix)
plt.subplot(1,3,3)
plt.hist([m.sample().sum() for i in trange(1000)])<jupyter_output><empty_output><jupyter_text>Subgraph connectivity<jupyter_code>m = cl.GraphEnsemble(1000)
m.fit([const.Connectivity(343, nodeset1=np.arange(100))], opt_kwargs={'nit':30,'fatol':1e-2,'disp':True})
plt.figure(figsize=[15,5])
plt.subplot(1,3,1)
plot_adj(ba_adj)
plt.subplot(1,3,2)
plot_adj(m.adj_matrix)
plt.subplot(1,3,3)
plt.hist([np.triu(m.sample()[:100,:100]).sum() for i in trange(1000)])<jupyter_output><empty_output><jupyter_text>Connectivity between 2 groups of nodes<jupyter_code>m = cl.GraphEnsemble(1000)
m.fit([const.Connectivity(343, nodeset1=np.arange(100), nodeset2=np.arange(150,200))], opt_kwargs={'nit':30,'fatol':1e-2,'disp':True})
plt.figure(figsize=[15,5])
plt.subplot(1,3,1)
plot_adj(ba_adj)
plt.subplot(1,3,2)
plot_adj(m.adj_matrix)
plt.subplot(1,3,3)
plt.hist([m.sample()[:100,150:200].sum() for i in trange(1000)])<jupyter_output><empty_output><jupyter_text>Fixed degree sequence  Full degree sequence<jupyter_code>m = cl.GraphEnsemble(1000)
m.fit([const.DegreeSequence(d)], opt_kwargs={'nit':100,'fatol':1e-2,'disp':True})
#m.fit([const.DegreeSequence(get_din_dout(ba)[0]),const.Connectivity(250, nodeset1=np.arange(30), nodeset2=np.arange(40,50))], opt_kwargs={'nit':100,'fatol':1e-2})
#m.fit([const.DegreeSequence(d[:30], nodeset=np.arange(30))], opt_kwargs={'nit':30,'fatol':1e-2})
plt.figure(figsize=[15,5])
plt.subplot(1,3,1)
plot_adj(ba_adj)
plt.subplot(1,3,2)
plot_adj(m.adj_matrix)
plt.subplot(1,3,3)
plt.plot(d, m.adj_matrix.sum(axis=1),'.')
plt.plot(plt.xlim(),plt.xlim())<jupyter_output><empty_output><jupyter_text>Partial degree sequence<jupyter_code>m = cl.GraphEnsemble(1000)
#m.fit([const.DegreeSequence(get_din_dout(ba)[0]),const.Connectivity(250, nodeset1=np.arange(30), nodeset2=np.arange(40,50))], opt_kwargs={'nit':100,'fatol':1e-2})
m.fit([const.DegreeSequence(d[:50], nodeset=np.arange(50))], opt_kwargs={'nit':30,'fatol':1e-2,'disp':True})
plt.figure(figsize=[25,10])
plt.subplot(1,3,1)
plot_adj(ba_adj)
plt.subplot(1,3,2)
plot_adj(m.adj_matrix)
plt.subplot(1,3,3)
plt.plot(d, '.', markersize=15)
plt.plot(m.adj_matrix.sum(axis=1),'.',markersize=5)<jupyter_output><empty_output><jupyter_text>Degree sequence in subgraph<jupyter_code>m = cl.GraphEnsemble(1000)
#m.fit([const.DegreeSequence(get_din_dout(ba)[0]),const.Connectivity(250, nodeset1=np.arange(30), nodeset2=np.arange(40,50))], opt_kwargs={'nit':100,'fatol':1e-2})
m.fit([const.DegreeSequence(np.arange(50), nodeset=np.arange(50), subgraph_nodeset=np.arange(100))], opt_kwargs={'nit':100,'fatol':1e-2,'disp':True})
#m.fit([const.DegreeSequence(d[:50], nodeset=np.arange(50))], opt_kwargs={'nit':30,'fatol':1e-2})
plt.figure(figsize=[20,5])
plt.subplot(1,3,1)
plot_adj(m.adj_matrix)
plt.subplot(1,3,2)
plt.plot(m.adj_matrix[:50,:100].sum(axis=1),'.')
plt.subplot(1,3,3)
plt.plot(m.adj_matrix.sum(axis=1),'.')
plt.axvline(100,color='red')<jupyter_output><empty_output><jupyter_text>Joining constraints<jupyter_code>m = cl.GraphEnsemble(1000)
m.fit([const.DegreeSequence(get_din_dout(ba)[0]),const.Connectivity(250, nodeset1=np.arange(30), nodeset2=np.arange(40,50))], opt_kwargs={'nit':100,'fatol':1e-2,'disp':True})
plt.figure(figsize=[20,5])
plt.subplot(1,3,1)
plot_adj(ba_adj)
plt.subplot(1,3,2)
plot_adj(m.adj_matrix)
plt.subplot(1,3,3)
plt.hist([m.sample()[:30,40:50].sum() for i in trange(1000)])<jupyter_output><empty_output><jupyter_text>Observables  RWR<jupyter_code>x = np.zeros(N)
x[np.random.randint(0,N, int(N/100*20))] = 1
#x = np.random.rand(N)
x= x/x.sum()
x = jnp.asarray(x)

lambd = 0.3

def propagate(adj,x,lambd=lambd):
    p = adj / jnp.reshape(adj.sum(axis=0), [adj.shape[0],1])
    I = jnp.eye(p.shape[0])
    return lambd*x.dot(jnp.linalg.inv(I - (1-lambd)*p))

def propagate2(adj,x,i,lambd=lambd):
    p = adj / jnp.reshape(adj.sum(axis=0), [adj.shape[0],1])
    I = jnp.eye(p.shape[0])
    return lambd*x.dot(jnp.linalg.inv(I - (1-lambd)*p))[i]
m = cl.GraphEnsemble(1000)
#m.fit([const.DegreeSequence(d)], opt_kwargs={'nit':100,'fatol':1e-2})
m.fit([const.DegreeSequence(d),const.Connectivity(250, nodeset1=np.arange(30), nodeset2=np.arange(40,50))], opt_kwargs={'nit':50,'fatol':1e-2,'disp':True})
k = obs.RandomWalkWithRestart.eval_transfer_matrix(ba_adj, lambd)
mu = m.predict_mean(obs.RandomWalkWithRestart.func, f_args=[x, lambd, None, k])
sigma = m.predict_std(obs.RandomWalkWithRestart.grad, f_args=[x, lambd, None, k], obs_dim_idx=1)
N_samples = 100
y = propagate(ba_adj, x)
#samples = []
rdmy_ms = np.zeros([len(ba),N_samples])
for i in trange(N_samples):
    flag = False
    while not flag:
        smpl = m.sample()
        prop = propagate(smpl,x,lambd)
        if np.isnan(propagate(smpl,x)).sum() == 0:
            #samples.append(smpl)
            rdmy_ms[:,i] = propagate(smpl, x)
            flag = True
    
z = (y - rdmy_ms.mean(axis=1))/rdmy_ms.std(axis=1)
plt.figure(figsize=[13,5])
plt.subplot(121)
plt.plot(rdmy_ms.mean(axis=1),mu,'.')
plt.xlabel('Numerical expected value',fontsize=15)
plt.ylabel('Predicted expected value',fontsize=15)
plt.plot(plt.xlim(),plt.xlim())
plt.subplot(122)
plt.plot(rdmy_ms.std(axis=1),sigma,'.')
plt.xlabel('Numerical std. dev.',fontsize=15)
plt.ylabel('Predicted std. dev.',fontsize=15)
plt.plot(plt.xlim(),plt.xlim())
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>ANND<jupyter_code>mu = m.predict_mean(obs.AverageNeighborDegree.func)
sigma = [m.predict_std(grad(obs.AverageNeighborDegree.func, argnums=0), f_args=[i]) for i in trange(N)]
annd = obs.AverageNeighborDegree.func
N_samples = 100
y = np.asarray(annd(csc_matrix(adj))).flatten()
#samples = []
rdm_annd = np.zeros([N,N_samples])
for i in trange(N_samples):
    smpl = csc_matrix(m.sample())
    prop = np.asarray(annd(smpl)).flatten()
    rdm_annd[:,i] = prop
    
z = (y - rdm_annd.mean(axis=1))/rdm_annd.std(axis=1)
plt.figure(figsize=[13,5])
plt.subplot(121)
plt.plot(rdm_annd.mean(axis=1),mu,'.')
plt.xlabel('Numerical expected value',fontsize=15)
plt.ylabel('Predicted expected value',fontsize=15)
plt.plot(plt.xlim(),plt.xlim())
plt.subplot(122)
plt.plot(rdm_annd.std(axis=1),sigma,'.')
plt.xlabel('Numerical std. dev.',fontsize=15)
plt.ylabel('Predicted std. dev.',fontsize=15)
plt.plot(plt.xlim(),plt.xlim())
plt.tight_layout()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21306990881458968, 'fraction_numerical': 0.06170212765957447, 'mean_word_length': 8.052269601100413, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '50857', 'license': 'MIT', 'n_tokens_mistral': 3201, 'n_tokens_neox': 2916, 'n_words': 298, 'path': 'demos/Untitled1.ipynb', 'repo_name': 'reemagit/claude', 'size': '6580'}