3. Discussion: how can we break out the context map generation? #3
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 context map generation logic is in the Walker constructor. This works but is ugly and not very extensible. How could we solve this?
Exercise instructions:
Go to the notebook walker/Step_3_break_out_the_context_map_initialization and follow the instructions. Comment here what you think the solution could look like. Also feel free to comment on other group's suggestions.
Make sure to include your suggested code snippet(s).
walker = Walker(..., map = map)
we take the whole
if-elifchain and make it a separate function outside class Walker.import construct_context_mapChange the
initto reflect changes and make it directly inject thecontext_mapfrom outside`.self.context_map = context_map, since_compute_next_step_probabilityuses itfrom context_map import context_map
context_map = context_map(size, type)
def init(self, sigma_i, sigma_j, context_map):
Improvement! Improved flexibility, adaptability, reduced complexity.....
from context_maps import create_context_mapcreate_context_map(size, type)__init__(self, sigma_i, sigma_j)"""Question 1"""
%matplotlib inline
from plotting import plot_trajectory, plot_trajectory_hexbin
from walker import Walker
from context_map import context_map_builder as cmb #new separte context map module
"""Question 2"""
map1 = cmb(size = 200, map_type = 'mountain')
"""Question 3"""
walker = Walker(sigma_i=3, sigma_j=4, size=200, context_map = map1)
"""Question 4"""
"""yes, because the context map gets built outside the walker class. The context map was not using any Walker attributes earlier anyway. This makes the code more flexible."""