Skip to content

Commit afb161a

Browse files
authored
Replace np.sum(a * b) with a @ b
1 parent f63761a commit afb161a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lectures/five_preferences.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def ent(π, π_hat):
100100
Compute the relative entropy of a probability vector `π_hat` with respect to `π`. JIT-compiled using Numba.
101101
102102
"""
103-
ent_val = -np.sum(π_hat * (np.log(π) - np.log(π_hat)))
103+
ent_val = -π_hat @ (np.log(π) - np.log(π_hat))
104104
105105
return ent_val
106106
@@ -115,7 +115,7 @@ def T_θ_factory(θ, π):
115115
Risk-sensitivity operator of Jacobson (1973) and Whittle (1981) taking a function `u` as argument.
116116
117117
"""
118-
return lambda c: -θ * np.log(np.sum(π * np.exp(-u(c) / θ)))
118+
return lambda c: -θ * np.log(π @ np.exp(-u(c) / θ))
119119
120120
return T_θ
121121
@@ -128,7 +128,7 @@ def compute_change_measure(u, c, θ, π):
128128
"""
129129
130130
m_unnormalized = np.exp(-u(c) / θ)
131-
m = m_unnormalized / (π * m_unnormalized).sum()
131+
m = m_unnormalized / (π @ m_unnormalized)
132132
return m
133133
134134

0 commit comments

Comments
 (0)