2. Discussion: What would a Walker class look like? #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Right now, the walker logic is implemented as a collection of standalone functions (sample_next_step, next_step_proposal, compute_next_step_probability, etc.). While this works, it might be more maintainable to encapsulate the walker’s state and behavior into a Walker class.
Exercise instructions:
Open the notebook walker/Step_1_classes and follow the instructions. Think about what you think the Walker interface should look like, answer the three questions in the notebook, and post your ideas as a comment to this issue.
Feel free to comment on other group's suggestions, respectfully.
Make sure to include your suggested code snippet(s).
Inside Walker class: i, j, sigma_i, sigma_j, context_map, sample_next_step()
We imagine Walker as an agent that, well, walks, given a set of inputs. Non-agentic things that pre-set environment like
create_context_mapshould be, probably, outside of class Walker.What's inside the Walker:
sample_next_stepi, jsigma_i,sigma_jcontext_maptrajectoryWhat's outside:
create_context_mapplot_trajectorysize@atillake wrote in #2 (comment):
agreed.
Write the (pseudo)code that uses your new
walkerinterface here!walker_1 = Walker(i=100, j=50 , sigma_i=3, sigma_j=4, trajectory)
walker_1.create_trajectory()
create_trajectory():
creates the trajectory -- for loop
includes sample_next_step fuction
w = Walker(i, j, sigma_i, sigma_j, size, trajectory)
w.create_context_map()
for _ in range(1000):
w.sample_next_step()
w.plot_trajectory()
We would define the walker by its initial position and degrees of freedom, while the context map could be still a separate function called by trajectory and along size. (Maybe size can be part of the walker though)
we are not sure if we need to import the class (and what that looks like)
from walker import Walker, create_context_map, plot_trajectory
size = 200 # size of the image
context_map = create_context_map(size, 'hills')
walker = Walker(sigma_i=3, sigma_j=4, i=100, j=50, context_map)
trajectory = []
for _ in range(1000):
i, j = walker.sample_next_step(i, j, sigma_i, sigma_j, context_map)
trajectory.append((i, j))
plot_trajectory(trajectory, context_map)
our pseudo code:
`class Walker:
def init(self, i, j, sigma_i, sigma_j):
self.i = i
self.j = j
self.sigma_i = sigma_i
self.sigma_j = sigma_j
In the class:
sample_next_stepi, jsigma_iandsigma_jtrajectoryThese are properties of the walker.
Outside the class:
create_context_mapplot_trajectorysizecontext_mapThese are properties of the context, independent of the walker.