CS作业代写 1 Computing a partition function

1 Computing a partition function
p(x; w) = 1 exp (x⊤w) (1) Z(w)
p(x;w)dx=1 (x∈R) or p(x;w)=1 (x∈Q) (2) x
􏰂p(x;w) = 􏰂 1 exp(x⊤w) (3) x x Z(w)

Copyright By PowCoder代写 加微信 powcoder

1= 1 􏰂exp(x⊤w) (4) Z(w) x
log1 = log 1 􏰂exp(x⊤w) (5) Z(w) x
0 = − log Z(w) + log 􏰂 exp (x⊤w) (6) x
log Z(w) = log 􏰂 exp (x⊤w) x

2 Log-Sum-Exp Trick
Given x = {x1,x2,…,xn}, where n ∈ N
y = ln 􏰂 exn ⇔ ey = 􏰂 exn (8)
n=1 n=1 NN
e−aey =e−a􏰂exn ⇔ ey−a =􏰂exn−a (9) n=1 n=1
y − a = ln 􏰂 exn −a ⇔ y = a + ln 􏰂 exn −a (10)
ln 􏰂 exn = a + ln 􏰂 exn −a , where a = max (xi ), i = 1..n

3 Compute a log of Gaussian PDF
Given D = (x(1), x(2), …x(N)), D ∈ R(N,d)
lnp(D;(m,S)) = ln􏰃p(x(i);(m,S)) = 􏰂lnp(x(i);(m,S)) = i=1 i=1
d ln 2π + ln |S| + (x(i) − m)⊤S−1(x(i) − m) =
−2 Ndln2π+Nln|S|+
i=1 D = D − m[np.newaxis],
x(i) = tr􏰅x(i)􏰆 􏰅􏰆􏰅􏰆
(14) tr ABC =tr BCA (15)
􏰂(x(i) − m)⊤S−1(x(i) − m) = 􏰂 tr􏰅(x(i) − m)⊤S−1(x(i) − m)􏰆 =
tr􏰅S−1 􏰂(x(i) − m)(x(i) − m)⊤􏰆 = tr􏰅S−1D⊤D􏰆 = tr􏰅DS−1D⊤􏰆 (16)
(x(i)−m)⊤S−1(x(i)−m) (12) D ∈ R(N,d) (13)
SA = D⊤ ⇔ A = S−1D⊤ (17) A = np.linalg.solve(S, D⊤) (18) tr􏰅DS−1D⊤􏰆 = tr􏰅DA􏰆 (19)

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com