# Alterna AI chapter 13: verified standalone examples
E=[[1,0,0],[.9,.1,0],[0,1,0],[0,.8,.2],[0,0,1],[.1,0,.9]]
onehot=[0,0,1,0,0,0]
h=[sum(onehot[i]*E[i][j] for i in range(6)) for j in range(3)]
assert h==E[2]==[0,1,0]


from math import exp,log
p0=exp(1)/(exp(1)+1)
loss=log(exp(1)+1)
assert abs(loss-1.3132616875182228)<1e-12
gradient=[p0,-p0]


from math import sqrt
similarity=.9/sqrt(.9**2+.1**2)
assert abs(similarity-.9938837346736189)<1e-12


from math import sqrt
assert [1,0,0][:2]==[1,0,2][:2]
assert abs(1/sqrt(5)-.4472135954999579)<1e-12


a,b=[1,0,0],[0,0,1]
mixed=[.5*x+.5*y for x,y in zip(a,b)]
assert mixed==[.5,0,.5]

print('Chapter 13: 5 examples PASS')
