khanna-lab / cadre

Other
0 stars 0 forks source link

recording time from the run method on Model() #12

Closed khanna7 closed 2 years ago

khanna7 commented 2 years ago

@ncollier: There is still one thing I didn't understand pertaining to our discussion of how to record the time of incarceration. The decision for whether a person is incarcerated happens in the simulate_incarceration() method on the Person class. That's where I record the change in the person's incarceration status, and I believe should be where I record the *time* of their incarceration too. But, the time variable is defined in the run method on the Model class. I am not sure how I access this variable in a method on Person() because the variable is defined in a method inside a whole other class. I'd be grateful for any tips.

class Person():
    def __init__(self, 
...
    current_incarceration_status = None,
    last_incarceration_time = None):
....
 def simulate_incarceration(self):
        PROBABILITY_DAILY_INCARCERATION = 1/100
        prob = random.uniform(0, 1)
        if self.current_incarceration_status == 0:
            if prob < PROBABILITY_DAILY_INCARCERATION:
                self.current_incarceration_status = 1
                self.last_incarceration_time = #how should I call the time attribute which appears in the run method in the Model class?

...

class Model:
  def __init__(self, n, verbose=True):
....
  def run(self, MAXTIME=10):

   for time in range(MAXTIME):
... #time is defined here, but I want to call it above in the simulate_incarceration method on the Person class 
khanna7 commented 2 years ago

I am thinking perhaps time inside Model() needs to be a property?

ncollier commented 2 years ago

You could pass the current time as an argument to simulate_incarceration, and that would make it available.

khanna7 commented 2 years ago

Thank you! Looks like this worked.