Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lectures/mccall_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class McCallModel:
# Evaluate value for each state-action pair
# Consider action = accept or reject the current offer
accept = w[i] / (1 - β)
reject = c + β * np.sum(v * q)
reject = c + β * (v @ q)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks @UdohNakamura and @mmcky,

When building on my side I got

<string>:3: NumbaPerformanceWarning: '@' is faster on contiguous arrays, called on (Array(float64, 1, 'C', False, aligned=True), Array(float64, 1, 'A', False, aligned=True))

Upon checking, I found we annotate the type

    ('w', float64[:]),   # array of wage values, w[i] = wage at state i
    ('q', float64[:])    # array of probabilities

The following type will help (see more here:

    ('w', float64[::1]),   # array of wage values, w[i] = wage at state i
    ('q', float64[::1])    # array of probabilities

Please let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HumphreyYang Thanks, I didn't know that. Maybe write float64[::1] in place of float64[:] and explain that it is needed to have @ work inside a jitclass?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @HumphreyYang and @oyamad

@HumphreyYang I will merge these great PRs and then you can do a pass to fix this.


return np.array([accept, reject])
```
Expand Down Expand Up @@ -488,7 +488,7 @@ def compute_reservation_wage(mcm,

# == Now compute the reservation wage == #

return (1 - β) * (c + β * np.sum(v * q))
return (1 - β) * (c + β * (v @ q))
```

The next line computes the reservation wage at default parameters
Expand Down Expand Up @@ -622,13 +622,13 @@ def compute_reservation_wage_two(mcm,

# == First compute h == #

h = np.sum(w * q) / (1 - β)
h = (w @ q) / (1 - β)
i = 0
error = tol + 1
while i < max_iter and error > tol:

s = np.maximum(w / (1 - β), h)
h_next = c + β * np.sum(s * q)
h_next = c + β * (s @ q)

error = np.abs(h_next - h)
i += 1
Expand Down
Loading