<jupyter_start><jupyter_text>Distances<jupyter_code>import categorical_distance as categ
k =100
causal = categ.sample_joint(k=k, n=5, concentration=1, symmetric=True)
anti = causal.reverse()
intcausal = causal.intervention(on='effect',concentration=1,fromjoint=False)
intanti = intcausal.reverse()
dicausal = causal.scoredist(intcausal)
dianti = anti.scoredist(intanti)
delta = dianti - dicausal 
print(delta) # the anticausal model is advantaged
print((delta>0).sum())<jupyter_output>[-17231.9 -11897.  -14001.7 -13912.9 -13771.9]
0<jupyter_text>Now Let's look at the contribution of each term<jupyter_code># marginal difference
dimargi = (np.sum((anti.sa - intanti.sa)**2, axis=1))
# causal mean deviation
dicaumean = (np.sum((intanti.sa - np.mean(causal.sba, axis=1))**2,axis=1))
# anticausal mean deviation
dianmean = (np.sum((causal.sa - np.mean(anti.sba, axis=1))**2, axis=1))
print(dimargi)
print(dicaumean)
print(dianmean, 'alpha')
estimate = dimargi - k*(dicaumean - dianmean) # oooh sign error
print('difference ', delta.mean())
print('estimate   ', estimate.mean())<jupyter_output>difference  -14163.1047877
estimate    -14163.1047877<jupyter_text>variance of logsumexp<jupyter_code>ss = np.random.randn(99,100)
lge = categ.logsumexp(ss)
np.var(lge)
np.var(np.amax(ss,axis=0))
np.var(np.mean(ss, axis=0))
np.var(ss[0])
np.var(ss[0] - np.mean(ss[1:],axis=0))
print(np.mean(ss, axis=0))
print(np.round(causal.sba.mean(1)[0],decimals=1))
np.var(causal.sba.mean(1))<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup