4. Discussion: Two next-step proposals #4

Open
opened 2025-09-17 14:55:26 +02:00 by Aitor · 2 comments
Owner

Prof. McSmartypants wants to try running the walker with a different next step proposal that looks like this:

def square_next_step_proposal(current_i, current_j, size, width):
    """ Square next step proposal. """
    grid_ii, grid_jj = np.mgrid[0:size, 0:size]
    inside_mask = (np.abs(grid_ii - current_i) <= width // 2) & (np.abs(grid_jj - current_j) <= width // 2)
    p_next_step = inside_mask / inside_mask.sum()
    return p_next_step

Maybe we will need to add different step proposals later, so let's set this up properly, maybe by passing the proposal function to the walker. How should we design that code?

Exercise instructions:
Go to the notebook walker/Step_4_break_out_the_next_step_probability 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)

Prof. McSmartypants wants to try running the walker with a different next step proposal that looks like this: ``` def square_next_step_proposal(current_i, current_j, size, width): """ Square next step proposal. """ grid_ii, grid_jj = np.mgrid[0:size, 0:size] inside_mask = (np.abs(grid_ii - current_i) <= width // 2) & (np.abs(grid_jj - current_j) <= width // 2) p_next_step = inside_mask / inside_mask.sum() return p_next_step ``` Maybe we will need to add different step proposals later, so let's set this up properly, maybe by passing the proposal function to the walker. How should we design that code? **Exercise instructions:** Go to the notebook `walker/Step_4_break_out_the_next_step_probability` 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)**
lisa changed title from Implement two next-step proposals to 4. Discussion: Two next-step proposals 2025-09-22 17:51:32 +02:00
Aitor added the
Enhancement
Conceptual
labels 2025-09-24 10:02:23 +02:00
Member
%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np

from context_maps import flat_context_map, hills_context_map, labyrinth_context_map
from plotting import plot_trajectory, plot_trajectory_hexbin
from next_step_proposals import square_next_step_proposal, gaussian_next_step_proposal
from walker import Walker
context_map = hills_context_map(size=200)
square_next_step_proposal_arguments = {'width': 5}
walker = Walker(sigma_i=3, sigma_j=4, context_map=context_map, next_step_proposal=square_next_step_proposal, **square_next_step_proposal_arguments)

# Sample a next step 1000 times
i, j = 100, 50
trajectory = []
for _ in range(1000):
    i, j = walker.sample_next_step(i, j)
    trajectory.append((i, j))
    
plot_trajectory(trajectory, walker.context_map)
```python %matplotlib inline import matplotlib.pyplot as plt import numpy as np from context_maps import flat_context_map, hills_context_map, labyrinth_context_map from plotting import plot_trajectory, plot_trajectory_hexbin from next_step_proposals import square_next_step_proposal, gaussian_next_step_proposal from walker import Walker context_map = hills_context_map(size=200) square_next_step_proposal_arguments = {'width': 5} walker = Walker(sigma_i=3, sigma_j=4, context_map=context_map, next_step_proposal=square_next_step_proposal, **square_next_step_proposal_arguments) # Sample a next step 1000 times i, j = 100, 50 trajectory = [] for _ in range(1000): i, j = walker.sample_next_step(i, j) trajectory.append((i, j)) plot_trajectory(trajectory, walker.context_map) ```
Member

from next_step_proposals import `gaussian_next_step_proposal`,  `square_next_step_proposal`

arguments = {....}
walker = Walker(sigma_i=3, sigma_j=4, context_map=context_map, next_step_proposal = gaussian_next_step_proposal(), next_step_proposal_arguments = arguments )
```python from next_step_proposals import `gaussian_next_step_proposal`, `square_next_step_proposal` arguments = {....} walker = Walker(sigma_i=3, sigma_j=4, context_map=context_map, next_step_proposal = gaussian_next_step_proposal(), next_step_proposal_arguments = arguments )
Sign in to join this conversation.
No milestone
No project
No assignees
3 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/2025-plovdiv-scientific-patterns#4
No description provided.