3. Discussion: how can we break out the context map generation? #3

Open
opened 2026-07-27 05:27:37 +02:00 by lisa · 6 comments
Owner

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?

  1. how would the import statement change as a result of needing a separate context_map module?
  2. what input arguments do the context_map functions need to take?
  3. how does the initialization of the walker change?
    • i.e. instead of "map_type"

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)

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? 1. how would the import statement change as a result of needing a separate context_map module? 2. what input arguments do the context_map functions need to take? 3. how does the initialization of the walker change? - i.e. instead of "map_type" **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)**
Member

The import statement would be like this:

from context_map import new_context_map

So we have a new module called context_map that contains a function to create a new context_map. This function would take as argument the type of context_map, for example "hill".

Finally, the Walker class takes a context_map object instead of map_type='hills':

walker = Walker(sigma_i=3, sigma_j=4, size=200, new_context_map("hill"))
The import statement would be like this: ``` from context_map import new_context_map ``` So we have a new module called context_map that contains a function to create a new context_map. This function would take as argument the type of context_map, for example "hill". Finally, the Walker class takes a context_map object instead of map_type='hills': ``` walker = Walker(sigma_i=3, sigma_j=4, size=200, new_context_map("hill")) ```
Member
  1. from walker import context_map
  2. size
  3. map_type='flat' would be gone
1. from walker import context_map 2. size 3. map_type='flat' would be gone
Member
  1. we wouldn't need to import any library for the Walker class

  2. just two, map_type and the size of the map
    def context_map (map_type, size)
    if map_type == 'a':
    map = map_a(size)
    elif map_type == 'b':
    map = map_b(size)
    return map

def map_a(size):
cont_map = np.ones((size, size))
return cont_map

def map_b(size):
...

  1. def __ init __(self, sigma_i, sigma_j, ctext_map):
1. we wouldn't need to import any library for the Walker class 2. just two, map_type and the size of the map def context_map (map_type, size) if map_type == 'a': map = map_a(size) elif map_type == 'b': map = map_b(size) return map def map_a(size): cont_map = np.ones((size, size)) return cont_map def map_b(size): ... 3. def __ init __(self, sigma_i, sigma_j, ctext_map):
Member

Inside the Walker class:

def map_type_flat(self):
...
def map_type_hills(self):
...
def map_type_labrynth(self):
...

Outside the Walker class:

walker1 = Walker(self...)
walker1.map_type_flat() # For example

The problem is when we use _compute_next_step_probability().
Maybe raise and error when the map isn't set up.

Inside the Walker class: def map_type_flat(self): ... def map_type_hills(self): ... def map_type_labrynth(self): ... Outside the Walker class: walker1 = Walker(self...) walker1.map_type_flat() # For example The problem is when we use _compute_next_step_probability(). Maybe raise and error when the map isn't set up.
Member

a) we have to separate each type of map into 3 pieces or methods in a new .py file and after that we can callable by importing. Nevertheless, it is necessary to establish their corresponding parameter to avoid errors.

a) we have to separate each type of map into 3 pieces or methods in a new .py file and after that we can callable by importing. Nevertheless, it is necessary to establish their corresponding parameter to avoid errors.
Member

1

We proposse to exclude the function create_context_map(), and create a new script named initial_context_map.py in the same folder, in the colab file we need to add from initial_context_map import create_context_map

2

In this new scrip, write a new claas, def class(self, size, shape_type):
self.size=size
self.shape_type = shape_type

                                    def size(self):
                                    ....
                                    def shape_type(self)
                                    case 1 = flat
                                    case 2 = hill
                                    case 3 = sin

3

It's no neccesary to use map_type, and keep size because of the random wlaker

## 1 We proposse to exclude the function create_context_map(), and create a new script named initial_context_map.py in the same folder, in the colab file we need to add from initial_context_map import create_context_map ## 2 In this new scrip, write a new claas, def class(self, size, shape_type): self.size=size self.shape_type = shape_type def size(self): .... def shape_type(self) case 1 = flat case 2 = hill case 3 = sin ## 3 It's no neccesary to use map_type, and keep size because of the random wlaker
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
7 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ASPP/2026-latam-scientific-patterns#3
No description provided.