QuantEcon / QuantEcon/lecture-python.myst

[kalman_2] Unclear purpose of single-worker plotting example code

Open
#483 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
123
Forks
57
Avg merge
3d 10h
Merged PRs (30d)
11

Description

Summary

I came across this block of code:

# We can generate a plot for only one of the workers:

T = 50
fig, ax = plt.subplots(figsize=(7, 7))

mu_0_1 = np.array([[1],
                 [100]])
mu_0_2 = np.array([[1],
                 [30]])
Sigma_0 = np.zeros((2,2))

uhat_0s = 100
αs = 0.5
βs = 0.3

worker = create_worker(uhat_0=uhat_0, α=α, β=β)
simulate_workers(worker, T, ax, mu_0=mu_0_1, Sigma_0=Sigma_0, 
                 diff=False, name=r'Hard-working worker')
simulate_workers(worker, T, ax, mu_0=mu_0_2, Sigma_0=Sigma_0, 
                 diff=False, 
                 title='A hard-working worker and a less hard-working worker',
                 name=r'Normal worker')
ax.axhline(y=u_0, xmin=0, xmax=0, color='grey', 
           linestyle='dashed', label=r'$u_{i, 0}$')
ax.legend(bbox_to_anchor=(1, 0.5))
plt.show()

However, I find it a bit confusing:

  • The comment says "We can generate a plot for only one of the workers," but two workers are actually plotted here.

  • The variable uhat_0s looks like it should be a list but it's just a single scalar. Should this be looped over?

  • The call to ax.axhline(y=u_0, ...) seems unnecessary, as horizontal lines for true values are already plotted inside simulate_workers.

  • Also, u_0 is undefined in this context outside of the loop.

Request

Could we clarify whether this example is meant to plot just one worker or two?

Should the code be refactored to loop over multiple workers instead of hardcoding two calls to simulate_workers?

Should the redundant external ax.axhline be removed?

Any additional comments on how to clean up this example for clarity?

Thanks for the great work!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the [kalman_2] example containing create_worker, simulate_workers, and the single-worker plotting block. Read the surrounding plotting code and definitions to determine whether the example demonstrates one worker or two and whether u_0 is in scope. Done means the example's comment, variables, plotting calls, and explanatory text consistently describe the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, documentation
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.