2. Discussion: Should the walker become a class? What should the interface look like? #2
Labels
No labels
Conceptual
Enhancement
Fix
No milestone
No project
No assignees
8 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: ASPP/2025-plovdiv-scientific-patterns#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 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)
Turn the walker code in to a classto 2. Walker code interface as a class2. Walker code interface as a classto 2. Refactor: Walker code interface as a class2. Refactor: Walker code interface as a classto 2. Discussion: Should the walker become a class? What should the interface look like?Actually, I think the current interface is fine as it is @Aitor ! No changes needed at all. I like calling it like this:
Thanks for the suggestion @lisa, but we do want to include modularity! I think re-structuring is much needed!
We suggest to implement two classes:
Walker, with attributes
methods:
sample_next_step
next_step_proposal
compute_next_step_probability
ContextMap, with attributes
create_context_map is basically init and plot_trajectory could be a method
In
walker.py
, the functionssample_next_step
,next_step_proposal
andcompute_next_step_probability
can be consolidated into a class. This is becausesample_next_step
,next_step_proposal
use similar inputs hence they seem to be an attribute of the walker.compute_next_step_probability
uses and input fromnext_step_proposal
and also seems to be an attribute of the walker.Could you add a Pseudo-code snippet to show what it would look like?
We agree that a
Walker class
would be a good idea. However, what should be the attributes of this class probably depends on whether your walker is designed for only one specific use case. For instance, thecontext_map
should only be a part of a Walker class if there is one specific use case.Pseudo Code
We would definitely add a Walker class,, could be instantiated with pos and Gaussian parameters (some walkers might follow different probability distributions in their decision making). We could have
simulate_trajectory
as a classmethod with argumentscontext_map
, nsteps. Plotting should be separate from the class, so trajectory needs to be returned.We agree that walker should be a class. Here's a rough implementation draft:
walker into class
class Walker
def init(i,j, sigma_i, sigma_j):
self.i= i
self.j =j
...
def context_map(self): .....
def next_step_sim(self): ....