Skip to content

External Exposure

Bases: BaseFeature

Source code in titan/features/external_exposure.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class ExternalExposure(base_feature.BaseFeature):
    name = "external_exposure"

    def __init__(self, agent: "agent.Agent"):
        super().__init__(agent)

        self.active = False

    def init_agent(self, pop: "population.Population", time: int):
        """
        Initialize the agent for this feature during population initialization (`Population.create_agent`).  Called on only features that are enabled per the params.

        If an agent has defined sex_type, with a random probability from params, assign them to be an agent with external exposure.

        args:
            pop: the population this agent is a part of
            time: the current time step
        """
        params = self.agent.location.params.external_exposure
        if self.agent.sex_type == params.sex_type:
            if pop.pop_random.random() < params.init:
                self.active = True

    def update_agent(self, model: "model.TITAN"):
        """
        Update the agent for this feature for a time step.  Called once per time step in `TITAN.update_all_agents`. Agent level updates are done after population level updates.   Called on only features that are enabled per the params.

        If the agent has external exposure, with a probability from params, convert the agent.

        args:
            model: the instance of TITAN currently being run
        """
        params = self.agent.location.params.external_exposure
        if self.active and model.run_random.random() < params.convert_prob:
            agent_exposure = getattr(self.agent, params.exposure)
            agent_exposure.convert(model)

init_agent(pop, time)

Initialize the agent for this feature during population initialization (Population.create_agent). Called on only features that are enabled per the params.

If an agent has defined sex_type, with a random probability from params, assign them to be an agent with external exposure.

Parameters:

Name Type Description Default
pop Population

the population this agent is a part of

required
time int

the current time step

required
Source code in titan/features/external_exposure.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def init_agent(self, pop: "population.Population", time: int):
    """
    Initialize the agent for this feature during population initialization (`Population.create_agent`).  Called on only features that are enabled per the params.

    If an agent has defined sex_type, with a random probability from params, assign them to be an agent with external exposure.

    args:
        pop: the population this agent is a part of
        time: the current time step
    """
    params = self.agent.location.params.external_exposure
    if self.agent.sex_type == params.sex_type:
        if pop.pop_random.random() < params.init:
            self.active = True

update_agent(model)

Update the agent for this feature for a time step. Called once per time step in TITAN.update_all_agents. Agent level updates are done after population level updates. Called on only features that are enabled per the params.

If the agent has external exposure, with a probability from params, convert the agent.

Parameters:

Name Type Description Default
model TITAN

the instance of TITAN currently being run

required
Source code in titan/features/external_exposure.py
30
31
32
33
34
35
36
37
38
39
40
41
42
def update_agent(self, model: "model.TITAN"):
    """
    Update the agent for this feature for a time step.  Called once per time step in `TITAN.update_all_agents`. Agent level updates are done after population level updates.   Called on only features that are enabled per the params.

    If the agent has external exposure, with a probability from params, convert the agent.

    args:
        model: the instance of TITAN currently being run
    """
    params = self.agent.location.params.external_exposure
    if self.active and model.run_random.random() < params.convert_prob:
        agent_exposure = getattr(self.agent, params.exposure)
        agent_exposure.convert(model)