import numpy as np
def softmax(z):
    z=np.asarray(z,dtype=float); e=np.exp(z-z.max(axis=-1,keepdims=True))
    return e/e.sum(axis=-1,keepdims=True)
for temp in (1.,.5):
    print("temperatuur",temp,"kansen",np.round(softmax(np.array([2.,1.,0.])/temp),6))
# Klein causaal attentionvoorbeeld; geen getraind taalmodel.
Q=np.array([[1.,0.],[0.,1.],[1.,1.]])
K=Q.copy(); V=np.array([[1.,0.],[0.,2.],[3.,1.]])
score=Q@K.T/np.sqrt(2)
score[np.triu_indices(3,1)]=-1e9
A=softmax(score)
print("causale attention",np.round(A,3))
print("contextvectoren",np.round(A@V,3))
# Onafhankelijke rekenproef van een toetsrapport.
groepen={"helder":[76,4,1,19],"schaduw":[72,8,8,12]}
for naam,(tn,fp,fn,tp) in groepen.items():
    print(naam,"recall",round(tp/(tp+fn),3),"FPR",round(fp/(fp+tn),3))
alles=np.sum(list(groepen.values()),axis=0)
tn,fp,fn,tp=alles
print("aggregaat recall",tp/(tp+fn),"precisie",tp/(tp+fp))
# Energie: uitsluitend veronderstelde boekhoudwaarden.
training_kwh=1200; levensduur_outputs=10_000_000
train_wh=training_kwh*1000/levensduur_outputs
it_wh=.020; pue=1.2; netwerk_wh=.006
per_output=train_wh+it_wh*pue+netwerk_wh
print("Wh/output",per_output,"kWh/jaar bij200perdag",per_output*200*365/1000)
print("apart continu apparaat5W",5*24*365/1000,"kWh/jaar")
